Questions tagged [hash-table]

A hash table is a data structure used to implement an associative array (a structure that can map keys to values). It uses a "hash function" to compute an index into an array from which the value can be found.

4
votes
1answer
59 views

Iterable hashtable implementation in C

I'm just finished my version of iterable hashtable. I want to review code in general (code style, data structures, remarks about the algorithms) and I have some questions: I don't know how to ...
10
votes
3answers
1k views

Find the common ancestor between two nodes of a tree

Here is my code in Python for to find a common ancestor between two nodes in a particular tree. This is a question from Cracking the Coding Interview that I decided to implement on my own. No one has ...
3
votes
1answer
49 views

Hashing array of strings as Merkle tree in one function

I want to hash an array of strings into one hash as shown on scheme on the image below. But I do not want to implement some class based Merkle tree. It's just a simple function. Is this a good ...
4
votes
1answer
75 views

Hashtable implementation in C for generic values

I am trying to implement a hashtable that supports character keys and can return any type of value contained in a struct as long as it contains as long as it contains ...
5
votes
0answers
67 views

Finding duplicates in an array using C [closed]

I came across a problem on LeetCode. There is an input array of integers. I need to find out if there any repeating integers, then return true else false. So, I tried using a hashtable library ...
5
votes
2answers
93 views

Hash table with dynamic sized array in C

To gain a broader insight in things many (high-level language) programmers nowadays take for granted, I decided to study some of the more basic ways of storing data in memory. I wrote a program which ...
3
votes
1answer
69 views

Generic Macro Generated Hashset in C

The Hashset uses open addressing, linear probing and Robin Hood hashing for handling collisions. It comes with insert and remove ...
2
votes
2answers
152 views

Consecutive words match in a dataset

I have written an algorithm to do consecutive word match in a dataset The input is a dataset (list of textlines) and I want to scan that and return repeated word(s)...
4
votes
2answers
115 views

Custom Hashset in Java

I have written this custom hashset and though it isn't completed yet, I would like to know if there is anything I am overlooking in terms of clean code conventions. My aim was also to apply generics ...
3
votes
1answer
43 views

unordered_set: a hash table -based set data structure in C89

In this post, I present a hash table -based set data structure written in C89: unordered_set.h ...
6
votes
2answers
112 views

Implementation of a simple hash function

This is my implementation of a hash function described below. The (compiled) program can be run as follows: $ java Hash1 < input.txt The program reads a text ...
9
votes
1answer
73 views

HashTable using C

Introduction This is my first attempt to mess with memory allocation using C and create something close to a python dictionary. Coming from a high level programming language like Python or Java, I am ...
3
votes
2answers
72 views

A HashTable optimised for a large in-memory storage

I've been making this pet project of mine which is an implementation of a HashTable for a very specific purpose: storing huge amounts of objects in-memory (think Redis). I ended up with this ...
3
votes
1answer
42 views

Hash table with complex variable-length keys

I'm trying to implement the game Snake in Javascript and getting the computer to play it by itself, and want to check whenever the snake loops (repeats the same set of moves twice) so I can kill it. ...
3
votes
1answer
92 views

Hash table in Python

...
2
votes
0answers
335 views

Rehashing a hash table in c++ with quadratic probing

The code below is my attempt at trying to create a hash table. I'm currently stuck with the rehash function as I think it's not efficient enough (I believe it's O(n^2). I'd be grateful if someone ...
1
vote
2answers
245 views

Quick & Simple Hash Table Implementation in C

First time implementing a hash table. I resolve collisions using the separate chaining method (closed addressing), i.e with linked lists. The hash function used is: ...
0
votes
1answer
90 views

HashMap Implemention in Java

I just finished implementing a HashMap in Java, with methods: add(String key, Integer value) get(String key) ...
1
vote
1answer
244 views

Hash Map implementation with a function to set all values

This is an interview question I saw online and thought to give it a try. The question is about implementing a hash map with a setAll(V value) function. This ...
2
votes
1answer
144 views

Using Java to implement a hash table (dictionary) with only arrays

I'm new to hash codes/hash tables, so I'm very unsure of my implementation. I want to create a hash table, but I can only use arrays. Specifically, I want to be able to insert things like a dictionary ...
0
votes
2answers
458 views

C++ - Hash map implementation using smart pointers

I am trying a simple Hash Map implementation in c++. I have used this and this as reference. The implemented design uses a class HashEntry to manage individual key-...
1
vote
1answer
46 views

hashtable search in JavaScript

I've implemented the search/insert part of a hashtable in JavaScript. This is in linear probing style. It resizes when the array is out of space. ...
4
votes
1answer
93 views

Hash table, using special values to mark empty and deleted indexes

The following is a program for my school. It's supposed to use a hashtable to store values/keys. We use a marking system to mark for empty indexes and deleted indexes. -1 for empty and -2 for deleted. ...
3
votes
1answer
133 views

Flood Fill using unordered_map which has user-defined type as key

I have an implementation of the flood fill algorithm. Assume that an image is provided as a vector of ...
6
votes
2answers
1k views

Phone book program using hash table in C++

I am a student and I am implementing data structures concept by myself using C and C++. I have implemented the concept of hash table here by making a "Phone book" program that takes input which ...
5
votes
1answer
144 views

Recursively generating the look-and-say sequence

I have a pattern where every number is counted by the number of repetitions. A new resulting number is formed by adding that repetition to the front of that value. The resulting pattern would look ...
3
votes
1answer
82 views

Pre-baked Hash table with a flat memory layout

A few notes: There is currently no non exception-based way of knowing whether a key is present in the table or not. This is intentional for my use case. Unlike the lookup process, the baking process ...
8
votes
3answers
353 views

Calculating effective shop inventories from CSV files

Program purpose The purpose for the program is to create a file containing the effective inventory for each stocked item stored in a collection of shops. Input and algorithm details For clarity, ...
10
votes
2answers
2k views

Hashtable Implementation - C

HashTable implementation The Specifics: It uses a simple hash function, it recieves a string and adds the ASCII values of each caracter, this can cause problems if the string is big, but for this ...
3
votes
0answers
130 views

HashTable with separate chaining and struct [closed]

I'm pretty new to C and I'm trying to implement a hashtable with chaining for a struct I created: HASH.h: ...
4
votes
2answers
435 views

Variant of 2-SUM Problem using Hashtable with multi-threading

I am doing a Coursera assignment on Hashtable and my solution is taking too long to run. Here is the problem as described in the assignment: The goal of this problem is to implement a variant of ...
6
votes
1answer
2k views

Hash table with separate chaining implementation in C

I'm attempting to implement a hash table with separate chaining in C. It works fine, but is there something that I should optimize, fix or maybe add some features? ...
4
votes
0answers
66 views

General Purpose C Dictionary

I'm trying to create a general purpose C dictionary (as an opaque data type) capable of dynamically allocating basic types (ints, floats, strings and longs) as well as accepting void pointers to ...
3
votes
2answers
754 views

Hash Table Implementation using Java

Looking for feedback on my java hash table implementation. Code uses an array of lists of entries as a sort of separate-chaining; not sure how much I prefer this approach in practice, and am ...
3
votes
2answers
391 views

Detecting a loop in a Linked list using a hashset

I was wondering if detecting a loop in a linked list using a HashSet is better than using two pointers? ...
0
votes
1answer
832 views

It is a hashmap, using linear probing on an array

I have been studying hashtable for two days and was musterring up the courage to write a code. Finally I have written code in which I have taken many shortcuts: The first being I have used ...
2
votes
1answer
161 views

Bidirectional hash map in Java

I have this bidirectional hash map that allows not just accessing values via keys, but also accessing keys via values. You can find a figure explaining the data structure in this post: Bidirectional ...
4
votes
1answer
589 views

Basic Implementation of Hash Table in Python

Basic impl of hash_table in python. Supports set, get, and delete. Uses open addressing with linear probing function. Any ideas would be greatly appreciated! Thanks! ...
0
votes
2answers
456 views

Data structure to count occurrences of words

I have some code for a assignment where the main marks are awarded based on efficiency. The program uses a given wordgenerator which generates random words and adds them to a user-made data structure. ...
3
votes
1answer
600 views

Python Hash Table and insertion

I'm attempting to implement a basic hash table in Python using linked lists. Any tips would be appreciated (including better hash functions). I intend this to handle collisions with separate chaining. ...
1
vote
2answers
2k views

Bloom filter implementation in C++

This is a bloom filter implementation in C++. To instantiate the BloomFilter class, supply it with the number of bool cells, and ...
1
vote
0answers
406 views

Direct address hash table

Note: I do know that Python libraries provide better solutions. This implementation has been done to practice python, data structures and Algorithms. This is a implementation of Direct-address hash ...
6
votes
3answers
6k views

Hash table implementation in c

This implementation resolves collisions using linked-lists. The hash function is from K&R but can be easily changed to more effective one. hash.c: ...
3
votes
1answer
262 views

HashMap in Javascript

I began working on a Javascript project, and the first fundamental building block is a data structure that mimics Java's java.util.HashMap, since Javascript ...
4
votes
1answer
121 views

Spatial Hash for optimizing AABB collisions

grid.h ...
5
votes
1answer
876 views

LRU Cache Implementation with HashTable and LinkedList

Problem Statement: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the value (will always be ...
3
votes
1answer
237 views

Half generic hash table

After alot of reading and testing I've created a "half generic" hash table. What I mean by half generic is that the struct that I'm using have a name variable which is ...
3
votes
4answers
2k views

C hashtable implementation

The following code is an implementation of an hashtable in C. hashTable.c: ...
4
votes
1answer
1k views

HashTable implementation using bucket lists

I wrote an implementation of a HashTable that uses bucket lists to store the key-value pairs implemented with a linked list. Here's the header: ...
6
votes
0answers
96 views

Bidirectional bijective hash map in C

I have this bidirectional hash map in C for dealing with bijective maps. Each key mapping consists of a primary key and a secondary key, and I can ask the data structure to give me a secondary key ...