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.

Filter by
Sorted by
Tagged with
1
vote
1answer
32 views

Designing a hashset with LinkedLists as buckets

I am solving a problem on Leetcode that requires me to design a hash set. I intend to solve it using linked lists where each linked list would represent a bucket. I am intending to implement this: ...
6
votes
2answers
169 views

C simple hashcons data structure

I wrote this hashcons data structure in C and it works correctly. It uses larger twin primes as the capacity and double hashing (open addressing). Page 614 of "Data Structures and Other Objects ...
5
votes
2answers
87 views

C Hash table implementation

I have written a pretty simple hash table in C. It uses a prime modulus, linear probing, open addressing, and robin hood hashing. The program can also be found on GitHub. For clarification, ...
3
votes
1answer
58 views

Implement hash table using linear congruential probing in python

I have just read the Chapter 5 of Data Structures and Algorithms with Python. The authors implemented hash sets using linear probing. However, linear probing may result in lots of clustering. So I ...
2
votes
1answer
61 views

Hash table in Java with arrays and linear probing

I did some manual tests by instantiating the class and it seems to be working okay. I wanted some feedback on the following: Is the code well structured? I notice I have a lot of redundancy. The ...
2
votes
1answer
67 views

SHA256 javascript implementation

I implemented a sha256 hash function for javascript just for a practice and I want to know if my code needs more improvement. Please tell me which to simplify if there's any. Thanks. Here is my code: ...
2
votes
1answer
62 views

Python Hash Table implemented using lists

I implemented a Python Hash Table using only lists. Here is my implementation: ...
1
vote
1answer
529 views

HashTable implementation in Python 3

I have implemented a hash table. It works well. But if you think something needs to be improved, say it. This code was tested in Python 3.7.4. ...
3
votes
2answers
91 views

Large matrix with lots of repetitive fields (C++)

I wrote a timetabling program and I have been using a matrix to check for clashes between courses. Index (i, j) in the matrix ...
3
votes
0answers
141 views

Implementation of a hash table using safe Rust

I just finished reading the rust book and I am doing lots of little projects to practice and try to get better at writing idiomatic Rust. One of them involves implementing a hash table (I find it's ...
2
votes
2answers
55 views

Hash table implementation in C for a simple table record

I have a requirement to implement this simple table from one of the DVB S2X standards. The table is relatively small that contains no more than 28 rows. I need to use the key for the table as the ...
2
votes
0answers
182 views

Solution to 3Sum problem on Leetcode using HashTable

The problem of 3sum is described as: Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero....
4
votes
1answer
454 views

Hash table implementation in Python

I wrote an implementation of a hash table in Python. This implementation uses chaining for handling collisions, based on lists. I also use an expansion/shrink factor of 2. The expansion is done ...
10
votes
3answers
2k views

Yet another hash table in C

Will be very grateful for thoughtful code review. I needed hash table (again) and I wrote one. Code here is here or inline: ...
4
votes
1answer
80 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 ...
11
votes
3answers
2k 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
71 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 ...
5
votes
1answer
185 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
74 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
2k 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
93 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
267 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
206 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
57 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
134 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
85 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
77 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
44 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
154 views

Hash table in Python

...
3
votes
1answer
762 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
494 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
106 views

HashMap Implemention in Java

I just finished implementing a HashMap in Java, with methods: add(String key, Integer value) get(String key) ...
4
votes
1answer
860 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
542 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
1k 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
54 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
214 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
173 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
3k 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
510 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
94 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
448 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, ...
13
votes
2answers
4k 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
181 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
934 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 the ...
6
votes
1answer
3k 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
79 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
1k 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
559 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
1k 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 ...

1
2 3 4 5 6