hashtable

Simple hash functions

大城市里の小女人 提交于 2019-11-28 15:39:15
问题 I'm trying to write a C program that uses a hash table to store different words and I could use some help. Firstly, I create a hash table with the size of a prime number which is closest to the number of the words I have to store, and then I use a hash function to find an address for each word. I started with the simplest function, adding the letters together, which ended up with 88% collision. Then I started experimenting with the function and found out that whatever I change it to, the

Hash Table - Sort in order of how they are input

我是研究僧i 提交于 2019-11-28 14:32:25
I have a hash table here and I have it eventually outputting to an Excel spreadsheet, but the issue appears to be the way the system sorts the hash table by default. I want it to return the machines in the same order that they are inputted, they way it currently works is a box pops up and you paste in all your machine names so they are all in memory prior to the foreach loop. I was previously sorting this by the longest uptime but it now needs to be the same way they are inputted. My initial thought is to create another hash table and capture them in the same order versus the $machineList

HashTable Insert Failed. Load Factor Too High. .NET 2.0 SP2

狂风中的少年 提交于 2019-11-28 14:29:52
We've just encountered this error on our web app, and immediately found the article here Hashtable insert failed. Load factor too high. - ASP.NET 2.0 . However, the hotfix that this points to ( http://support.microsoft.com/?id=927579 ) was already included in .NET 2.0 SP1 ( http://support.microsoft.com/kb/945757 ). A restart of the WWW Publishing Service made it go away. Does anyone know of any other valid conditions where this can occur? And how to make sure they don't happen? Thanks. Edit: I believe this could also be linked to another issue we're having with a Dictionary object stored in

Custom HashMap Code Issue

爷,独闯天下 提交于 2019-11-28 14:19:50
I have following code, where I used HashMap (using two parallel arrays) for storing key-value pairs (key can have multiple values). Now, I have to store and load it for future use that's why I store and load it by using File Channel. Issue with this code is: I can store nearly 120 millions of key-value pairs in my 8 GB server (actually, I can allocate nearly 5 gb out of 8 gb for my JVM, and those two parallel arrays takes nearly 2.5 gb, other memory are used for various processing of my code). But, I have to store nearly 600/700 millions of key-value pairs. Can anybdoy help me how to modify

PowerShell: Combine two hash tables

送分小仙女□ 提交于 2019-11-28 13:56:48
I have two hash tables created from data from two different XML files. What I would like to do is combine the two tables into a single hash table based on a common value in the both tables. Inv Hash: $invHash = $invXML.InventoryDto.ProductInventoryItem.SkuInventoryItem | select @{ L = 'SkuID'; E = { $_.SkuId } }, @{ L = 'SkuStatusCode'; E = { if ($_.SkuStatusCode -eq 'Active') { 'True' } else { 'False'} } }, @{ L = 'QuantityOnHand'; E = { $_.QuantityOnHand } } Sample Contents of $invHash: SkuID SkuStatusCode QuantityOnHand ----- ------------- -------------- 1828 True 441 3022 True 325 2981

Why is Dictionary.First() so slow?

久未见 提交于 2019-11-28 13:31:09
Not a real question because I already found out the answer, but still interesting thing. I always thought that hash table is the fastest associative container if you hash properly. However, the following code is terribly slow. It executes only about 1 million iterations and takes more than 2 minutes of time on a Core 2 CPU. The code does the following: it maintains the collection todo of items it needs to process. At each iteration it takes an item from this collection (doesn't matter which item), deletes it, processes it if it wasn't processed (possibly adding more items to process), and

Using IEqualityComparer GetHashCode with a tolerance

十年热恋 提交于 2019-11-28 12:46:33
I am trying to implement an IEqualityComparer that has a tolerance on a date comparison. I have also looked into this question . The problem is that I can't use a workaround because I am using the IEqualityComparer in a LINQ .GroupJoin() . I have tried a few implementations that allow for tolerance. I can get the Equals() to work because I have both objects but I can't figure out how to implement GetHashCode() . My best attempt looks something like this: public class ThingWithDateComparer : IEqualityComparer<IThingWithDate> { private readonly int _daysToAdd; public ThingWithDateComparer(int

C# Dictionary<> and mutable keys

烂漫一生 提交于 2019-11-28 12:10:08
I was told that one of the many reasons strings were made immutable in the C# spec was to avoid the issue of HashTables having keys changed when references to the string keys altered their content. The Dictionary<> type allows reference types to be used as a key. How does the dictionary avoid the issue of altered keys that lead to "misplaced" values? Is there a memberwise clone made of an object when used as a key? The Dictionary<TKey,TValue> type makes no attempt to protect against the user modifying the key used. It is purely left up to the developer to be responsible in not mutating the key

c++ - unordered_map complexity

喜夏-厌秋 提交于 2019-11-28 12:01:14
I need to create a lookup function where a (X,Y) pair corresponds to a specific Z value. One major requirement for this is that I need to do it in as close to O(1) complexity as I can. My plan is to use an unordered_map. I generally do not use a hash table for lookup, as the lookup time has never been important to me. Am I correct in thinking that as long as I built the unordered_map with no collisions, my lookup time will be O(1)? My concern then is what the complexity becomes if there the key is not present in the unordered map. If I use unordered_map::find():, for example, to determine

How to do associative array/hashing in JavaScript

◇◆丶佛笑我妖孽 提交于 2019-11-28 11:53:00
I need to store some statistics using JavaScript in a way like I'd do it in C#: Dictionary<string, int> statistics; statistics["Foo"] = 10; statistics["Goo"] = statistics["Goo"] + 1; statistics.Add("Zoo", 1); Is there an Hashtable or something like Dictionary<TKey, TValue> in JavaScript? How could I store values in such a way? Alek Davis Use JavaScript objects as associative arrays . Associative Array: In simple words associative arrays use Strings instead of Integer numbers as index. Create an object with var dictionary = {}; Javascript allows you to add properties to objects by using the