Questions tagged [hash-map]

A data structure that uses a hash function to map identifying values, known as keys, to their associated values

Filter by
Sorted by
Tagged with
8 votes
1 answer
3k views

Dictionary<TKey, TValue> Implementation

This class encapsulates a List<KeyValuePair> (see List<T> implementation here, and ...
Mathieu Guindon's user avatar
5 votes
2 answers
264 views

Genericizing PropertyValues

This should be the last iteration for this code. Does this approach make sense or am I heading down the wrong path? The only thing I can see to make this better is to genericize the ...
Gabriel W's user avatar
  • 371
2 votes
3 answers
1k views

LeetCode 49: Group Anagrams

I'm exceeding the time limit for a 10,000 word test case provided on LeetCode: Given an array of strings, group anagrams together. For example, given: ...
boltthrower's user avatar
8 votes
0 answers
1k views

IndexedArray Class: Uses a Dictionary Keys to Index a 2 Dimensional Array of Values

This class encapsulates a 2D Array and a Scripting Dictionary. Values are add or returned from to the Array using a Key and a ColumnIndex, e.g. ...
TinMan's user avatar
  • 4,133
7 votes
2 answers
9k views

Traversing and printing complex Dictionary types (Scripting.Dictionary) - Dictionary inside of a Dictionary

Based on this SO post - also reposted on vba4all.com with a few more details and explanations. Please notice there currently is no error handling whatsoever as I didn't analyse and consider any traps ...
user avatar
7 votes
2 answers
209 views

Unicode-capable symbol table (N-way search tree with hash buckets)

As in my previous question, this module is coupled with its own testing framework. As a symbol-table for a Unicode-capable programming language interpreter, I decided to combine the 3 types of ...
luser droog's user avatar
  • 2,008
6 votes
2 answers
1k views

Hackerrank challenge - Dictionaries and Maps

This is a solution for the Day 8 hackerrank.com challenge. The basic idea of the challenge is to create a mapping of names to phone numbers based on the the given input, and later look up the phone ...
Lotix's user avatar
  • 63
4 votes
1 answer
84 views

Preparing tabular data to be sent as json

I query a database and pass the data for processing as a DataTable. After all computations (grouping, filtering, formatting etc.) I need to send it to a Web-Service ...
t3chb0t's user avatar
  • 44.2k
1 vote
0 answers
78 views

A simple Java integer hash set - follow-up

(See the previous version.) (See the next version.) After incorporating changes in the previous post, I came up with this implementation. However, I left hashing as it is. ...
coderodde's user avatar
  • 27k
29 votes
5 answers
51k views

Type-safe Dictionary for various types

Assume the following situation: you have an object that can store any object based on a key (basically, IDictionary<string, object>). You want to store ...
svick's user avatar
  • 24.2k
26 votes
2 answers
2k 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 ...
rolfl's user avatar
  • 97.3k
17 votes
1 answer
619 views

Python Dictionary Black Magic

I am defining a subclass of a the python dictionary object mpCmd where every item is converted to a lambda. The intended usage is that every item in the dictionary ...
cheezsteak's user avatar
  • 2,381
14 votes
5 answers
27k 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. ...
Brandon Deo's user avatar
13 votes
1 answer
6k views

Simple trie implementation in JavaScript

After experimenting with a sorted trie implementation in C, I felt that I understood tries pretty well, but was having trouble explaining how they work. Since the C code was based on existing code, I ...
Dagg's user avatar
  • 4,531
13 votes
3 answers
4k views

Codewars: Reduce strings to one character

I am trying to solve a puzzle in a performant way. This is the puzzle. Simply explained: you have a String and you must reduce it to one character with the given rules. This is the solution to the ...
Superluminal's user avatar
12 votes
4 answers
6k views

Extraction of value from a dict-tree, given a path of arbitrary length

Problem: We read a complex json-file which grants us a tree in terms of a python "dict of dicts". We're then requested to retrieve a specific path from the tree, represented by a list of elements. The ...
Wololo's user avatar
  • 223
11 votes
1 answer
2k views

iterating over the values of a list of ordered dictionaries

I am facing the following problem: I have a special data structure that is a dictionary whose keys are integers (dimensions). The values are also dictionaries whose keys are strings (geometric types) ...
aaragon's user avatar
  • 295
10 votes
3 answers
3k 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: ...
Leo's user avatar
  • 201
10 votes
1 answer
13k views

An interval-map data structure

This data structure maps values from intervals of some type Key which satisfies LessThanComparable<Key> to values of some ...
Maikel's user avatar
  • 740
9 votes
5 answers
2k views

Bidirectional Dictionary

The management of bidirectional mappings is a reoccuring topic. I took the time to write an (hopefully) efficient implementation. ...
Benj's user avatar
  • 389
8 votes
1 answer
531 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 ...
Mast's user avatar
  • 13.1k
8 votes
3 answers
1k views

HackerRank "Ransom Note" challenge

I have solved the Ransom Note challenge on HackerRank using JavaScript / ECMAScript 6. The challenge goes like this: A kidnapper wrote a ransom note but is worried it will be traced back to him. He ...
Phrancis's user avatar
  • 20.4k
8 votes
3 answers
585 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, ...
pk72's user avatar
  • 113
7 votes
0 answers
466 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 ...
coderodde's user avatar
  • 27k
7 votes
0 answers
116 views

Agent-based Immutable Map

I am in the process of removing the last few pieces of mutable state from an F#-based distributed system. Some of the remaining mutable state is a ...
Aaron M. Eshbach's user avatar
7 votes
2 answers
3k 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/...
Alex's user avatar
  • 581
6 votes
2 answers
350 views

InfixDictionary: Data structure for Infix string lookup

I needed a data structure to quickly find all previously inserted values, that have the given string as key or substring (full text search). At first, I tried out some tree structures (infix trie/...
ASA's user avatar
  • 473
6 votes
2 answers
5k 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 ...
Kabachok's user avatar
  • 163
6 votes
2 answers
14k views

Pythonic way to flatten nested dictionarys

Here's my attempt to write a function that flattens a nested dictionary structure in Python 3.6 This came about because I had a nested dictionary structure of data I wanted to visualize in the ...
James Schinner's user avatar
6 votes
0 answers
1k views

Recursive conversion from ExpandoObject to Dictionary<string, object> #2

Because my original question was lacking many details, I have been advised to ask a new question. I will repeat the important parts of the original question and add examples etc to hopefully make it ...
Joelius's user avatar
  • 355
5 votes
1 answer
3k views

HackerEarth - SimpleFunction

Problem statement Let us first describe a SimpleFunction: ...
Jianmin Chen's user avatar
  • 2,396
5 votes
1 answer
244 views

Finding added keys, removed keys, and unchanged keys in ordereddict

I'm comparing two OrderedDict objects and I need to find added keys, removed keys, and keys that are present in both (the intersection). Sets are designed for ...
Conor Mancone's user avatar
5 votes
4 answers
5k views

Recursive conversion from ExpandoObject to Dictionary<string, object>

For my blazor library which is a modification of this awesome library I have to convert an ExpandoObject into a ...
Joelius's user avatar
  • 355
5 votes
2 answers
232 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 ...
Node.JS's user avatar
  • 389
5 votes
0 answers
369 views

Van Emde Boas tree -based map in Java [duplicate]

(Follow-up question: Improved Van Emde Boas tree based map in Java) For the experimental part of my MSc thesis I was working on van Emde Boas tree, and I have this: ...
coderodde's user avatar
  • 27k
5 votes
2 answers
6k views

Function that shortens a String based on a term/abbreviation mapping

I have a function that takes a description as a String and returns a shortened version of the description. The shortening is done by checking if a word matches the ...
isADon's user avatar
  • 195
5 votes
2 answers
3k views

sorting a map by converting it to vector

I have a map that I want to print out sorted by value, I convert it to vector and sort the vector. Is this code correct? ...
Ring Zero.'s user avatar
5 votes
3 answers
11k views

Search in a big dictionary Python

I have a big Python dictionary with more then 150,000 keys every key has list value. This dictionary contains infinitive words as key and all grammatical forms of these words as values: ...
Yan's user avatar
  • 235
5 votes
1 answer
316 views

Tracking the number of string elements using std::unordered_map

I'm looking for the most simple and efficient way to track the number of string elements in a container. Previously, I used std::vector but I tried changing the ...
Zack Lee's user avatar
  • 322
5 votes
2 answers
4k views

Refactor deeply nested if-else

I found a code on my computer that i wrote a while ago. It is based on an exercise from O'Reilly book Programming the Semantic Web. There is a class, that stores RDF triples, that is data in the form ...
Mirzhan Irkegulov's user avatar
4 votes
3 answers
501 views

Generic implementation of a hashtable with double-linked list

I implemented a hashtable that handles collisions by chaining entries using a double linked list. The idea is that it can store/lookup any kind of generic data structure, while maintaining an API that ...
766F6964's user avatar
  • 901
4 votes
2 answers
1k views

A 'flexible' VBA approach to lookups using arrays, scripting dictionary and user input

In my previous post Optimise compare and match method using scripting.dictionary in VBA I wanted to address optimising the scripting.dictionary approach I was using and I feel I have achieved that (...
Iain Saunders's user avatar
4 votes
3 answers
307 views

A program to display, update and save a dictionary as .csv

I'm now looking for feedback on v2.0 of this program instead. I'd like some feedback about my code. What bad habits do I have? What advice could help me write more Pythonic? I'm trying to write a ...
12345678910111213's user avatar
4 votes
2 answers
308 views

Data Persistence

I was wondering if I could get some feedback on the library I created to persist data online. JitterPushDemo.java ...
Malik Brahimi's user avatar
4 votes
1 answer
1k views

Morse code string - follow-up 2

This is my second follow-up. Major changes made: Use a Map instead of an enum for the Morse characters Added ...
TheCoffeeCup's user avatar
  • 9,454
4 votes
3 answers
11k 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 ...
Aaron's user avatar
  • 935
4 votes
2 answers
5k views

DataTable runtime grouping on user defined criteria

I one of my tools I use the user can define grouping for a DataTable. The criteria are known only at run-time. To achieve this I use a ...
t3chb0t's user avatar
  • 44.2k
4 votes
1 answer
1k views

Transliterate between Cyrillic and Latin scripts

I want to get a code review on the following transliteration code. I wrote it because there were some libraries that I have tried and they were specifically failing with the name "Yuliya" ...
nop's user avatar
  • 719
4 votes
2 answers
2k views

Website Spell Checker in Java

I've implemented a program that spell checks a website. Here is the idea that I have in mind: Scan all of the words in a web page into a string (using jsoup) Filter out all of the HTML markup and ...
ary's user avatar
  • 55
3 votes
1 answer
3k views

Python lazy dictionary

Here is a lazy dictionary with test cases. ...
Justin Fay's user avatar