Package Cn.com.commsoft.map;public class MyMap {myentry[] arr = new Myentry[100];int size;/** * Implement map with hash algorithm (each object has an address , * A hash code generated by the base site, because each object's address is different, so * generated hash code is unique) * @param key * @param value */public void put (object key, Object value {Myentry my = new Myentry (key, value);//corresponds to the address mapping function, but generates an address mapping conflict int a = (Key.hashcode ()%100);//Idea one: when the address conflicts, The open address method is used to process the conflict while (arr[a].key! = null) {a++;} Idea two: When the address conflict, the use of linked list method to deal with the conflict arr[a] = my;} public object get (object key) {int a = (Key.hashcode ()%100); return arr[a].value;}} Class Myentry{object Key;object value;public myentry (Object key, Object value) {super (); This.key = Key;this.value = value; }}
The content will continue to update, please pay attention!
Java Map Bottom-line implementation ideas