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
7
votes
2answers
928 views

The cleanest way to print the max value and its key from a dictionary

I'm getting the highest value and its respective from a dictionary and printing it out for the user. Even though it's working, I'm wondering if I'm doing it in the cleanest way. Here it is: ...
1
vote
1answer
50 views

Sports DataSheet

This program asks the user for a players name, # of goals, saves, games played, etc. This information is ten organized on a .txt file along with the time the information was logged. users can also ...
1
vote
1answer
39 views

I have a query like this that seems complicated and I want to do it by using Java Stream Api

I have method that fetches sorted and filtered data from Mysql Database, Firstly I had done It by using Java. Now I did it by Mysql but I don't like the way the code looks I have entity that named ...
2
votes
1answer
40 views

Implementing hash table in Python using Tuples

I am trying to implement a basic hash table using a list of tuples. The code produce the desired output. Please help me improve my code as I feel there are a lot of while loops. ...
5
votes
2answers
767 views

Hashmap implementation in C++

I have been asked to implement a HASHMAP in C++ in a job interview (home assignment). I'm a bit unsure about exception safety, but this is what I came up with: Block.h ...
0
votes
0answers
44 views

Quadratic Probing Hash Map - questions about implementation and testing

Quadratic Probing Hash Map Looking to improve my quadratic probing hash map. Here are some design considerations and questions. Implementation is made such that the hashing function, probing function ...
2
votes
1answer
185 views

3Sum - leetcode

Question: Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set ...
0
votes
0answers
55 views

Is this a good way to construct the class for a C++ template partial specialisation of a member function?

I am teaching myself c++ by doing a series of exercises. I liked the idea of working out how hash tables could be done using just the language and no std calls. I discovered that you cant do "...
6
votes
2answers
1k views

Income tax rate calculator in c++

I have been trying to learn c++ for the sake of being comfortable with a second language. I found a project that seemed relatively easy, although it may not be implemented perfectly, it was a simple ...
2
votes
1answer
38 views

Hash Table implementation in C using linear probing for collisions

I've written a simple Hash Table implementation in C, in order to use it in an IRC bot, so mostly storing nicknames, channel names, etc (small strings). I'm using linear probind to resolve collision. ...
3
votes
2answers
66 views

Create a dictionary from a list of key and multi list of values in Python

I have a list of key: list_date = ["MON", "TUE", "WED", "THU","FRI"] I have many lists of values that created by ...
3
votes
1answer
67 views

Aggregating hourly location data into daily sublocation data for many columns

I start with an hourly table that has around 40 of items (example: bread, barley, bagels, beef, chicken). The purpose of my code is to aggregate this hourly table's numbers to daily numbers but broken ...
5
votes
2answers
376 views

Hash table implemented in C with open addressing

While posting this, I noticed there are quite a few similar C hash table implementations here already. So I figured one more wouldn't hurt. :-) In any case, I'm writing a teaching article on "how ...
2
votes
1answer
40 views

Linked list that support modifications during iteration

Update: Fixed last item is not removed during iteration Fixed clear() during iteration does nothing Fixed addition of removed item is ignored The lasted code can ...
3
votes
1answer
74 views

lazy_map implementation in C++ | Similar to unordered_map but O(1) copyable

I implemented lazy_map - https://github.com/tinytrashbin/lazy_map. Can someone help with reviews ? lazy_map is an implementation of unordered_map that has O(1) cost of copying irrespective of the ...
13
votes
3answers
2k views

Count word frequencies, and print them most-frequent first

I'm writing a comparison of a simple word-counting program in various languages. The task is to count the frequencies of unique, space-separated words in the input, and output the results most ...
1
vote
0answers
34 views

Global Dictionary Class

For a Django-Server I use several custom Error-Codes, error-titles and descriptions, possibly other fields might follow. I'm using right now a basic global dictionary. ...
0
votes
1answer
25 views

Calculating ordered differences between elements in vector

Input I start with a vector of integers or floats, e.g.: [10, 100, 20, 5, 50] Output I want to return a list of differences or "deltas" between elements ...
2
votes
0answers
57 views

Hash table library implementation

I wrote my own implementation of generic hash table. I’m using linked list to resolve collision problem. I want to share my code with you and get your opinion about it, and if there are any advice or ...
3
votes
1answer
139 views

Hashtable with separate chaining and dynamic resizing

An attempt at a clean implementation of this important data structure in C. It's hard to make such structures generic in C without losing performance, so this specialises on ...
4
votes
1answer
91 views

Data set with many variables in Python, many indented dictionaries?

I am working with a data set that has many variables. Currently I am storing the data in many indented dictionaries in the following way: ...
1
vote
2answers
79 views

Finding duplicates in multiple lists for configuration validation

I have created helper class for configuration validation, the main purpose is to find any human "errors" in the configuration for the app. the case is that any type of "message" ...
1
vote
1answer
85 views

Generic hashmap with dynamic resizing and collision handling

This is a (more or less) continuation of a previous post I made: Generic implementation of a hashtable with double-linked list. I got lots of valuable feedback, so I decided to rewrite the entire ...
1
vote
2answers
296 views

How to make Map<String, Object> expendible(?) safely in java

I am building some statistic counter in Java. Each metric could have flexible depth so the implementation should able to explore the depth when value insert or update. So I implement like below (with ...
3
votes
2answers
856 views

Simple Hashmap in C

I've been working on a simple hashmap in C. Here is hashmap.h: ...
4
votes
3answers
180 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 ...
0
votes
1answer
64 views

Nested dictionary creation with setdefault

Is there a better way of creating a nested dictionary than what I'm doing below? The result for the setdefault is because I don't know whether that particular key ...
3
votes
0answers
70 views

Modeling data from Excel sheets to parse to Excel sheet

Background: I have close to 50 excel files - I cannot change the data source - and I steadily get more. My task is to make sense of all that data and, lo an behold, save that as another excel file (I ...
2
votes
1answer
66 views

Print the App Name Using Latest Version

I am trying to solve a problem, where we are given an app name, service name, and version number of an api. We need to print the name of app, which is using the latest version for most of the service. ...
2
votes
0answers
43 views

Hashtable Visualizer in TypeScript

Implementation is based on the MVC design pattern, with callbacks to allow model and view to communicate with controller. Concerns: It's not ideal to have async code inside the model, i.e the model ...
1
vote
1answer
49 views

group list of dictionary [closed]

I have a list of dictionaries and I want to group them by a specific value let's say this is the list: ...
5
votes
1answer
75 views

Basic Markov Chain Algorithm

So I have a file(story.dat) with a randomly generated story like: "Sleeping in his car was never the plan but sometimes things don't work out as planned. This..." It will print out each word ...
4
votes
1answer
126 views

Increment value in a list of dictionaries

I have a list of dictionary let's say : l=[{'a':1,'b':2},{'a':5,'b':6},{'a':3,'b':2}] and I want to have another list l2 and add 4 to the 'a' in the all ...
5
votes
1answer
132 views

Find the shortest sub array that contains all element from 1 to K

I'm trying to solve this problem here. The question is all about finding the shortest sub array inside an array that contains all the element from 1 to K. Input: The first line contains three space-...
3
votes
1answer
67 views

Function for accessing and searching dictionaries using /slashed/paths (like xpath)

So I have some data being returned to me in the form of a deeply nested Dict and I need to parse multiple values from it which may or may not be there. I saw this library (https://github.com/...
2
votes
0answers
35 views

Converts Pandas and Numpy into Dictionary and Converts back to original format for data split

I'm trying to refactor some code so that it does not have so much repetition to it. What I'm trying to do is create an input for a multiple channel/input neural network. The features that are being ...
7
votes
2answers
595 views

Number of occurrences of strings in array

This is a Hackerrank problem (https://www.hackerrank.com/challenges/sparse-arrays/problem). We're given an array of strings and an array of queries, and have to return an array of the number of ...
3
votes
2answers
43 views

Handle missing children nodes when parsing XML into a dictionary

I work on a code-base that uses xml to set up problems and specify model parameters. I've created a script that I run in tandem with our code. This script will ...
10
votes
2answers
2k views

first pizza order program

Trying to learn a new skill at 40 without any prior related experience :-) Bought the book 'Python crash course 2e' and decided to freewheel a bit with after a week with what I've learned so far.. I ...
4
votes
2answers
234 views

JavaScript implementation of Symbol Table (Dictionary)

I'm currently going over Robert Sedgewick Algorithms book. Here I'm implementing a Symbol Table using a Linked List. The Sequential Search Symbol table is implemented in JavaScript. The book mentiones ...
2
votes
2answers
147 views

Finding unique keys

I made the following snippet. It finds unique keys based on their values. For all keys \$s\$ that are contained in another key \$D\$ with the same value, key \$s\$ is discarded and key \$D\$ is ...
4
votes
1answer
49 views

Add lines from files to corresponding dictionaries

I have to iterate through multiple text files. For each file I read its contents and append each line to its corresponding dictionary to then build a JSON file. Each text file has the following ...
5
votes
1answer
121 views

python3 function to merge dictionaries

I have a bunch of JSON records, each record with a varying degree of completeness. In other words, record A may contain keys not in record B, and vice-versa. To get a better understanding of the data ...
5
votes
1answer
182 views

Recursively merge n-level maps of values and lists

I was looking for a solution for a way to easily merge maps of serialized Yaml and came up with this. Reference to a similar question (not asked by me): https://stackoverflow.com/questions/25773567/...
5
votes
1answer
57 views

Dynamic-sized Hash table with Linked List

Below is an implementation heavily based on climberig's implementation on Leetcode for LeetCode 706. Design HashMap. Just to preface, I am doing this in preparation for an exam. The one below is ...
3
votes
0answers
83 views

Linear probing 16 hashmap elements in parallel using SIMD instrinsics

For my hashmap implementation, I'm caching hashes for each map element in an array of length NBUCKETS, where each element corresponds to an element in the hashmap. ...
5
votes
1answer
205 views

Dictionary implementation in Rust

This is an implementation of a dictionary (hash map) in Rust. It is loosely based on Python's dictionary implementation, using the same "random" probing and capacity/size management. Does it ...
5
votes
2answers
241 views

Can it be shorter?: DNA Sequence Analyzer from CS50 written in Python

This is my first time requesting a code review. This is code I wrote in Python to create a DNA sequence analyzer. This is for the Harvard CS50 course. I was really hoping to get some constructive ...
2
votes
1answer
46 views

Optimize insertion from ArrayList to HashMap

I'm trying to insert data from ArrayList to HashMap<String, Language> optimally. Many items may have the same languge_name (code below), so I need to group items having the same language in ...
2
votes
0answers
45 views

Linkedlist & hashmap _duplicates removal

I have implemented a LinkedList removal fo duplicates class by using HashMap. Looking forward to your reviews. Thanks. ...

1
2 3 4 5
17