hashtable

Constructing a hash table/hash function

你说的曾经没有我的故事 提交于 2019-12-07 06:54:05
问题 I would like to construct a hash table that looks up keys in sequences (strings) of bytes ranging from 1 to 15 bytes. I would like to store an integer value, so I imagine an array for hashing would suffice. I'm having difficulty conceptualizing how to construct a hash function such that given the key would give an index into the array. Any assistance would be much appreiated. The maximum number of entries in the hash is: 4081*15 + 4081*14 + ... 4081 = 4081((15*(16))/2) = 489720. So for

What happens at a hardware level when I access an element of an array?

寵の児 提交于 2019-12-07 06:30:25
问题 int arr [] = {69, 1, 12, 10, 20, 113}; What happens when I do int x = a[3]; ???? I was always under the impression that a[3] meant something like: " Start at the memory address arr . Walk 3 memory addresses forward. Get the integer represented at that memory address. " But then I'm confused about how hash tables work. Because if hash tables are implemented as an array of "buckets" (like the professor says in this lecture: https://www.youtube.com/watch?v=UPo-M8bzRrc), then you still have to

How do you use (get values from keys, add items) Hashtables in F#

三世轮回 提交于 2019-12-07 04:44:07
问题 I would like to know how to use a System.Collections.Hashtable in F#. The reason it is a Hashtable is because I am referencing C# assemblies. How would I call the following methods? - Add - Get value from key I have not been able to find anything useful in Google about this. 回答1: As Mark points out, you can work with the Hashtable type directly from F# (just like with any other .NET type). The syntax for accessing indexers in F# is slightly different though: open System.Collections // 'new'

Format a nested hashtable

社会主义新天地 提交于 2019-12-07 03:44:45
问题 Given a hashtable that contains heterogeneous data such as: $items = @{ a = @{a1 = "A1"; a2 = "A2"; a3 = "A3" } b = 1234 c = @{c1 = "C1"; c2 = "C2"; c3 = "C3" } d = [DateTime]::Now } When I attempt to display the contents using the following: $items | Format-Table -AutoSize The output is: Name Value ---- ----- c {c3, c1, c2} d 05/23/15 11:37:56 b 1234 a {a2, a3, a1} But how can I expand the contents of the nested hashtables so that I can see the key-value pairs such as: Name Value ---- -----

Using CLOS class instances as hash-table keys?

孤人 提交于 2019-12-07 03:38:57
问题 I have the following class: (defclass category () ((cat-channel-name :accessor cat-channel-name :initarg :cat-channel-name :initform "" :type string :documentation "Name of the channel of this category") (cat-min :accessor cat-min :initarg :min :initform 0 :type number :documentation "Mininum value of category") (cat-max :accessor cat-max :initarg :max :initform 1 :type number :documentation "Maximum value of category")) (:documentation "A category")) Now, I would like to use this class as a

Basic Hashtable algorithm - removing duplicates

隐身守侯 提交于 2019-12-07 02:40:04
问题 I just had an interview this morning and I was given the question "Give an algorithm for removing duplicates from a list of integers". This is a fairly standard question so I was pretty confident I could answer it. I am paraphrasing, but I said something along the lines of "You could use a hashtable. Start with the first integer and insert it into the hashtable. Then for each successive integer do a hashtable lookup to check if the integer is already in the hashtable, if not then insert it,

python 2.7 module pandas not installing “cannot import name hashtable”

拜拜、爱过 提交于 2019-12-07 00:02:31
问题 I tried looking for an answer to this around the forum/google, but I can't find anything. My issue is this (from python console): >>> import pandas cannot import name hashtable Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-packages\pandas\__init__.py", line 6, in <module> from . import hashtable, tslib, lib ImportError: cannot import name hashtable //also can't import name NaT somtimes I ran the windows 1-click installer prior to attempting

Serialize hashtable using Json.Net

独自空忆成欢 提交于 2019-12-06 16:21:15
I have a hashtable whose keys are of type integer, however when deserializing using json.net the keys come back as strings, is there a way to keep the key type on hashtable using json.net serialization/deserialization? This hashtable is a property of the type 'MyType' var settings = new JsonSerializerSettings(); settings.TypeNameHandling = TypeNameHandling.Objects; string json = JsonConvert.SerializeObject(o, Formatting.Indented, settings); mo = JsonConvert.DeserializeObject<MyType>(json, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects }); public Hashtable jsonViews {

What's the problem with this code? [hashtable in C]

混江龙づ霸主 提交于 2019-12-06 15:59:50
问题 I'm implementing a hash table. The following is my function for initializing it. Im getting some errors which I cant understand why. I have also quoted what valgrind says. typedef struct HashTable { int size ; struct List *head; struct List *tail; }HashTable; typedef struct List { char *number; char *name; int time; struct List *next; }List; #define size_of_table 211 HashTable *createHashTable(void) { HashTable *new_table = malloc(sizeof(*new_table)*size_of_table); //line 606 if (new_table ==

C++ hash table w/o using STL

浪尽此生 提交于 2019-12-06 15:40:01
I need to create a hash table that has a key as a string, and value as an int. I cannot use STL containers on my target. Is there a suitable hash table class for this purpose? Here's a quick a dirty C hash I just wrote. Compiles, but untested locally. Still, the idea is there for you to run with it as needed. The performance of this is completely dependant upon the keyToHash function. My version will not be high performance, but again demonstrates how to do it. static const int kMaxKeyLength = 31; static const int kMaxKeyStringLength = kMaxKeyLength + 1; struct HashEntry { int value; char key