hashtable

C - Segmentation Fault with strcmp?

与世无争的帅哥 提交于 2019-11-26 06:49:39
问题 I appear to be getting a segmentation fault somewhere with the strcmp function. I\'m still very new to C and I can\'t see why it gives me the error. int linear_probe(htable h, char *item, int k){ int p; int step = 1; do { p = (k + step++) % h->capacity; }while(h->keys[p] != NULL && strcmp(h->keys[p], item) != 0); return p; } gdb: Program received signal SIGSEGV, Segmentation fault. 0x0000003a8e331856 in __strcmp_ssse3 () from /lib64/libc.so.6 (gdb) frame 1 #1 0x0000000000400ea6 in linear

Hash Table/Associative Array in VBA

北战南征 提交于 2019-11-26 06:37:35
问题 I can\'t seem to find the documentation explaining how to create a hash table or associative array in VBA. Is it even possible? Can you link to an article or better yet post the code? 回答1: I think you are looking for the Dictionary object, found in the Microsoft Scripting Runtime library. (Add a reference to your project from the Tools...References menu in the VBE.) It pretty much works with any simple value that can fit in a variant (Keys can't be arrays, and trying to make them objects

Associative arrays in Shell scripts

假如想象 提交于 2019-11-26 06:04:25
问题 We required a script that simulates Associative arrays or Map like data structure for Shell Scripting, any body? 回答1: To add to Irfan's answer, here is a shorter and faster version of get() since it requires no iteration over the map contents: get() { mapName=$1; key=$2 map=${!mapName} value="$(echo $map |sed -e "s/.*--${key}=\([^ ]*\).*/\1/" -e 's/:SP:/ /g' )" } 回答2: Another option, if portability is not your main concern, is to use associative arrays that are built in to the shell. This

PSCustomObject to Hashtable

只愿长相守 提交于 2019-11-26 05:58:35
问题 What is the easiest way to convert a PSCustomObject to a Hashtable ? It displays just like one with the splat operator, curly braces and what appear to be key value pairs. When I try to cast it to [Hashtable] it doesn\'t work. I also tried .toString() and the assigned variable says its a string but displays nothing - any ideas? 回答1: Shouldn't be too hard. Something like this should do the trick: # Create a PSCustomObject (ironically using a hashtable) $ht1 = @{ A = 'a'; B = 'b'; DateTime =

How to do associative array/hashing in JavaScript

点点圈 提交于 2019-11-26 05:34:14
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

Tuples( or arrays ) as Dictionary keys in C#

回眸只為那壹抹淺笑 提交于 2019-11-26 04:43:01
问题 I am trying to make a Dictionary lookup table in C#. I need to resolve a 3-tuple of values to one string. I tried using arrays as keys, but that did not work, and I don\'t know what else to do. At this point I am considering making a Dictionary of Dictionaries of Dictionaries, but that would probably not be very pretty to look at, though it is how I would do it in javascript. 回答1: If you are on .NET 4.0 use a Tuple: lookup = new Dictionary<Tuple<TypeA, TypeB, TypeC>, string>(); If not you can

Is a Python dictionary an example of a hash table?

限于喜欢 提交于 2019-11-26 04:05:26
问题 One of the basic data structures in Python is the dictionary, which allows one to record \"keys\" for looking up \"values\" of any type. Is this implemented internally as a hash table? If not, what is it? 回答1: Yes, it is a hash mapping or hash table. You can read a description of python's dict implementation, as written by Tim Peters, here. That's why you can't use something 'not hashable' as a dict key, like a list: >>> a = {} >>> b = ['some', 'list'] >>> hash(b) Traceback (most recent call

Looking for a good hash table implementation in C [closed]

为君一笑 提交于 2019-11-26 03:49:57
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I am primarily interested in string keys. Can someone point me towards a library? 回答1: I had the same need and did some research and ended up using libcfu It's simple and readable so if I have a need to modify, I can do it without spending too much time to understand. It's also of BSD license. No need to change

What&#39;s a correct and good way to implement __hash__()?

左心房为你撑大大i 提交于 2019-11-26 03:29:29
问题 What\'s a correct and good way to implement __hash__() ? I am talking about the function that returns a hashcode that is then used to insert objects into hashtables aka dictionaries. As __hash__() returns an integer and is used for \"binning\" objects into hashtables I assume that the values of the returned integer should be uniformly distributed for common data (to minimize collisions). What\'s a good practice to get such values? Are collisions a problem? In my case I have a small class

Good Hash Function for Strings

寵の児 提交于 2019-11-26 03:24:30
问题 I\'m trying to think up a good hash function for strings. And I was thinking it might be a good idea to sum up the unicode values for the first five characters in the string (assuming it has five, otherwise stop where it ends). Would that be a good idea, or is it a bad one? I am doing this in Java, but I wouldn\'t imagine that would make much of a difference. 回答1: Usually hashes wouldn't do sums, otherwise stop and pots will have the same hash. and you wouldn't limit it to the first n