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
4
votes
3answers
92 views

Updating a huge hashmap from a resultset

I am using Java 7 Problem: I need to retrieve records from a database table based on a condition, orig_setting = 1. This query could return ~1000 records. Parameters from 1-7 of the Params object are ...
-2
votes
0answers
36 views

Iterating through map keys in C++ 17 [migrated]

I am looking for a way to iterate through the keys of a map in C++ 17. The way that I have in mind right now is based on the answer of this question, the way is presented below. ...
6
votes
2answers
98 views

Create a 2 way mapping to allow you to stringify enums or map one enum to another

I've created a class that creates key->value pairs but also value->key pairs - i.e. a reversible hash-map. This is because I want to be able to switch between corresponding members of 2 enums with ...
1
vote
2answers
50 views

Removing duplicate hashes in an array while keeping count of the times the hash was present

I have an array of hashes (price_params['items']) where each item has a key called quantity what I'm trying to do is to clean ...
2
votes
2answers
165 views

HashMap in Python

This is a HashMap implementation written in Python. All the methods are based on the java implementation of a HashMap. Any and ...
1
vote
0answers
45 views

HashSet without collision

I have written a custom HashSet and though it isn't completed yet (this code does not consider test cases with collisions), I would like to know if there is anything I can improve in areas of clean ...
1
vote
0answers
35 views

Checking for a values existence: slice iteration vs map lookups in Go [closed]

Assuming I have the following slice: mySlice := []string{"one", "two", "three"} and I want to know whether or not it contains a given string, say ...
4
votes
3answers
137 views

Bidirectional Map in C#

Inspired by this question and its answers, I've made my own version. ...
1
vote
0answers
49 views

Custom HashMap implementation in Java with Linear Probing

I have taken a stab at implementing a HashMap in Java. To deal with collisions I implemented sort of a LinkedList using a dataNode. I am not very confident of my implementation hence looking for some ...
4
votes
1answer
157 views

A Basic HashMap (Python)

A hashmap is a data structure that implements an associative array abstract data type using keys and values and has a hash function to compute an index into an array, from which the desired value can ...
1
vote
0answers
78 views

Building maps for Dgraph integration tests in Java 8

I want to refactor this in Java to reduce my code duplication. ...
1
vote
0answers
86 views

Rust book ch 13 Closures + HashMap exercise

So the exercise is as follows: Try modifying Cacher to hold a hash map rather than a single value. The keys of the hash map will be the arg values that are passed in, and the values of the ...
0
votes
1answer
70 views

Linked HashMap in C

I was looking for comments (on performance and general implementation) on the following Linked HashMap implementation in C: ...
2
votes
1answer
91 views

Moving an element from one unordered_map to another

This code moves one element from one unordered_map to another. I would like to ask if my code below can be improved. ...
3
votes
1answer
69 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 ...
2
votes
0answers
69 views

Coding Challenge Solution - Find Number of Elements in a range in \$O(1)\$ with preprocessing

Overview This is my solution to the following Coding Challenge - Find Num of Elements in a Range in \$O(1)\$ with Preprocessing - Given an array and max element in the array, find the number of ...
0
votes
2answers
116 views

Creating a Java text-based game map [closed]

i got a college project and i'm trying to create a map for my text-based game in Java. Me and my colleague* created this code: ...
4
votes
2answers
725 views

How to set an interval to std::map [closed]

This code belongs to a contest. I tried to apply the range of data to a std::map. The contest system however warns me that the implementation of the assign function ...
3
votes
1answer
119 views

Hash table in Python

...
0
votes
1answer
96 views

java.util.Set extension/implementation

Lately, I was working on some experimental java.util.Set extension, IdSet: ...
2
votes
0answers
35 views

Convert flat object hierarchy to json

I do work for a project currently, where the data is send to the server as application/x-www-form-urlencoded (which is bad, and it should be JSON, but unfortunately I am not able to change this one). ...
0
votes
1answer
41 views

Generating probability table of 2-character combinations from text file in Java

I have written a probability table generator in Java to help me generate randomized girl's names for the game I am making. It reads from a text file and creates a ...
7
votes
1answer
2k views

Sort int array by frequency then value

Problem Take an array of ints as input and run a special sorting algorithm on it. This algorithm must first sort by int frequency, less frequent first, then sort by value. For example ...
0
votes
1answer
95 views

Implementation of a Hash Map in C++

I created a templated Hash Map class in C++, which supports most of the basic C++ types (e.g. int, float, ...
1
vote
2answers
381 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: ...
4
votes
2answers
855 views

Data Structures for Counting Duplicates and using std::vector::erase

Problem Dupe detection for a vector of ints. I simply want a count of the unique input characters that occurred at least twice. The goal is to count a dupe only once and ignore that input character ...
5
votes
2answers
1k 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? ...
1
vote
2answers
142 views

HashMap implementation, is this good enough for interviews?

After understanding HashMaps, I decided to implement my own using 3 classes HashMap, LinkedList, and Node. I knew how to implement LinkedList from before. Can you please give me feedback on this. ...
1
vote
1answer
44 views

Turn a list of words into a dictionary

I am looking for a way to turn a list of words that may have duplicates into a dictionary/map that counts the number of occurrences of words. After spending some time with the problem, this seems to ...
0
votes
1answer
98 views

HashMap Implemention in Java

I just finished implementing a HashMap in Java, with methods: add(String key, Integer value) get(String key) ...
-3
votes
1answer
60 views

Reducing function calls with Map [closed]

Currently I am working on reducing function calls in my tool. My function is called add_field_and_calc ...
2
votes
1answer
32 views

case…when or Hash#fetch [closed]

I have the following method, which can be written in the following two ways: which one would you prefer, and why? ...
0
votes
2answers
905 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
0answers
54 views

Using HashMaps to track parent and rank of graph nodes

I often find myself in the following position: I have created a class in some file, and would like to add a new data member to that class without changing the original class definition. Now, you ...
3
votes
2answers
74 views

Return Kth to Last: Implement an algorithm to find the kth to last element of a singly linked list

Implement an algorithm to find the kth to last element of a singly linked list. Any comments or feedback regarding this? I came up with another algorithm that uses ...
1
vote
1answer
752 views

Frequency Queries hackerrank [closed]

This is the problem: You are given queries. Each query is of the form two integers described below: - 1: Insert x in your data structure. - 2: Delete one occurrence of y from your data ...
3
votes
1answer
179 views

Buy and Sell a Stock for maximum profit (given a day and a price)

If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit. Example one: Input: [7,1,5,3,6,4] ...
4
votes
1answer
197 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 ...
-4
votes
1answer
72 views

Use key as object in map C++: Check if the less operator is implemented correcty [closed]

Hello I wrote the following code. It allows me to use objects as keys in a map. I have a constraint though: In addElement function both arguments must be pointers ...
5
votes
0answers
220 views

HashMap exercise, Rust book Ch.8

I'm learning Rust by learning the Rust programming language book. I'm now implementing the solution for the third challenge. Using a hash map and vectors, create a text interface to allow a user to ...
2
votes
2answers
66 views

Chinese mapping number routing

I want to design Chinese mapping number routing. How can I improve this code in the method mapRouting? I want to use reflect auto get method name by providing a ...
4
votes
1answer
2k views

Hackerrank Day 8: Dictionaries and Maps solution in C++

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 ...
2
votes
0answers
237 views

Ruby Hash to XML

I've just made this "serialization" module in Ruby that takes a hash and outputs a XML string. ...
0
votes
1answer
1k views

Custom LinkedHashMap Implementation

I implemented my own LinkedHashMap in java. ...
4
votes
2answers
2k views

Spell Checker program using dictionary implementation

This is a small program written for a small assignment to check spelling. The assignment asks for the following output: A list of words that are misspelled in the file A count of the ...
5
votes
1answer
96 views

Number base manipulation in Haskell

I am picking up good Haskell practices! In this instance, I wanted to pick a file which contains a title in the first line and then every line is a string. Each string represents a number in base ...
12
votes
3answers
2k views

Determine if one string is a permutation of the another

Can anyone give me some feedback if I'm using std::unordered_multimap optimally? I don't know the ins-and-outs of the ...
6
votes
1answer
2k views

Hash table with separate chaining implementation in C

I'm attempting to implement a hash table with separate chaining in C. It works fine, but is there something that I should optimize, fix or maybe add some features? ...
1
vote
0answers
218 views

java - A* search algorithm

I'm having trouble with my homework implementing A* search algorithm in java, I'm given the graph, origin and destination, I had to follow some specific tasks in the homework so the code might be a ...
1
vote
2answers
4k views

Custom HashMap Implementation in java

I implemented a CustomHashMap in Java, and would like to know if my approach is good or not. Below I am sharing the complete code of my ...