Java Map Bottom-line implementation ideas

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.