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
6 votes
3 answers
2k views

How best to differentiate boolean values in a long list?

I have a large C# Dictionary of string keys and boolean values. Background on the reason for it is this: my program builds up a bunch of the same objects from two different sources, and then compares ...
deed02392's user avatar
  • 296
11 votes
6 answers
18k views

"Multi-key" dictionary

I was making a relatively large-scale project in Python as a learning experiment, and in the process I found that it would be useful to have a map (or, in Python, I guess they're called dictionaries) ...
asteri's user avatar
  • 4,879
3 votes
1 answer
2k views

Prime number dictionary

I attempted to write a read-only dictionary, containing primes: ...
blueberryfields's user avatar
0 votes
1 answer
34k views

Proper way to compare two Dictionaries [closed]

I am implementing an IEqualityComparer for Dictionary objects and am looking for input on a couple of different approaches. I define equality in this case to be that both dictionaries contain the same ...
dkackman's user avatar
  • 161
1 vote
2 answers
141 views

Searching for words in a dictionary

I'm using an open source program called MElt which lemmatize (give the lemma example:giving-->give) of words. MElt works on Linux and it's programmed in Perl and Python. So far it's working good but ...
Med's user avatar
  • 11
5 votes
2 answers
2k views

Hash Table: adding and finding functions

I made this function to teach myself about hash tables. Any ideas? I commented out free(addition) because it was giving me a compiler error, but I need to figure ...
sammis's user avatar
  • 113
3 votes
2 answers
257 views

Nested array-to-dict transformation

I'm looking to let people define arbitrarily nested lists of lists and return a random json document for them. Right now the assumption is that if you have a structure like this: ...
Slater Victoroff's user avatar
2 votes
2 answers
469 views

Fast integer handling

Each data structure has its own time complexities. The biggest one that jumps out at you is the hash table. The average times for Insertion, Deletion and Searching are all O(1). But it's really ...
Kevin Melkowski's user avatar
1 vote
2 answers
4k views

Making a 2D dict readable

I am building a 2d dictionary with an altered list at the end Afterwords I want to find the min of each list. Is there a better way to do it? Better being faster or at least less of an eyesore. ...
EasilyBaffled's user avatar
1 vote
3 answers
900 views

Creating a dictionary with a path name and SHA-256 hash

The purpose is just to create a dictionary with a path name, along with the file's SHA-256 hash. I'm very new to Python, and have a feeling that there's a much better way to implement the following ...
user2407064's user avatar
6 votes
1 answer
317 views

Load drinks and their ingredients into dictionaries

I'm working on a web application using Bottle, and it is, at this point, functional. The gist of it is that I have a database of drinks, with associated IDs, and associated sets of ingredients. the ...
Tadgh's user avatar
  • 195
4 votes
1 answer
133 views

Object map in JavaScript

I want to make a map object that key is object. But, JavaScript only allows string as a hash key. (at least before ECMAScript6 comes?) So, I tried to write auxiliary functions to emulate, hash-ish (...
Tsuneo Yoshioka's user avatar
5 votes
2 answers
5k views

HashTable - separate chaining collision in C++

I'm trying to implement a HashTable. In fact, I want a HashSet with Persons that have a name and a phoneNumber, both string. I understood the theory with collisions and everything but I don't know how ...
user1849859's user avatar
16 votes
3 answers
73k views

Set a default if key not in a dictionary, *or* value is None [closed]

Let's say I have a key 'messages' that is usually a list, but might be None, or might not be present. So these are all valid inputs: ...
Kevin Burke'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
1 vote
1 answer
3k views

Sorted trie implementation in C

I wanted to store some dictionary data (key/value pairs of strings) in C, and decided to use a trie. I found what looks like a good implementation here, along with some nice notes. In this ...
Dagg's user avatar
  • 4,531
0 votes
1 answer
176 views

Dictionary Structure

I am brand new to dictionaries and coding and am hoping to get some suggestions on how I should structure my dictionary. I have a collector number which has meters connected to them. Each of the ...
user24194's user avatar
1 vote
3 answers
103 views

update list based on other values

Basically I have a 2d list containing movies. Movies are specified by name, version and description. For example ['Jaws', 1, 'Movie about sharks'] - where ...
user1741339's user avatar
1 vote
3 answers
17k views

Updating list of Dictionaries from other such list

Basically I have created a function which takes two lists of dicts, for example: oldList = [{'a':2}, {'v':2}] newList = [{'a':4},{'c':4},{'e':5}] My aim is to ...
user1741339's user avatar
11 votes
2 answers
26k views

Mapping enum to enum

I need to map from one enum type to another. Here is the enum I am given: ...
arcomber's user avatar
  • 2,449
11 votes
2 answers
24k 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 ...
raptortech97's user avatar
4 votes
1 answer
963 views

Insert tags around entities in body

Because we're passing object to Spring Framework in which Jackson classes convert them into JSON as a response, we chose to implement a simpler Tweet class rather ...
ochitos's user avatar
  • 193
7 votes
3 answers
15k 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 ...
Dave Jarvis's user avatar
  • 1,897
3 votes
1 answer
405 views

Applying a currency symbol based on a tested string value

My conditional code here seems repetitive and long. Is there a better approach? I want to test for a string value in a NSDictionary object and then depending upon ...
hanumanDev's user avatar
2 votes
1 answer
317 views

Iterating X times (where X > Y) over Y element dictionary

I need to write a procedure, that will take a dictionary consisting of server names and their available slots and a number of slots required, and redispatch it over the servers, so that every server ...
SpankMe's user avatar
  • 143
1 vote
2 answers
514 views

Readability concerns with literal dictionary lookup vs if-else

I'm having concerns about the readability of this piece of code: ...
fortran's user avatar
  • 137
2 votes
1 answer
451 views

Simplify complex hash-table manipulations in Common Lisp

I'm trying to write a simple triplestore in Common Lisp that will store triples in the form subject-predicate-object. The code is inspired by the book "Programming the Semantic Web". ...
Mirzhan Irkegulov's user avatar
6 votes
2 answers
4k views

Convert dictionary of lists of tuples to list of lists/tuples in python

I've got dictionary of lists of tuples. Each tuple has timestamp as first element and values in others. Timestamps could be different for other keys: ...
user avatar
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
1 answer
1k views

Custom dictionary for caching assistance

I'm writing a custom dictionary which is to be used as a helper for caching. The reason I use delegates is because it must interface with generated code, so I can't change this. However, you can ...
Earlz's user avatar
  • 227
2 votes
2 answers
155 views

Is there a better way of showing multiple NSDictionaries?

I have a method that contains a bunch of NSDictionaries (in fact, the only reason I have that method is to create those NSDictionaries). While I don't believe there are enough NSDictionaries ...
cory ginsberg's user avatar
5 votes
1 answer
5k views

Hash table using open-addressing with linear probing

I've written a hash-table implementation. This is the first time I've written such code. The hash-table uses open-addressing with linear probing. The hash function is still subject to change as I ...
FUZxxl's user avatar
  • 641
7 votes
3 answers
2k views

Creating and searching a dictionary of passwords and MD5 hashes

In this program, I have been asked to read an existing textfile (1324passlist) containing a list of passwords, then create a dictionary file with both the password and MD5 hash of the password on the ...
j_u_l_e_s's user avatar
9 votes
2 answers
8k views

Thread-safe LRU Dictionary in C#

Can't seem to find one, so trying to build a very simple but fast implementation. Thought I would post on SO for review/feedback, and so that others can just copy/paste for their own use. I'm using a ...
Jamona Mican's user avatar
9 votes
0 answers
257 views

Take two on type to instance map [closed]

I realised that what I was doing wasn't particularly smart, so I switched to a different approach. This costs more dynamic allocations but has a much simpler implementation: ...
Cactus Golov's user avatar
  • 3,229
3 votes
1 answer
3k views

Dictionary tree optimization

I was wondering if anyone could give me a little bit of help with optimizing a tree-structure in C++. I'm currently developing a dictionary program for a school project but want to take it a bit ...
icdae's user avatar
  • 151
3 votes
2 answers
2k views

Iterating thousands of times over large collections: advices

This is a pet project :) I have hundreds of playlist files .m3u whose many entries have a wrong path. I'd like to fix them programmatically. Suppose one of my .m3U contains the following entry: <...
roland's user avatar
  • 141
7 votes
3 answers
18k 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 ...
brainydexter's user avatar
2 votes
2 answers
3k views

Creating a dictionary of all prefixes of a string in Python

a=raw_input() prefix_dict = {} for j in xrange(1,len(a)+1): prefix = a[:j] prefix_dict[prefix] = len(prefix) print prefix_dict Is there any possibility of ...
sachin irukula's user avatar
10 votes
5 answers
2k views

Simple word counter

I've decided to do this by writing a simple word counter. The app gets all the params and outputs all the unique words, each one with a counter: "Hello world Hello" would return "Hello: 2", "world: ...
PirosB3's user avatar
  • 205
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
3 votes
1 answer
4k views

Open addressed hash table

I'm attempting to implement various data structures and algorithms to better learn C. I would appreciate comments on style, correctness of the implementation, memory management, etc. One specific ...
Jared S's user avatar
  • 95
28 votes
8 answers
59k views

LINQ approach to flatten Dictionary to string

I have a Dictionary<string,string> and want to flatten it out with this pattern: ...
Martin's user avatar
  • 383
5 votes
2 answers
1k views

Transforming a Python dictionary into CSS

Recently I had the idea to write a module for the transformation of the dictionary into valid CSS code. And I would like to hear your comments on my code. License MIT, BSD etc. The code is very ...
Alexander Abashkin's user avatar
2 votes
2 answers
2k views

File to map class

This code will be used to map a set of unique keys to a container of objects that are unique to that key. I would like to be able to reuse this code in future projects hence the template, and not hard ...
Matthew Hoggan's user avatar
8 votes
7 answers
7k views

Any way of simplifying the following two short snippets regarding Dictionary?

Example 1 if (myList.ContainsKey(myKey)) { myList[myKey]++; } else { myList.Add(myKey,1); } Example 2 ...
colinfang's user avatar
  • 521
7 votes
5 answers
1k views

Holding records using dictionary

Can you please help me with the following script? At the moment the script is taking up to 20 mins to execute, depending on the amount of data being processed (each time the script is executed, it ...
Junior's user avatar
  • 71
5 votes
1 answer
4k views

Return Dictionary object having key/value pair of keywords and URLs

Can you please help me split this method to reuse the repeating code? Any advice/comments on the code are welcome. ...
Kashif's user avatar
  • 399
6 votes
1 answer
204 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] ...
Brian Reichle's user avatar
7 votes
1 answer
1k views

Map implementation in F#

Just as a refresher I put together a simple Map implementation and I would love to get some feedback on it. ...
ChaosPandion's user avatar
  • 1,753