Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [hash-map]

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

7
votes
1answer
510 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
71 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
94 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
176 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
568 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
75 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
41 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
64 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
57 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 ...
1
vote
1answer
28 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
70 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
49 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
59 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
135 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 ...
2
votes
1answer
97 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
144 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
68 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
80 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
63 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
603 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 ...
1
vote
0answers
135 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
422 views

Custom LinkedHashMap Implementation

I implemented my own LinkedHashMap in java. ...
4
votes
2answers
727 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
67 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
837 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
140 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
3k 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 ...
0
votes
0answers
51 views

Linear Probing / Perfect Hashing hybrid approach implementation

The domain: As a part of my university course we've implemented a tiny in-memory database engine. In order to perform a equi-join (join which is based on equal operation ...
0
votes
1answer
340 views

It is a hashmap, using linear probing on an array

I have been studying hashtable for two days and was musterring up the courage to write a code. Finally I have written code in which I have taken many shortcuts: The first being I have used ...
1
vote
1answer
640 views

Find the most frequent number in an array

I implemented a solution for: Finding the most frequent number from an array. How are my variable names? Or how could I improve this? ...
1
vote
2answers
98 views

Finding duplicates in arrays

I'm given two sorted arrays, arr1 and arr2. They can either be of the same length or arr2 ...
1
vote
2answers
69 views

Given a list containing dates and the amount spent on each date, display the total amount spent per month

I had an interview yesterday where I was asked to write a function that would take in a list containing a date and the amount of money spent on that date, and to output the total amount spent per ...
2
votes
3answers
146 views

Find the first reoccuring char from a String

Can anyone give me advice on how I can improve my answer? I have tested it out using "ABCA", "BCABA" and "ABC". Two things I would like help on. 1.How can I move this code into a method where it ...
7
votes
4answers
6k views

HashMap implementation in Python

Here's my implementation of a bare-bones HashMap in Python. Expected behavior, it returns None if a key is missing, When a key is inserted the second time it just overwrites the first value. ...
1
vote
1answer
304 views

Put ages within a supplied range into a HashMap

I'm looking for general considerations to make for the next time I'm writing code. I'm wondering if in this case it's better to have another auxiliary storage (another map?) in this case (and how to ...
4
votes
1answer
157 views

Simple form validation module

Thinking about form validation, I just wanted something simple that works and is extensible. I came up with the following code, which expects a list of selectors that maps to one or more functions ...
1
vote
0answers
244 views

constexpr hashtable string to user type

This creates something like constexpr mar<String, T> using C++14. Collision resolution is with static_assert and manually ...
2
votes
3answers
587 views

HashMap implementation in Java

I have implemented a hash map in Java, using generics. Let me know if I can improve it. ...
3
votes
1answer
841 views

Thread safe tbb::concurrent_hash_map and std::set

I have a basic websocket server implemented in C++. I'm using Intel TBB's concurrent hash_map to store all the users, uniquely identified by the id. The concurrent ...
2
votes
2answers
388 views

Parse a formatted string, which may have duplicate keys, into a map

I have a String which is coming in particular format so I want to parse that string into map. I have a below method which parses String to a Map and it works fine. ...
3
votes
1answer
182 views

Counting subsets with sum not exceeding some limit

I am facing a variation of a subset sum problem. I have to count the number of subsets with sum less than or equal to some integer(limit). I think the optimal solution for this problem would be the ...
3
votes
1answer
176 views

HashMap in Javascript

I began working on a Javascript project, and the first fundamental building block is a data structure that mimics Java's java.util.HashMap, since Javascript ...
5
votes
2answers
142 views

Develop custom Hash Map

I've got a task to implement custom hash map with only get, put, size functions without remove and implementing base Map interface in Java. I've made one but not sure if it is good one. Can You check ...
2
votes
1answer
569 views

Java Concurrent Multimap

I've implemented a concurrent multimap that support concurrent put and remove but I'm unsure of its correctness. I would appreciate your feedback. ...
3
votes
3answers
3k views

Specializing std::hash for std::array

I want to have an std::unordered_map which uses arrays as keys. As long as a type has an operator== and an ...
2
votes
1answer
812 views

HashMap Implementation

Purpose I've never implemented a HashMap and thought it would be a good data structure exercise. I tried looking at the Java source code as little as possible. ...
2
votes
1answer
90 views
3
votes
1answer
5k views

Generate JSON for Map<String, Map<String, List<String>>>

Consider I have a String: ...
2
votes
2answers
1k views

Splitting Hashmap by converting to TreeMap

I have a project requirement where I have to split a HashMap of around 60-70 entries into multiple HashMaps. The critical number of the split is 30 due to ...