Questions tagged [hashtable]

A hash table in programming is a collection that uses a hash function to map identifying values (keys) to their associated values.

The basic advantage of a hash table is that they provide very efficient lookup and search functionality. Unlike many other linear collection types (such as arrays and linked lists), one does not have to loop through all the elements in a hash table searching for a particular entity.

For Java: https://docs.oracle.com/javase/8/docs/api/java/util/Hashtable.html

5453 questions
126
votes
10 answers

How do HashTables deal with collisions?

I've heard in my degree classes that a HashTable will place a new entry into the 'next available' bucket if the new Key entry collides with another. How would the HashTable still return the correct Value if this collision occurs when calling for one…
Alex
  • 4,844
  • 7
  • 44
  • 58
126
votes
18 answers

Advantages of Binary Search Trees over Hash Tables

What are the advantages of binary search trees over hash tables? Hash tables can look up any element in Theta(1) time and it is just as easy to add an element....but I'm not sure of the advantages going the other way around.
Devoted
  • 177,705
  • 43
  • 90
  • 110
121
votes
8 answers

Looping through a hash, or using an array in PowerShell

I'm using this (simplified) chunk of code to extract a set of tables from SQL Server with BCP. $OutputDirectory = 'c:\junk\' $ServerOption = "-SServerName" $TargetDatabase = "Content.dbo." $ExtractTables = @( "Page" ,…
Sylvia
  • 2,578
  • 9
  • 30
  • 37
112
votes
5 answers

Hash table runtime complexity (insert, search and delete)

Why do I keep seeing different runtime complexities for these functions on a hash table? On wiki, search and delete are O(n) (I thought the point of hash tables was to have constant lookup so what's the point if search is O(n)). In some course…
user1136342
  • 4,731
  • 10
  • 30
  • 40
100
votes
4 answers

Hash Table/Associative Array in VBA

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?
Tyler
  • 4,679
  • 12
  • 41
  • 60
99
votes
10 answers

Super high performance C/C++ hash map (table, dictionary)

I need to map primitive keys (int, maybe long) to struct values in a high-performance hash map data structure. My program will have a few hundred of these maps, and each map will generally have at most a few thousand entries. However, the maps will…
Haywood Jablomey
  • 1,011
  • 1
  • 8
  • 4
94
votes
2 answers

ConcurrentHashMap and Hashtable in Java

What is the difference between a ConcurrentHashMap and a Hashtable in Java? Which is more efficient for threaded applications?
sheidaei
  • 9,842
  • 20
  • 63
  • 86
92
votes
6 answers

Hash tables in MATLAB

Does MATLAB have any support for hash tables? Some background I am working on a problem in Matlab that requires a scale-space representation of an image. To do this I create a 2-D Gaussian filter with variance sigma*s^k for k in some range., and…
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
91
votes
4 answers

Why are there no hashtables in the C standard library?

Why is that there is no Hashtable support as part of Standard C Library? Is there any specific reason for this?
Shankar Raju
  • 4,356
  • 6
  • 33
  • 52
90
votes
10 answers

PSCustomObject to Hashtable

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()…
alphadev
  • 1,529
  • 5
  • 18
  • 20
90
votes
5 answers

Hash tables VS associative arrays

Recently I have read about hash-tables in a very famous book "Introduction to Algorithms". I haven't used them in any real applications yet, but want to. But I don't know how to start. Can anyone give me some samples of using it, for example, how to…
Bakhtiyor
  • 7,198
  • 15
  • 55
  • 77
88
votes
2 answers

Does "put" overwrite existing values?

New to hashtables with a simple question. For some reason googling hasn't gotten me a straight answer. Say I've got an hashtable set up: myHashtable.put(1,"bird"); myHashtable.put(2,"iguana"); and I want to change "bird" to "fish"…
Ben
  • 54,723
  • 49
  • 178
  • 224
86
votes
16 answers

Hashtable with MultiDimensional Key in C#

I'm basically looking for a way to access a hashtable value using a two-dimensional typed key in c#. Eventually I would be able to do something like this HashTable[1][false] = 5; int a = HashTable[1][false]; //a = 5 This is what I've been…
Scott Schulthess
  • 2,853
  • 2
  • 27
  • 35
82
votes
9 answers

Why is accessing an element of a dictionary by key O(1) even though the hash function may not be O(1)?

I see how you can access your collection by key. However, the hash function itself has a lot of operations behind the scenes, doesn't it? Assuming you have a nice hash function which is very efficient, it still may take many operations. Can this be…
monogate
  • 1,419
  • 1
  • 11
  • 16
79
votes
1 answer

Why does my Intel Skylake / Kaby Lake CPU incur a mysterious factor 3 slowdown in a simple hash table implementation?

In short: I have implemented a simple (multi-key) hash table with buckets (containing several elements) that exactly fit a cacheline. Inserting into a cacheline bucket is very simple, and the critical part of the main loop. I have implemented three…
Marc Stevens
  • 1,628
  • 1
  • 6
  • 16