Chirikov criterion: Difference between revisions
en>Yobot m WP:CHECKWIKI error 22 fixes (category with space) + general fixes (BRFA 16) using AWB (7799) |
en>Addbot m Bot: Migrating 1 interwiki links, now provided by Wikidata on d:q5101905 |
||
| Line 1: | Line 1: | ||
{{DISPLAYTITLE:Java <tt>hashCode()</tt>}} | |||
In the [[Java (programming language)|Java]] [[programming language]], every [[class (computer science)|class]] implicitly or explicitly provides a '''<code>hashCode()</code>''' [[method (computer science)|method]], which digests the data stored in an instance of the class into a single hash value (a 32-[[bit]] [[integer (computer science)|signed integer]]). This hash is used by other code when storing or manipulating the instance – the values are intended to be evenly distributed for varied inputs in order to use in [[hash table#Choosing a good hash function|clustering]]. This property is important to the performance of [[hash table]]s and other [[data structure]]s that store objects in groups ("buckets") based on their computed hash values. Technically, in Java, <tt>hashCode()</tt> by default is a native method, meaning, it has the modifier 'native', as it is implemented directly in the native code in the JVM. | |||
==<tt>hashCode()</tt> in general== | |||
All the classes inherit a basic hash scheme from the fundamental base class <tt>java.lang.Object</tt>, but instead many override this to provide a hash function that better handles their specific data. Classes which provide their own implementation must override the object method <tt>public int hashCode()</tt>. | |||
The general [[design by contract|contract]] for overridden implementations of this method is that they behave in a way consistent with the same object's <tt>equals()</tt> method: that a given object must consistently report the same hash value (unless it is changed so that the new version is no longer considered "equal" to the old), and that two objects which <tt>equals()</tt> says are equal ''must'' report the same hash value. There's no requirement that hash values be consistent between different Java implementations, or even between different execution runs of the same program, and while two ''unequal'' objects having different hashes is very desirable, this is not mandatory (that is, the hash function implemented need not be a [[perfect hash function|perfect hash]]).<ref name="oracle_objectdoc">[http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html#hashCode%28%29 java.lang.Object.hashCode() documentation], Java SE 1.5.0 documentation, Oracle Inc.</ref> | |||
For example, the class <tt>Employee</tt> might implement its hash function by composing the hashes of its members: | |||
<source lang="java"> | |||
public class Employee { | |||
int employeeId; | |||
String name; | |||
Department dept; | |||
// other methods would be in here | |||
@Override | |||
public int hashCode() { | |||
int hash = 1; | |||
hash = hash * 17 + employeeId; | |||
hash = hash * 31 + name.hashCode(); | |||
hash = hash * 13 + (dept == null ? 0 : dept.hashCode()); | |||
return hash; | |||
} | |||
} | |||
</source> | |||
==The <tt>java.lang.String</tt> hash function== | |||
In an attempt to provide a fast implementation, early versions of the Java <tt>String</tt> class provided a <tt>hashCode()</tt> implementation that considered at most 16 characters picked from the string. For some common data this worked very poorly, delivering unacceptably clustered results and consequently slow hashtable performance.<ref name="Bloch">Bloch</ref> | |||
From Java 1.2, <tt>java.lang.String</tt> class implements its <tt>hashCode()</tt> using a product sum algorithm over the entire text of the string.<ref name="Bloch" /> An instance <code>s</code> of the <code>java.lang.String</code> class, for example, would have a hash code <math>h(s)</math> defined by | |||
:<math>h(s)=\sum_{i=0}^{n-1}s[i] \cdot 31^{n-1-i}</math> | |||
where terms are summed using Java 32-bit <code>int</code> addition, <math>s[i]</math> denotes the <math>i</math>th character of the string, and <math>n</math> is the length of <code>s</code>.<ref name="javadoc">[http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#hashCode%28%29 java.lang.String.hashCode() documentation], Java SE 1.5.0 documentation, Oracle Inc.</ref> | |||
<ref name="williams">[http://www.cogs.susx.ac.uk/courses/dats/notes/html/node114.html Choice of hash function -> The String hash function"], Data Structures course notes (2006), Peter M Williams, [[University of Sussex]] School of Information </ref>{{Dead link|date=August 2013}} | |||
==References== | |||
*"Always override hashCode when you override equals" in {{Citation | |||
| last =Bloch | |||
| first =Joshua | |||
| author-link =Joshua Bloch | |||
| year =2008 | |||
| title =Effective Java | |||
| edition =2 | |||
| publisher =Addison-Wesley | |||
| isbn =978-0-321-35668-0 | |||
}} | |||
<references /> | |||
==External links== | |||
* [http://www.ibm.com/developerworks/java/library/j-jtp05273.html "Java theory and practice: Hashing it out"], Brian Goetz, IBM Developer Works article, 27 May 2003 | |||
* [http://www.javamex.com/tutorials/collections/hash_function_technical.shtml "How the String hash function works (and implications for other hash functions)"], Neil Coffey, Javamex | |||
[[Category:Java programming language]] | |||
[[Category:Hashing]] | |||
[[Category:Hash functions]] | |||
[[Category:Checksum algorithms]] | |||
Revision as of 17:34, 17 March 2013
In the Java programming language, every class implicitly or explicitly provides a hashCode() method, which digests the data stored in an instance of the class into a single hash value (a 32-bit signed integer). This hash is used by other code when storing or manipulating the instance – the values are intended to be evenly distributed for varied inputs in order to use in clustering. This property is important to the performance of hash tables and other data structures that store objects in groups ("buckets") based on their computed hash values. Technically, in Java, hashCode() by default is a native method, meaning, it has the modifier 'native', as it is implemented directly in the native code in the JVM.
hashCode() in general
All the classes inherit a basic hash scheme from the fundamental base class java.lang.Object, but instead many override this to provide a hash function that better handles their specific data. Classes which provide their own implementation must override the object method public int hashCode().
The general contract for overridden implementations of this method is that they behave in a way consistent with the same object's equals() method: that a given object must consistently report the same hash value (unless it is changed so that the new version is no longer considered "equal" to the old), and that two objects which equals() says are equal must report the same hash value. There's no requirement that hash values be consistent between different Java implementations, or even between different execution runs of the same program, and while two unequal objects having different hashes is very desirable, this is not mandatory (that is, the hash function implemented need not be a perfect hash).[1]
For example, the class Employee might implement its hash function by composing the hashes of its members:
public class Employee {
int employeeId;
String name;
Department dept;
// other methods would be in here
@Override
public int hashCode() {
int hash = 1;
hash = hash * 17 + employeeId;
hash = hash * 31 + name.hashCode();
hash = hash * 13 + (dept == null ? 0 : dept.hashCode());
return hash;
}
}
The java.lang.String hash function
In an attempt to provide a fast implementation, early versions of the Java String class provided a hashCode() implementation that considered at most 16 characters picked from the string. For some common data this worked very poorly, delivering unacceptably clustered results and consequently slow hashtable performance.[2]
From Java 1.2, java.lang.String class implements its hashCode() using a product sum algorithm over the entire text of the string.[2] An instance s of the java.lang.String class, for example, would have a hash code defined by
where terms are summed using Java 32-bit int addition, denotes the th character of the string, and is the length of s.[3]
[4]Template:Dead link
References
- "Always override hashCode when you override equals" in Many property agents need to declare for the PIC grant in Singapore. However, not all of them know find out how to do the correct process for getting this PIC scheme from the IRAS. There are a number of steps that you need to do before your software can be approved.
Naturally, you will have to pay a safety deposit and that is usually one month rent for annually of the settlement. That is the place your good religion deposit will likely be taken into account and will kind part or all of your security deposit. Anticipate to have a proportionate amount deducted out of your deposit if something is discovered to be damaged if you move out. It's best to you'll want to test the inventory drawn up by the owner, which can detail all objects in the property and their condition. If you happen to fail to notice any harm not already mentioned within the inventory before transferring in, you danger having to pay for it yourself.
In case you are in search of an actual estate or Singapore property agent on-line, you simply should belief your intuition. It's because you do not know which agent is nice and which agent will not be. Carry out research on several brokers by looking out the internet. As soon as if you end up positive that a selected agent is dependable and reliable, you can choose to utilize his partnerise in finding you a home in Singapore. Most of the time, a property agent is taken into account to be good if he or she locations the contact data on his website. This may mean that the agent does not mind you calling them and asking them any questions relating to new properties in singapore in Singapore. After chatting with them you too can see them in their office after taking an appointment.
Have handed an trade examination i.e Widespread Examination for House Brokers (CEHA) or Actual Property Agency (REA) examination, or equal; Exclusive brokers are extra keen to share listing information thus making certain the widest doable coverage inside the real estate community via Multiple Listings and Networking. Accepting a severe provide is simpler since your agent is totally conscious of all advertising activity related with your property. This reduces your having to check with a number of agents for some other offers. Price control is easily achieved. Paint work in good restore-discuss with your Property Marketing consultant if main works are still to be done. Softening in residential property prices proceed, led by 2.8 per cent decline within the index for Remainder of Central Region
Once you place down the one per cent choice price to carry down a non-public property, it's important to accept its situation as it is whenever you move in – faulty air-con, choked rest room and all. Get round this by asking your agent to incorporate a ultimate inspection clause within the possibility-to-buy letter. HDB flat patrons routinely take pleasure in this security net. "There's a ultimate inspection of the property two days before the completion of all HDB transactions. If the air-con is defective, you can request the seller to repair it," says Kelvin.
15.6.1 As the agent is an intermediary, generally, as soon as the principal and third party are introduced right into a contractual relationship, the agent drops out of the image, subject to any problems with remuneration or indemnification that he could have against the principal, and extra exceptionally, against the third occasion. Generally, agents are entitled to be indemnified for all liabilities reasonably incurred within the execution of the brokers´ authority.
To achieve the very best outcomes, you must be always updated on market situations, including past transaction information and reliable projections. You could review and examine comparable homes that are currently available in the market, especially these which have been sold or not bought up to now six months. You'll be able to see a pattern of such report by clicking here It's essential to defend yourself in opposition to unscrupulous patrons. They are often very skilled in using highly unethical and manipulative techniques to try and lure you into a lure. That you must also protect your self, your loved ones, and personal belongings as you'll be serving many strangers in your home. Sign a listing itemizing of all of the objects provided by the proprietor, together with their situation. HSR Prime Recruiter 2010
- ↑ java.lang.Object.hashCode() documentation, Java SE 1.5.0 documentation, Oracle Inc.
- ↑ 2.0 2.1 Bloch
- ↑ java.lang.String.hashCode() documentation, Java SE 1.5.0 documentation, Oracle Inc.
- ↑ Choice of hash function -> The String hash function", Data Structures course notes (2006), Peter M Williams, University of Sussex School of Information
External links
- "Java theory and practice: Hashing it out", Brian Goetz, IBM Developer Works article, 27 May 2003
- "How the String hash function works (and implications for other hash functions)", Neil Coffey, Javamex