Skip to main content

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
-2 votes
1 answer
54 views

Multiple key swap algorithm [closed]

I have a dictionary with key - data pairs. My data comes from excel sheets. When I create the dictionary my objects are placed in order by their keys ex. 1 -> data of sheet1, 2 -> data of sheet2 ...
4 votes
0 answers
89 views

A new Dictionary for VBA

The latest version of the Dictionary class presented in this question is available in the VBA-FastDictionary repository under the latest release. Motivation I ...
5 votes
1 answer
389 views

Optimizing Perfect Hash Table Implementation in C for Improved Performance

I wrote code that implements perfect hash table, according to its description in the book "Introduction to Algorithms by Thomas H Cormen", but the code does not pass time tests in contest. I ...
4 votes
3 answers
254 views

Given two sparse vectors, compute their dot product

Problem Statement: Given two sparse vectors, compute their dot product. Implement class SparseVector: SparseVector(nums) Initializes the object with the vector nums dotProduct(vec) Compute the dot ...
6 votes
3 answers
698 views

Program that brute forces to find the minimum dominating set

This program solves the minimum dominating set but it takes an insanely long time to run. In case you do not know, in graph theory, a dominating set for a graph G is a subset D of its vertices, such ...
4 votes
2 answers
427 views

Map constructor utility class in Java 8

In a Java 8 project, I'm using several maps, many of which contain static or default content. In Java 9 and newer, there's the convenient Map.of() method and I want ...
1 vote
1 answer
102 views

An immutable class that contains Dictionary properties and needs a distinct hash code based on those Dictionaries

I have a Job class that represents jobs in a manufacturing system. The idea is that a job requires some quantity of certain materials, and it outputs some quantity ...
1 vote
2 answers
92 views

Saving multiple files in python

I have this stupid code block below to save multiple files in Python. It is kind of repetitive (but it works). I was wondering how to improve it, notably: Is it worth it to write a function for two ...
7 votes
1 answer
3k views

Implementing a dictionary and thesaurus in Python

Write code that functions as both a dictionary and a thesaurus. Supported operations: Add a word and its definition to the dictionary Add a synonym to a word in the dictionary Look up ...
36 votes
1 answer
1k 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
1 answer
108 views

Simple hash table written in C with REPL

This is a simple hash table I've written in C. It is a closed-addressing hash table with TABLE_SIZE number of buckets. The hash ...
2 votes
2 answers
77 views

Dictionary additional function implementations

I've written a utility class BetterDict to help me on some of my other projects. I've implemented the &, ...
5 votes
2 answers
770 views

Fast unpack of SAM flag bitfield to named symbols

...
1 vote
1 answer
101 views

Implemented a basic dictionary in python using lists as linked list and murmur hash as a hash function

...
5 votes
2 answers
259 views

C# console app that computes the Jaccard Index

So I wrote a basic C# console application that computes the Jaccard Index. This has its applications in cybersecurity and machine learning. Given two sets X and Y, the basic formula is: $$ J(X, Y) = \...
2 votes
3 answers
333 views

A hierarchical dictionary for dotnet

Is there an existing class in .Net for representing and querying hierarchical data; i.e. providing methods which allow you to test whether one item is an ancestor or descendant of another, or to ...
5 votes
1 answer
161 views

Set implementation

I believe reinventing the wheel is in fact a good learning exercise. How can I improve my Set implementation without just copying ...
3 votes
2 answers
135 views

Covid Data Base Hash Map in C++

This is a follow up question to Date Checking in C++ I have these two function prototypes: void CovidDB::add_covid_data(std::string const COVID_FILE) ...
5 votes
2 answers
4k views

Bidirectional map based on memory manipulation

This is a bidirectional map implementation that stores the values as pairs on the heap, and uses pointer arithmetic for efficient lookup. codepad link, may be easier to read ...
0 votes
2 answers
61 views

Checking which programs are used for scripting

I have a directory where there are some script files, some binary files, and some subdirectories. I have tried to write a program which gets names of all files in directory, and excludes if they are ...
5 votes
2 answers
2k views

SHA-256 Hash with a short string length in javascript

I think I've found a way to somewhat "compress" the length of a SHA-256 hash. I am doing some addition, so I wanted to know whether an approach like this is secure or not. ...
4 votes
1 answer
133 views

Find the longest palindromic subsequence - Using a hashmap in Rust

This is a leetcode question which I wanted to solve using Rust as I'm learning Rust at the moment. I would appreciate some feedback on how to write it idiomatically. Link to the question: https://...
7 votes
2 answers
37k 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
2 answers
1k views

Implementing hash table

I am implementing a program to interact with hash table, the data to be hashed is just number. It works but I want to know if there is any error like: memory leak,... in my code and how to improve my ...
4 votes
3 answers
172 views

quadratic probing hashmap and its time efficiency

I am writing small a hashmap library (not full featured yet) but I have some questions about the algorithm I wrote, the formula I hope I got right from wikipedia and general things. Measured ~14.3 ...
2 votes
1 answer
46 views

Remove inputted keys separated by spaces from map and output the resulting map, including alias recognition

I'm looking to integrate Kotlin idioms (including code style) and maybe better performance. I wonder if there's a better way to do line 17 (the str.split(' ') one). ...
19 votes
5 answers
64k views

Get value from dictionary given a list of nested keys

I would like to get a deeply-nested value, for example {"a":{"b":{"c":"myValue"}} by providing the keys to traverse. I tried chaining together .get() but that didn'...
4 votes
1 answer
183 views

Langton's Ant cellular automaton in Java

I made a couple of little games and cellular automata in Java. For every new 'game', I used the same code as a base, except for the game logic of course. With every iteration of me customizing my ...
5 votes
1 answer
908 views

Merge multiple map with java stream api

I am trying to merge multiple map with Java stream API. The reqiurements like ... this method can receive multiple map, does not care hot many of it support 2 merge method: intersection, union if key ...
4 votes
2 answers
142 views

Sort a dict by keys, assuming keys are orderable

I found a suspicious code snipped in an existing project in which I am involved as a developer. The code sorts a dict by its keys, so that if iterated over the dict,...
7 votes
4 answers
1k views

Calculate average values for each day of the week for each Meter

I have a program with these two methods. One method to import a set of data from a CSV within the given time period and store them in a dictionary. Here the data in CSV file is stored in following ...
4 votes
1 answer
3k views

Merge two dictionaries

This function merges two dictionaries, using the value from the later dictionary to resolve conflicts. I have 5 tests that the program passes successfully: ...
3 votes
3 answers
601 views

VBA Very Slow Performance using objects with scripting dictionary

I have a simple code that loops through a text file to fix a few things in it and I use mostly dictionaries to find and handle the adjustment. However, with larger files (about 30K lines) it seems to ...
3 votes
1 answer
280 views

C void* Generic Hash Table

Some time ago I tried to make a generic linked list in pure C (no external libraries, only the C standard library) using void*s here. Building on top of that and ...
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" ...
0 votes
2 answers
112 views

Create all words that correspond to a telephone digit sequence

I wrote a terrible function to map E.161 keys to letter strings. I think the logic could be simplified using a recursive function; however I have never been good at recursive methods. Any suggestions ...
3 votes
2 answers
2k views

Implementation of Hash Function in C language

I'm new to programming. and I'm learning a C language. Currently working on Harvard's CS50 problem set (this one: https://cs50.harvard.edu/x/2022/psets/5/speller/). In that problem, they want us to ...
4 votes
3 answers
2k views

Switch case on an enum to return a specific mapped object from IMapper

I have an ever growing switch case statement I plan on adding 3 more case statements to. Given an int, compare it to an enum, and call ...
5 votes
2 answers
2k views

Dictionary as context manager

I've created a class that implements customized addition, subtraction, etc. But for this class I'd like to have some additional parameters for these methods (__add__...
0 votes
1 answer
47 views

Count occurrence of elements in map during creation

This code works, but it's so ugly, so I was hesitant to put it on display. There must be a nicer/easier way to achieve this. The main issue is to count each unique occurrence during runtime when the ...
6 votes
1 answer
201 views

Creating a Dictionary<string,string> to generate the most frequent continuations (without Linq)

Main is added to compare the expected result with the result of the function, the war field is GetMostFrequentNextWords. What ...
2 votes
1 answer
123 views

Write a function that takes a list of dicts and combine them

There is an exercise in the book Python Workout: 50 Ten-minute Exercises that asks to write a function to do the following: Write a function that takes a list of dicts and returns a single dict that ...
2 votes
1 answer
206 views

Finger Exercise: Update book cipher by creating new book

I'm working my way through the finger exercises in John Guttag's book Introduction to Python Programming, third edition. The following finger exercise on page 143 describes encryption/decryption with ...
3 votes
1 answer
52 views

Optimizing code for this function that filters a JSON file

I made a function that turns all child from a JSON file to parents (or brothers?). It adds the parent name to the key, so there are no duplicates. It works ok, but I would like to ask if there are ...
1 vote
2 answers
172 views

Parse list of UserPrincipal objects into custom class

I'm wondering how I could optimize this method that takes in a list of UserPrincipal objects, filters them by Regex and inserts the new class instance into a list. It takes 4 to 5 seconds for an input ...
3 votes
1 answer
117 views

Multiway map in C++

I recently had the problem that I wanted a hashmap where there would be a variable amount of distinct classes which each could be used to look up each other. I couldn't find any implementation online ...
1 vote
3 answers
163 views

Caesar cipher - Encode text from external file using HashMap Java

This is one of my school assignments and I just wanted to ask if there are some obvious mistakes or things I could maybe improve in this code. Thank you for any suggestions. ...
6 votes
3 answers
12k views

Simple cache dictionary

I decided to write a simple dictionary to use as a cache: ...
10 votes
2 answers
8k views

Efficient renaming of dict keys from another dict's values - Python

I have a dictionary in Python (uglyDict) that has some really un-cool key names. I would like to rename them based on values from another dictionary (...
1 vote
2 answers
154 views

Implementation of Hashtable in C99

I tried implementing a general purpose hashtable in C99. The basic structure is I have a huge array of hashtable entries and each entry is the entry point to a doubly linked list so that in case there ...

1
2 3 4 5
19