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
6
votes
2answers
167 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 ...
12
votes
5answers
22k views

Python Hash Table Implementation

I'm attempting to implement a basic hash table in Python using only lists. Any tips would be appreciated (including better hash functions). I intend this to handle collisions with separate chaining. ...
4
votes
2answers
79 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
56 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 ...
1
vote
1answer
60 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 ...
4
votes
1answer
837 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 ...
4
votes
1answer
17k views

Convert Multivalued map to HashMap

I have a Multivalued map (javax.ws.rs.core.MultivaluedMap<String, String>) which I want to convert to regular HashMap so I got below code: ...
2
votes
1answer
65 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: ...
5
votes
1answer
179 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 ...
1
vote
1answer
493 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
134 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 ...
30
votes
0answers
948 views

Making a generic NSMapTable replacement written in Swift thread-safe

This is a follow-up to this question. While discussing some details about the code I posted there, I came upon a problem with thread-safety. After searching and trying different things, I reached a ...
3
votes
1answer
690 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 ...
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: ...
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
173 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....
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 ...
4
votes
1answer
447 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 ...
6
votes
1answer
195 views

Overlapping table fragments

One of my side projects is a table driven scanner/parser generator, in an effort to reduce the size of the transition table I represent the generated table A[x, y] ...
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
70 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
0answers
73 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 ...
4
votes
3answers
69k views

Check for null/empty in dictionary

I am doing the following about 10 times with other strings, so the code is duplicated. How can I refactor this? queryWhere is a ...
5
votes
1answer
1k 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
2answers
547 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? ...
2
votes
1answer
533 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 ...
5
votes
2answers
1k 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
90 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
243 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
189 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 ...
4
votes
3answers
10k views

Most common occurrence of an int in an array

I am prepping for a junior level interview in C#. I am hoping I can get some feedback on how to improve my code to print the most common occurrence of an int in an ...
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 ...
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 ...
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 ...
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 ...
2
votes
2answers
7k views

Merge array of hashes, keeping duplicate values as arrays

I am working on a Ruby gem to pull data from the Wikidata API. The data is deeply nested, as it contains a lot of repetition. I have written a piece of Ruby (sans Rails) code that enables an array ...
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. ...
4
votes
2answers
18k views

Mapping object values from one object to another

I have an object called defaultOptions and a function that accepts as an argument an object called newValues meant to override ...
3
votes
4answers
3k views

C hashtable implementation

The following code is an implementation of an hashtable in C. hashTable.c: ...
1
vote
2answers
485 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
104 views

HashMap Implemention in Java

I just finished implementing a HashMap in Java, with methods: add(String key, Integer value) get(String key) ...
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
53 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. ...
7
votes
2answers
30k views

Simple string hashing algorithm implementation

I thought of a simple way to hash a string. By taking the ASCII decimal value of each character, multiplying it by 10, and adding all of the values computed together for each character in a string. Is ...
4
votes
1answer
209 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
172 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 ...

1
2 3 4 5 6