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
29
votes
0answers
883 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 ...
24
votes
8answers
46k views

LINQ approach to flatten Dictionary to string

I have a Dictionary<string,string> and want to flatten it out with this pattern: ...
24
votes
2answers
1k views

Mapping arbitrary Int values to a linear index space

This is part of a growing "primitive" tools collection here on github, and is the initial use-case for the IntArray for review here. Often, when processing data, you encounter unique values that you ...
19
votes
3answers
51k views

Java implementation of spell-checking algorithm

This little program was written for an assignment in a data structures and algorithms class. I'll just note the basic requirements: Given an inputted string, the program should check to see if it ...
13
votes
3answers
7k views

HashTable implementation in C++

I made a simple hash table and I was wondering if there was any way to increase the efficiency of search times. My table class is called Dictionary, because C# has ...
12
votes
2answers
32k views

HashTable implementation

I have been trying to implement the Hash Table function in Java and here is what I came up with. I would just like to get an opinion on this work. Would there be a better way or any improvement to ...
12
votes
3answers
11k views

Simple C# HashTable Implementation

Haven't put one of these together since college. How does this look overall? ...
12
votes
2answers
27k views

Perfect Hashing Implementation

I'm building a hash table for this problem: Implement a class for storing a set of integers: ...
11
votes
2answers
3k 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 ...
11
votes
2answers
22k views

Hash table implementation in Java

For class, I was asked to write a (linear probing) hash table in Java. (I was also asked to write a linear-chaining hash table, which is why I named this one ...
11
votes
2answers
4k views

Improving HashMap in C++

I have created a HashMap<string,int> in C++. I would like help determining if it is good or bad. I have not handled the errors or successes with messages. I ...
11
votes
1answer
416 views

OOP paradigm implementation of a Dictionary data model

Here is the implementation of interface Dictionary using chained hash table class HashTableChained. Despite item 22* saying ...
10
votes
4answers
1k views

Strategy pattern - design hash table

My programming skill has gotten rusty, so I would like to elicit constructive criticism that can make me write code better. I know the standard design is to use templates, and even obtain the hash ...
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: ...
10
votes
2answers
4k views

Checking for any character common to two strings — Go is 50× slower than Python

I decided to learn Go, knowing Python. My approach is by solving easy problems like this one: You are given two strings, A and B. Find if there is a substring that appears in both A and B. ...
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 ...
10
votes
5answers
18k 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. ...
10
votes
2answers
758 views

Cash Register Kata

The Setup This kata is a spin on the old backpack problem. Please give feedback on both the kata itself as well as my solution. I'm not sure if the kata needs to lead the student more or if this is a ...
10
votes
1answer
330 views

ConcurrentDecayingHashMap<K,V>, a concurrent decaying HashMap

I wrote a wrapper for Java's ConcurrentHashMap that enables you to add a decay time to inserted values, meaning they will be automatically removed after the given ...
10
votes
1answer
206 views

BiDirectional Dictionary (and its Mutable friend can come too)

I've attempted to implement a 1-to-1 dictionary in Objective-C. I'm probably missing some convenient methods that one might commonly want to use. These are both declared in the same ...
10
votes
1answer
886 views

Object pool implementation

Below is my implementation of a pool. It is based on a hash table and supports using strong, soft or weak references to store objects. At the start there is a builder class to configure and create ...
10
votes
1answer
3k views

HashMap and HashSet classes for ES6

The new EcmaScript standard, ES6, contains specifications for Map and Set built-in classes. Each of these collections treats an ...
9
votes
2answers
12k views

Convert a list of dictionaries to a dictionary of dictionaries

I need to convert a list of dictionaries to a dictionary of dictionaries, with a particular item as the new key. This is the way I'm currently doing it: ...
9
votes
3answers
2k views

Recursive Insertion in Hash Table (Linear Probing)

I was practicing implementing a hash function. I tried to use linear probing to insert in hash table. The insertion is working alright but I am not satisfied with the recursion. It doesn't feel like "...
9
votes
1answer
76 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 ...
8
votes
2answers
490 views

method to decide if two strings are anagrams

I'm studying with the Cracking the Code Interview book. I'm just looking for some feedback on this method: C++ ...
8
votes
3answers
2k views

Initialize a hash with all 0 values based on two arrays

Given two arrays (for instance a list of people and a list of subjects), I need to initialise a Hash with all zeros for all possible combinations of these two ...
8
votes
3answers
11k views

Replace keys in values with key->values from same dictionary

I have a dictionary whose values may contain keys that are already in the dictionary. What we are actually talking about are parameters. Sometimes a parameter is defined by a number plus another ...
8
votes
1answer
29k views

A dictionary that allows multiple keys for one value

I'm trying to learn to program on my own with the help of books and the Internet and thought I'd start a project (a sub-project for a project). I want to build a dictionary that allows multiple keys ...
8
votes
3answers
25k views

Map with different types for values

I am trying to implements a map (that can work as a cache) that has strings as keys and values of different types. In my real case once set the key/values in the map will not change. I used these ...
8
votes
1answer
2k views

Dictionary (with silly hash)

Based on this question (but fixed so it can run). I have kept the code as close to the original as possible. I have Marked all the changes with Loki (should be easy to spot). Code here is written in ...
8
votes
3answers
378 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, ...
8
votes
1answer
204 views

Calculating protein mass

This question is part of a series solving the Rosalind challenges. For the previous question in this series, see A sequence of mistakes. The repository with all my up-to-date solutions so far can be ...
8
votes
2answers
721 views

Hash table OOP implementation in C

To brush up my C I decided to do some OOP programming in C. I have never tested this before, but I was curious to try it since seeing an example of it a while ago. I decided to implement a simple hash ...
7
votes
2answers
27k 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 ...
7
votes
3answers
13k views

Two Key HashMap

Background Would like to create a two-key map that is fairly generic. In the existing system, there are a number of ways to name a parameter for a report. Rather than re-writing each report (too much ...
7
votes
3answers
17k views

Implementation of hash map

I was asked to implement a hash map in this phone interview (screen-share), so time was limited and this is what I came up with. I'd appreciate if someone can take a minute to critique/review it and ...
7
votes
2answers
2k views

Generic NSMapTable replacement written in Swift

This is my attempt at writing a generic NSMapTable with weak keys and strong values (after your feedback I'll be trying to write Strong-Key/Weak-Value and Weak-Key/...
7
votes
2answers
1k views

Trie key/value store implementation comparing with HashMap

I have implemented a Trie-based concurrent key/value store using hashcode similar to HashMap. It is something like, if your ...
6
votes
5answers
10k views

Finding the most common character in a string with a hash map

I created a method for finding the most common character in a string (using HashMap): ...
6
votes
3answers
5k views

Simple cache dictionary

I decided to write a simple dictionary to use as a cache: ...
6
votes
2answers
2k 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 ...
6
votes
2answers
519 views

VSTO Write Dictionary To Range Extension Method

I was hoping to receive some criticism on this block of code. I wrote it to write the contents of a dictionary to excel range in VSTO. It works well. I am interested to see how people could improve it....
6
votes
2answers
119 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 ...
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: ...
6
votes
2answers
1k views

Hash table based key/value dictionary in C++ with murmur hash function, linked list buckets in 200 LOC

hashdic.h -- suggested for direct include or copy paste to your project. ...
6
votes
4answers
6k views

Hash table and linked list implementation in C++

I'm trying to improve my understanding of inheritance and template classes in C++ so I coded a hash table (see compilable source code below). I would be greatly appreciative of any comments on how to ...
6
votes
2answers
2k views

Recursively merge dictionaries with generic types in C#

I am looking to implement a method that is capable of merging 2 dictionaries using generics. I've seen several great answers on SO already, but none handle the case of nested dictionaries. As in, what ...
6
votes
2answers
4k views

The most efficient way to merge two lists in Java

I am looking for a way to merge two files with a list of distinct words, one word per line. I have to create a new txt file that would contain all the words of the first list and all the words from ...
6
votes
2answers
4k views

“Invert” a JavaScript object hash whose values are arrays to produce a new object hash with keys as the elements of those original value vectors

Background lodash and underscore have an invert function that takes an object hash and converts it to a new one, which has keys as the input object's values and ...