hashtable

Why use an array to implement a “list” instead of a hash table?

*爱你&永不变心* 提交于 2019-12-06 06:54:42
问题 Consider an array versus a hashtable where the keys are just the integral indexes of a list. Their average-case insertion, lookup, and removal big-O bounds are all O(1) constant time. I understand that you may get some low-level wins in cache locality with an array, and there is a marginal (mostly-constant) overhead to the hashtable operations, but hashtables get you sparseness for free, which in some applications is a big win. What other significant (or small) contrasts am I missing? Context

Timeout Mechanism for Hashtable

橙三吉。 提交于 2019-12-06 06:35:06
问题 I have a hashtable that under heavy-traffic. I want to add timeout mechanism to hashtable, remove too old records. My concerns are, - It should be lightweight - Remove operation has not time critical. I mean (timeout value is 1 hour) remove operation can be after 1 hour or and 1 hour 15 minute. There is no problem. My opinion is, I create a big array (as ring buffer)that store put time and hashtable key, When adding to hashtable, using array index find a next slot on array put time, if array

Does unordered_map iterator/reference invalidation allow for cuckoo, hopscotch, and robin hood hashing?

人走茶凉 提交于 2019-12-06 05:35:49
问题 I'm trying to figure out if it's possible to build a conformant, efficient implementation of modern C++'s std::unordered_map using techniques like Cuckoo Hashing, Hopscotch Hashing, and Robin Hood Hashing that allow for very compact tables, high load factors, and maintain high performance. What's special about these techniques is that they involve potentially moving some elements around to make room for others, rather than just chaining, or probing until an open slot is found (as in linear or

Why we need the IEqualityComparer,IEqualityComparer<T> interface?

断了今生、忘了曾经 提交于 2019-12-06 01:59:43
问题 the 'Equal' and 'GetHashcode' method are exist in the object class, and our type inherit the object base class. what's the different between implement the two methods of the object directly and using the IComparer interface? if we overriding object's Equal and GetHashCode , and push to a hashtable , it will use the overring 's equal method? what' the differents of new a hashtable with the IEqualityComparer constructor? 回答1: The IComparable interface is used when you need to be able to "sort"

Powershell: replacing in strings using a hashtable

走远了吗. 提交于 2019-12-06 00:53:28
Okay, so I've set up a hash table with names being what to replace and keys being what to replace with, like this: $r = @{ "dog" = "canine"; "cat" = "feline"; "eric" = "eric cartman" } What should I do next? I've tried this: (Get-Content C:\scripts\test.txt) | Foreach-Object { foreach ( $e in $r.GetEnumerator() ) { $_ -replace $e.Name, $e.Value } } | Set-Content C:\scripts\test.txt.out But it doesn't work at all, it just writes each line three times, without replacing anything. EDIT: Contains of test.txt: dog cat eric test.txt.out: dog dog dog cat cat cat eric eric eric Here's one way to do it

How does one retrieve the hash code of an enumeration without boxing it?

左心房为你撑大大i 提交于 2019-12-05 22:03:25
问题 If one has an enumeration stored inside an aggregate type, one might want to include that inside the type's hash code (assuming a typical "multiply by primes" hash function). If one just calls SomeEnum.GetHashCode() , it appears that the JIT boxes the instance, even in release builds. Profiling this shows some 10% of the time of my application spent boxing enumerations inside various GetHashCode functions. Several value types implement IEquatable or similar interfaces, which allows calling

Powershell error returning hashtable

[亡魂溺海] 提交于 2019-12-05 19:18:04
Anyone have any ideas why the following code would produce an error, see additional comments after the function for more details function callee ([Hashtable]$arg0) { [Hashtable]$hashtable = @{} $hashtable = $arg0 $hashtable.add('passed', $True) # $hashtable ######## toggle this line $type = $hashtable.GetType() Write-Host "$type" return $hashtable } function caller { [Hashtable]$hashtable = @{'00'='0'} $hashtable = callee $hashtable ##### returns error here $hashtable.add('returned', $True) $hashtable } caller error message: Cannot convert the "System.Object[]" value of type "System.Object[]"

Reversible dictionary for python

心不动则不痛 提交于 2019-12-05 19:17:45
问题 I'd like to store some data in Python in a similar form to a dictionary: {1:'a', 2:'b'} . Every value will be unique, not just among other values, but among keys too. Is there a simple data structure that I can use to get the corresponding object no matter if I ask using the 'key' or the 'value'? For example: >>> a = {1:'a', 2:'b'} >>> a[1] 'a' >>> a['b'] 2 >>> a[3] KeyError The 'keys' are standard python ints, an the values are short (<256char) strings. My current solution is creating a

Binary Search and Hashtable Search

谁说我不能喝 提交于 2019-12-05 17:53:21
I wanted to find out the trade off point between a Dictionary lookup and a binary search lookup of an array. I was expecting constant time lookups for the Dictionary, and logarithmic time lookups for the binary search depending on the size of the collection, with the binary search performing better for smaller sized collections. However, I was surprised when I saw the following results: I was surprised at: 1. Binary search is growing logarithmically at first, and then grows much faster. 2. Hash is pretty consistent at first, but then also starts growing slowly. 3. Binary search is never better

mmap vs O_DIRECT for random reads (what are the buffers involved?)

邮差的信 提交于 2019-12-05 12:33:34
I am implementing a disk based hashtable supporting large amount of keys (26+ million). The value is deserialized. Reads are essentially random throughout the file, values are less than the page size, and I am optimising for SSDs. Safety/consistency are not such huge issues (performance matters). My current solution involves using a mmap() file with MADV_RANDOM | MADV_DONTNEED set to disable prefetching by the kernel and only load data as needed on-demand. I get the idea that the kernel reads from disk to memory buffer, and I deserialize from there. What about O_DIRECT ? If I call read() , I'm