hashtable

Java Object and array memory location

旧巷老猫 提交于 2019-12-06 14:40:41
问题 I'm writing an array-backed hashtable in Java, where the type of key and value are Object; no other guarantee. The easiest way for me code-wise is to create an object to hold them: public class Pair { public Object key; public Object value; } And then create an array public Pair[] storage = new Pair[8]; But how does the jvm treat that in memory? Which is to say, will the array actually: be an array of pointers to Pair() objects sitting elsewhere, or contain the actual data? edit Since the

How to deal with old references to a resized hash table?

你。 提交于 2019-12-06 14:40:38
问题 I'm currently working on a hash table implementation in C. I'm trying to implement dynamic resizing, but came across a problem. If resizing a hash table means creating a new one with double (or half) the size, rehashing, and deleting the old one, how can I deal with old references the user may have made to the old table? Example code (I've omitted error checking just for this example): int main(int argc, char *argv[]) { ht = ht_create(5) /* make hashtable with size 5 */ ht_insert("john",

How does the MAD (Multiply, Add, Divide) Hashing function work?

南楼画角 提交于 2019-12-06 14:39:42
I have been assigned as a university project the task to create data structures (such as minheap, hashtable etc.) from scratch. However the Hashtable or more specifically the Hash maps - functions have given me quite some trouble. I have come across the MAD (Multiply, Add, Divide) function which basically is: h(x) = [(a*x + b) % p] % N, where a,b : random integers, p : large prime number and N : number of elements in hashtable. My question is how (and why) exactly does this function distribute evenly the values in the hashtable. h(x) = [(a*x + b) % p] % N Let's look at a*x + b in isolation

Hashtable and list side by side?

谁说我不能喝 提交于 2019-12-06 14:33:55
问题 I need a data structure that is ordered but also gives fast random access and inserts and removes. Linkedlists are ordered and fast in inserts and removes but they give slow random access. Hashtables give fast random access but are not ordered. So, it seems to nice to use both of them together. In my current solution, my Hashtable includes iterators of the list and the List contains the actual items. Nice and effective. Okay, it requires double the memory but that's not an issue. I have heard

Is it possible to initialize a .NET type with properties?

天涯浪子 提交于 2019-12-06 14:25:21
For example I want use this class Microsoft.HyperV.PowerShell.HardDiskDrive I tried to initialize it by this way: $obbb = [Microsoft.HyperV.PowerShell.HardDiskDrive]@{ Path = 'D:\\TEST\\test\\Virtual Hard Disks\\test.vhdx' DiskNumber = $null MaximumIOPS = '1000' MinimumIOPS = '0' QoSPolicyID = '00000000-0000-0000-0000-000000000000' SupportPersistentReservations = $false WriteHardeningMethod = '0' ControllerLocation = '0' ControllerNumber = '0' ControllerType = '0' Name = 'Hard Drive on IDE controller number 0 at location 0' PoolName = 'Primordial' Id = 'Microsoft:480244F9-44D4-4BFC-B34B

How does Python implement dictionaries?

左心房为你撑大大i 提交于 2019-12-06 13:27:47
问题 I was wondering how python dictionaries work under the hood, particularly the dynamic aspect? When we create a dictionary, what is its initial size? If we update it with a lot of elements, I suppose we need to enlarge the hash table. I suppose we need to recompute the hash function to adapt the size of the new bigger hash table while keeping a kind of logic with the previous hash table? As you can see, I do not fully understand the internal of this structure. 回答1: (some of) The following

Java hashtable with separate chaining collision resolution?

久未见 提交于 2019-12-06 12:13:35
I have created a program using the built in java.util.hashtable but now I need to resolve collisions using separate chaining. Is it possible with this implementation of a hashtable? Is there one out there already implemented that uses separate chaining? Looking at the source of the Hashtable implementation, it looks like it already uses separate chaining. If you look at the Entry<K,V> class starting at line 901, you'll see that it has a reference to another Entry named next . If you then look at the put() method, on line 420 the next reference is populated via the constructor to be whatever

Sort Hashtable by (possibly non-unique) values

时光毁灭记忆、已成空白 提交于 2019-12-06 07:46:22
问题 I have a Hashtable that maps strings to ints. Strings are unique, but several may be mapped to the same integer. My naive approach was to simply invert the Hashtable to a SortedList that is indexed by the Hashtable's values, but the problem is that you get a clash as soon as two of the Hashtable's strings map to the same value. What is the most efficient way to list my entire Hashtable (keys and values) ordered by the values? (Where two values are the same, I don't care about their ordering.)

When should I do rehashing of entire hash table?

拥有回忆 提交于 2019-12-06 07:12:19
问题 How do I decide when should I do rehashing of entire hash table? 回答1: This depends a great deal on how you're resolving collisions. If you user linear probing, performance usually starts to drop pretty badly with a load factor much higher than 60% or so. If you use double hashing, a load factor of 80-85% is usually pretty reasonable. If you use collision chaining, performance usually remains reasonable with load factors up to around 150% or or more. I've sometimes even created a hash table

How can I test that ConcurrentHashMap is truly thread-safe?

纵然是瞬间 提交于 2019-12-06 06:55:17
Just learning more about threads and concurrency, and thought of playing around with a regular hashtable and a ConcurrentHashMap. What would be a good way to test for concurrency for these hashtables? (obviously the hash table will fail this test) It would be cool if I could also somehow keep track of how many reads/writes the test performs to see which one (ht or conccurrent ht) faster. John Vint This is an answer to your last edit about how you can test it. This also touches on Hot Licks comment. In practice you can't really test thread safety as it is highly non-deterministic and failures