Mahout-hashmap's evolutionary version of Fastbyidmap

Source: Internet
Author: User

Fastbyidmap is a hash-based, linear probe rather than a detached link when dealing with collisions, thus saving memory overhead by not having to add an Map.entry object for each entry.
The following code is a demo of a linear probe map:

Package com.example.mahout; Public classArrayhashst_linear_probing<key, val> {Private intM =30001;PrivateKey[] keys = (key[])NewOBJECT[M];PrivateVal[] Vals = (val[])NewOBJECT[M];Private int Hash(Key key) {return(Key.hashcode () &0x7fffffff)% M; } Public void put(Key key, Val val) {intI for(i = hash (key); Keys[i]! =NULL; i = (i +1) (% M)if(Keys[i].equals (key)) Break;        Keys[i] = key;    Vals[i] = val; } PublicValGet(Key key) {intI for(i = hash (key); Keys[i]! =NULL; i = (i +1) (% M)if(Keys[i].equals (key)) Break;returnVals[i]; } Public Static void Main(string[] args) {Arrayhashst_linear_probing<string,string> St =NewArrayhashst_linear_probing<string, string> (); St.put ("Jocularly","Jocularly"); St.put ("Seriously","Seriously"); St.put ("Listen","Listen"); St.put ("Suburban","Suburban"); St.put ("untravelled","untravelled"); St.put ("Considerating","Considerating"); St.put ("Browsing","Browsing"); System. out. println (St.Get("Jocularly")); }}

This is the demo of the Detach Link:

Package com.example.mahout; Public classListhashst_separate_chaining<key, value> {Private intM =8191;Privatenode[] St =NewNODE[M];Private Static classNode {Object key;        Object Val;        Node Next; Node (object key, Object Val, node next) { This. key = key; This. val = val; This. next = Next; }    }Private int Hash(Key key) {return(Key.hashcode () &0x7fffffff)% M; } Public void put(Key key, Value Val) {inti = hash (key); for(Node x = st[i]; x! =NULL; x = X.next) {if(Key.equals (X.key)) {x.val = val;return; }} St[i] =NewNode (Key, Val, St[i]); } PublicValueGet(Key key) {inti = hash (key);//system.out.println (i);         for(Node x = st[i]; x! =NULL; x = x.next) {System. out. println (X.val);if(Key.equals (X.key))return(Value) X.val; }return NULL; } Public Static void Main(string[] args) {//TODO auto-generated method stubListhashst_separate_chaining<string, String> st =NewListhashst_separate_chaining<string, string> (); St.put ("Jocularly","Jocularly"); St.put ("Seriously","Seriously"); St.put ("Listen","Listen"); St.put ("Suburban","Suburban"); St.put ("untravelled","untravelled"); St.put ("Considerating","Considerating"); St.put ("Browsing","Browsing"); St.Get("Jocularly");//system.out.println (St.get ("jocularly"));}}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Mahout-hashmap's evolutionary version of Fastbyidmap

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.