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
3 votes
1 answer
152 views

Return whether the cards can be rearranged

I solved this question on LeetCode.com: Alice has a hand of cards, given as an array of integers. Now she wants to rearrange the cards into groups so that each group is size W, and consists of W ...
J. Doe's user avatar
  • 133
1 vote
0 answers
2k views

What is the best implementation of a ignore case dictionary In C#

Imagine we have a custom dictionary class which is derived from Dictionary<string, object>. Dictionary is case-insensitive about keys and elements arrange is ...
M.H.Ahmadi's user avatar
5 votes
2 answers
227 views

C Hash table implementation

I have written a pretty simple hash table in C. It uses a prime modulus, linear probing, open addressing, and robin hood hashing. The program can also be found on GitHub. For clarification, ...
Lev Knoblock's user avatar
4 votes
2 answers
2k views

Replacing all keys found in a dictionary for its value in a list

I have a file that is written DOS format and I need to replace some characters into others. I created a dictionary for that purposes, and now I have to read everyline from my stream and replace my ...
RegularNormalDayGuy's user avatar
1 vote
1 answer
75 views

Unscramble words faster in Python

So I'm currently using python to unscramble words that are retrieved from an OCR program, and checked in the 'dictionary'. The current code I am using to unscramble words is this: ...
Adam's user avatar
  • 11
-2 votes
1 answer
78 views

Sorting through two dictionaries [closed]

What my code try to do here is to sort items trough 2 dictionaries. If they are similar or the same, I create a new list to append them. The test file is relatively big, around 2000 data each ...
Bobby's user avatar
  • 1
3 votes
1 answer
127 views

Open-addressed C hashmap

I implemented an open-addressed, double-hashed hashmap in C, now looking for some advice on improving it. Thank you. hashmap.h: ...
G.K.'s user avatar
  • 33
3 votes
1 answer
345 views

Implement hash table using linear congruential probing in python

I have just read the Chapter 5 of Data Structures and Algorithms with Python. The authors implemented hash sets using linear probing. However, linear probing may result in lots of clustering. So I ...
user141240's user avatar
1 vote
2 answers
467 views

HashMap Implementation (dictionary) in Python

I attempted making a hashmap in python, and it was harder, due to some limitations but this is my version of dictionaries in python. Are there any way to simplify or do the same thing in less code ...
Anonymous's user avatar
  • 1,204
-1 votes
1 answer
47 views

Best way of converting a dynamic number of list items into variables in Python [closed]

I have a simple scrapy spider that crawls a page and returns H1 on the pages. Since, each page is unique, one cannot know how many h1's will be on the page. Since the scrapy spider returns a list, I ...
Sam's user avatar
  • 103
2 votes
1 answer
362 views

Hash table in Java with arrays and linear probing

I did some manual tests by instantiating the class and it seems to be working okay. I wanted some feedback on the following: Is the code well structured? I notice I have a lot of redundancy. The ...
RogerThat's user avatar
3 votes
0 answers
130 views

C# code for minimizing the sum of an array by dividing it's elements (repetition allowed) by 2 for k times

The assumption is that k is quite large as compared to no. of elements in the array and division by 2 returns ceiling of the result. Request for your review and suggestions for further improvements ...
Deepak Mishra's user avatar
1 vote
0 answers
40 views

regex on a log file utilizing stacks and queue's in Java

This would be for a MUD client, which has elements of a sort of telnet bot. Here, there's ...
Thufir's user avatar
  • 379
1 vote
1 answer
357 views

Is this locked use of a Java HashMap thread safe?

I am trying to improve the performance of one of my project's methods, which obtains the command line of a process using WMI. A summary of key points: The method is on an object representing a ...
Daniel Widdis's user avatar
3 votes
2 answers
747 views

Best approach for converting list of nested dictionaries to a single dictionary with aggregate functions

I've looked through a lot of solutions on this topic, but I have been unable to adapt my case to a performant one. Suppose I have a list of dictionaries stored as: ...
Jasper Sardonicus's user avatar
4 votes
2 answers
4k views

Increment values in a dictionary

In my continued venture to teach myself C# I came across an exercise using Dictionary. I created a class that has a method. In that method it creates a dictionary with keys/values. A string is ...
Milliorn's user avatar
  • 620
4 votes
1 answer
511 views

simple map in C

I wrote a simple map structure in C: map.c ...
xrfang's user avatar
  • 143
1 vote
0 answers
32 views

Simplifying decision tree when working with map which has two keys and value as a slice

Can this logic not be simplified more, the code works, but it has become too much of a spaghetti. The requirements are that there should always be one connection if possible in ...
JonB's user avatar
  • 431
3 votes
1 answer
283 views

Is this an optimal implementation for the knapsack algorithm?

I have implemented a solution for the knapsack problem while breaking an item is allowed. I've used the dictionary data structure where I used weight as a key and value per weight as a value. After ...
Mahmudul Hasan's user avatar
1 vote
1 answer
119 views

Dictionary or custom Collection

I have a list of rule names coming from .xml file. These rule names needs to be validated against rule names in database (Validator.cs). If valid, then ...
iniki's user avatar
  • 335
1 vote
1 answer
282 views

LeetCode: Divide Array in Sets of K Consecutive Numbers C#

https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/ Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into sets of ...
Gilad's user avatar
  • 5,321
3 votes
1 answer
367 views

Finding out the indices of common elements in two array lists having duplicate elements

I have two lists which are also having some duplicate elements , i am converting this list to map as key value pair with element index as the value for the key - element List 1 : [1, 2, 3, 4, 5, 6, ...
Anurag Tiwari's user avatar
1 vote
0 answers
45 views

Map of objects sharing characteristics [closed]

What I'm trying to achieve From a list of lists of elements (one element can be in multiple lists, but only once in each list), I want to generate a map whose keys are each elements and the values ...
Mathieu's user avatar
  • 127
1 vote
0 answers
233 views

Convert dict to array in Python [closed]

I have a dictionary that looks like this: Counter({(1, 9): 3, (4, 2): 2, (3, 0): 1, (5, 4): 1}) I would like to convert it to an array that would look like this: ...
Per Helge Semb's user avatar
12 votes
3 answers
2k views

Implementing a rectangle class

First I've to indicate that this is my homework. An example of a given input is: s1 = {'p1': (x1, y1), 'p2': (x2, y2)} where all names and coordinations are ...
Nitwit's user avatar
  • 501
7 votes
1 answer
1k views

Merging two dictionaries together whilst adding keys but multiplying values

I have two dictionaries and a merged dictionary: dict1 = {-3: 0.3, -2: 0.1, 1: 0.8} dict2 = {0: 0.3, 1: 0.5, -1: 0.7} dict_merged = {} I have code that basically ...
gjdpm1's user avatar
  • 73
1 vote
1 answer
60 views

Iterating lists and updating dictionary for corresponding match logic improvement

I have two lists: Users - [<UserObject1>, <UserObject2>, ...] Contributions - [...
ParthS007's user avatar
  • 197
4 votes
2 answers
3k views

Takes json input and builds dynamic json output based on values in input: Looking for a better way to accomplish this

I have this specific scenario where I'm going to get a JSON that could have multiple Objects. From the Multiple Objects I will create a new Json that can have nested arrays growing by n amount ...
Philip Jay Fry's user avatar
1 vote
1 answer
599 views

Premier League data scraper

I have started a project where I am scraping JSON-data from an API. How the scraping is done right now is done in a very repetitive way where the keys of interest are specified and scraped. The data-...
MisterButter's user avatar
2 votes
0 answers
67 views

Pythonic way to cast a dictionary into a pd.DataFrame with two columns?

I have a dictionary where for each key, a single value is stored. Say import pandas as pd dd = {'Alice': 40, 'Bob': 50, 'Charlie': 35} Now, I want to ...
Qaswed's user avatar
  • 183
9 votes
2 answers
4k views

Better way to iterate through a dictionary and comparing its keys with itself

I have a dictionary with author names as keys and values of None. I want to use fuzzywuzzy ...
Trevor Allen's user avatar
1 vote
0 answers
89 views

get better performance [closed]

I have this code that works, but I'm sure that it can be done better, any suggestions? ...
Iria's user avatar
  • 111
4 votes
3 answers
3k 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 ...
Sara's user avatar
  • 151
-1 votes
1 answer
56 views

Comparing dictionary values from list [closed]

I'm writing some Python code that will handle huge datasets. On a small scale, this snippet works fine, but as the datasets become bigger it grinds my script to a halt (I know it is this part as I ...
Jessica Chambers's user avatar
3 votes
1 answer
433 views

SHA256 javascript implementation

I implemented a sha256 hash function for javascript just for a practice and I want to know if my code needs more improvement. Please tell me which to simplify if there's any. Thanks. Here is my code: ...
MMJM's user avatar
  • 173
5 votes
1 answer
308 views

Minimum amount of spaces inserted in a given string, such that it gets composed only of elements from a given list

The Challenge Given a big string and a list of smaller strings, find the minimum amount of spaces that must be inserted between characters of the string in such way that it becomes composed only of ...
Lucas Werner Kuipers's user avatar
2 votes
1 answer
41 views

Print a word with numbers substituted for characters

I wrote the following Python program to take 1 word from the user and return certain characters replaced by numbers. Given a dictionary, the program should print all possible combinations of the same ...
the_endian's user avatar
  • 1,343
6 votes
2 answers
292 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 ...
Greedo's user avatar
  • 2,345
2 votes
1 answer
660 views

Python Hash Table implemented using lists

I implemented a Python Hash Table using only lists. Here is my implementation: ...
Samuel Padilla 's user avatar
1 vote
2 answers
193 views

Bi Directional Dictionary

I wrote a class that extends the dict class to provide indexing like functionality, so I can find which key(s) map to a given value in the dict. It's pretty bare ...
Tobi Alafin's user avatar
  • 1,806
0 votes
1 answer
946 views

To convert all the class properties to IDictionary<string, dynamic>

I have the requirement to return the result of my ViewModel as a Dictionary of KeyValue pairs. My view model comprises of multiple classes and can have null values in properties. I need to return only ...
Sahil Sharma's user avatar
2 votes
1 answer
339 views

Add items to Dictionary from another dictionary on cell value change

I have created a very simple Class Module and a Dictionary to store original values when the workbook is opened as part of this project ive been working on. When the workbook opens I call a test to ...
Zack E's user avatar
  • 535
1 vote
2 answers
189 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 ...
Sebastian Delgado's user avatar
9 votes
3 answers
1k views

Creating an affinity-matrix between protein and RNA sequences

I wrote an algorithm that analyzes protein-RNA interactions and I found that the following function is the bottleneck that causes performance issues: ...
KaPy3141's user avatar
  • 243
5 votes
1 answer
788 views

Normalizing mixed format nested dictionary with delimiter separated keys

I recently worked with some pickle files which had a really strange format where the keys are sometimes delimiter separated with colons and placed in the same depth but also mixed with ordinary key ...
Linus's user avatar
  • 917
2 votes
2 answers
1k 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 ...
Linny's user avatar
  • 9,989
1 vote
0 answers
66 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 ...
devil0108's user avatar
1 vote
2 answers
664 views

Check if dictionary keys are declared, if not leave them as true

I've tried with: dictionary.TryGetValue("MoreDetails", out bool MoreDetails); but if the key is not present it defaults to false, and I need it to default to ...
user33276346's user avatar
2 votes
1 answer
97 views

Dictionary function for R

I'm new to R and have created a dictionary function. A user will input a phrase into a text field and the server will read it and see if there's a match in a back-end data table and if so, output the ...
rNewb23's user avatar
  • 23
12 votes
4 answers
6k views

Extraction of value from a dict-tree, given a path of arbitrary length

Problem: We read a complex json-file which grants us a tree in terms of a python "dict of dicts". We're then requested to retrieve a specific path from the tree, represented by a list of elements. The ...
Wololo's user avatar
  • 223

1 2 3
4
5
19