hashtable

Why is the initialCapacity of Hashtable 11 while the DEFAULT_INITIAL_CAPACITY in HashMap is 16 and requires a power of 2?

Deadly 提交于 2019-12-02 15:34:10
Comparing the HashMap and Hashtable source code in JDK 1.6, I saw the below code inside HashMap: /** * The default initial capacity - MUST be a power of two. */ static final int DEFAULT_INITIAL_CAPACITY = 16; int capacity = 1; while (capacity < initialCapacity) capacity <<= 1; However, in Hashtable, I saw this: table = new Entry[initialCapacity]; public Hashtable() { this(11, 0.75f); } So my question is: Why does HashMap require a power of 2 as the initial capacity, while Hashtable chooses 11 as the default initial capacity? I assume this has nothing to do with the thing that Hashtable is

Are Open Addressing in Hash Tables only useful for searching ? How do the elements get into the HashTable in the very first place?

戏子无情 提交于 2019-12-02 14:26:19
问题 From Wikipedia link on Open Addressing : Open addressing, or closed hashing, is a method of collision resolution in hash tables. With this method a hash collision is resolved by probing, or searching through alternate locations in the array (the probe sequence) until either the target record is found, or an unused array slot is found, which indicates that there is no such key in the table.1 . I have two questions on this . What is the intuition for using the fancy term open addressing and

What are hashtables and hashmaps and their typical use cases?

眉间皱痕 提交于 2019-12-02 14:14:54
I have recently run across these terms few times but I am quite confused how they work and when they are usualy implemented? Well, think of it this way. If you use an array, a simple index-based data structure, and fill it up with random stuff, finding a particular entry gets to be a more and more expensive operation as you fill it with data, since you basically have to start searching from one end toward the other, until you find the one you want. If you want to get faster access to data, you typicall resort to sorting the array and using a binary search. This, however, while increasing the

A minimal hash function for C?

醉酒当歌 提交于 2019-12-02 14:06:42
I can't use boost:hash because I have to stick with C and can't use C++. But, I need to hash a large number (10K to 100k) of tokens strings (5 to 40 bytes length) so that search within those are fastest. MD5, SHA1 or any long hash function seems too heavy for a simple task, I am not doing cryptography. Plus there is the storage and computing cost. Therefore my question: What might be the simplest hash algorithm that will ensure collision prevention in most practical cases. How many bit to use for the hash value? I am developing for 32 bit systems. Does hash algorithm in Perl/Python use 32 bit

Perl hash substitution with special characters in keys

爱⌒轻易说出口 提交于 2019-12-02 13:58:54
My current script will take an expression, ex: my $expression = '( a || b || c )'; and go through each boolean combination of inputs using sub/replace, like so: my $keys = join '|', keys %stimhash; $expression =~ s/($keys)\b/$stimhash{$1}/g; So for example expression may hold, ( 0 || 1 || 0 ) This works great. However, I would like to allow the variables (also in %stimhash) to contain a tag, *. my $expression = '( a* || b* || c* )'; Also, printing the keys of the stimhash returns: a*|b*|c* It is not properly substituting/replacing with the extra special character, *. It gives this warning: Use

Lower / upper load factor in hash tables

北城余情 提交于 2019-12-02 13:31:17
I am to write a chained hash set class in java. I understand the load factor is M/capacity where M is the number of elements currently in the table and capacity is the size of the table. But how does the load factor help me determine if I should resize the table and rehash or not? Also I couldn't find anywhere how to calculate the lower / upper load factors. Are they even needed? I hope this is enough information, Thank you!! A single loadFactor used to configure standard Java hashes (and in a number of hash APIs in other languages) is a simplification. Conceptually, it is reasonable to

Utilize Results from Synchronized Hashtable (Runspacepool 6000+ clients)

笑着哭i 提交于 2019-12-02 10:20:50
Adapting a script to do multiple functions, starting with test-connection to gather data, will be hitting 6000+ machines so I am using RunspacePools adapted from the below site; http://learn-powershell.net/2013/04/19/sharing-variables-and-live-objects-between-powershell-runspaces/ The data comes out as below, I would like to get it sorted into an array (I think that's the terminology), so I can sort the data via results. This will be adapted to multiple other functions pulling anything from Serial Numbers to IAVM data. Is there any way I can use the comma delimited data and have it spit the

GHashTable that using uint64_t as key and a struct as value

拜拜、爱过 提交于 2019-12-02 09:45:24
I am studying the GHashTable . Though there are already some examples in Stackoverflow, they are just some common case. So I am still not sure how to implement my requirements and decide to ask for help. I want to use a uint64_t as key and a struct as value. I find that there is no such built-in hash function in GLib . There is just a g_int64_hash() . Though the key is uint64_t , it will just be about 52 bits. So I think gint64 is OK. But I see some examples using GINT_TO_POINTER() to convert the value (and sometimes they didn't). So just be confused about this. Thanks very much! See in ghash

HashTable to Lwuit Table

萝らか妹 提交于 2019-12-02 09:37:06
Hashtable iHashtable=new Hashtable(); iHashtable.put("Name", "Jhon"); iHashtable.put("Address","India"); Enumeration iEnumeration=iHashtable.keys(); while(iEnumeration.hasMoreElements()) { Object iresult1=iEnumeration.nextElement(); String iresult2=(String) iHashtable.get(iresult1); System.out.println(iresult1); System.out.println(iresult2); My problem is I want to put the value at LWUIT table dynamically using the HashTable key and value,here is iresult1 and iresult2,using the key and value I want to create the LWUIT table where the value will be shown in the following form. Name Jhon Address

Collection was modified; enumeration operation may not execute. when update values of hashtable

两盒软妹~` 提交于 2019-12-02 08:26:10
this code throw exception while i am trying to update value ,first value only updated and then throw the exception "Collection was modified; enumeration operation may not execute." !!!! Hashtable hh = new Hashtable(); hh.Add("val 1",null); hh.Add("val 2", null); foreach (string dd in hh.Keys) { hh[dd] = "some_value"; // MessageBox.Show(dd.Value.ToString()); } i need to update empty values in hashtables or any equivalent structure that has [key,value]?? You need to make copy of hh.Keys, because you are trying to change Hashtable which is invalid operation while enumerating its keys in the