Questions tagged [hashmap]

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
0 votes
0 answers
14 views

Vector as key in HashMap in Matlab - Is that possible? [duplicate]

Assume that you are creating a HashMap in Matlab and you are using int64 as the data type for the key. S = containers.Map('KeyType', 'int64', 'ValueType', 'any'); But you want to use multipley ...
euraad's user avatar
  • 2,559
0 votes
0 answers
73 views

function breaks ranged-based for

Somehow, in the ranged-based for loop in findLongestPath(), the dfs() function makes it so the loop quits after the first iteration instead of going through every element to pass it to the function ...
Olb's user avatar
  • 1
0 votes
1 answer
26 views

How should I search items in a nested HashMap with inner key?

I have a nested HashMap HashMap<String, TreeMap<Integer, Item>>, and now I know the inner key Id(Integer) in TreeMap but don't have the key String in HashMap. Could I use some build-in ...
snow's user avatar
  • 5
-2 votes
0 answers
18 views

Problem with asynchronous webservices client deployed in multiple pods

I have an asynchronous webservices client with a completionable future stored in a HashMap, the problem is that if I deploy this client in multiple kubernetes pods exposing with ingress the endpoint ...
Hector Ahs's user avatar
4 votes
1 answer
53 views

Why do HashMap::get and HashMap::entry take different types of key?

The signature of HashMap::entry is: pub fn entry(&mut self, key: K) -> Entry<'_, K, V> OK, looks good. I want to take an entry from the HashMap whose key is K, so of course I need to ...
Kodra's user avatar
  • 59
0 votes
1 answer
41 views

Time Complexity of accessing [class variables,functions] vs [dictionary values,keys] in Python3

I implemented trie by using classes and by dictionaries separately and got different runtimes.Trie implementation with dictionaries worked about 2.5 times faster than trie with classes when input size ...
Ahmet Cicek's user avatar
1 vote
2 answers
37 views

Merging two hashmaps with their values combined as object of specific class

I have a class like public class Values { BigDecimal a; BigDecimal b; } And two maps with the same keys like Map<String, Double> map1 = Map.of("A", 123.1, "B", 345....
Alexander Konev's user avatar
0 votes
1 answer
43 views

How to initialize a HashMap whose values are functions that return trait objects from functions that return concretes types?

I have the following Rust toy code, which is building a global HashMap with closures that return a Struct that is implementing a Trait (please excuse the silly example) pub trait Animal { fn ...
Jaka's user avatar
  • 1,207
1 vote
0 answers
57 views

Changing ownership back and forth

I'm new to Rust and I'm still struggling with borrowing and move concepts. To set the context, I'm using a library (namely MVT ) that uses following construct to create a layer: let mut tile = ...
Nino's user avatar
  • 441
0 votes
1 answer
36 views

split String twice and put it in a HashMap

I have a String atp.Status="draft";pureMM.maxOccurs="1";pureMM.minOccurs="1";xml.attribute="true" and want to split it twice and insert it into a HashMap. For ...
matti's user avatar
  • 3
0 votes
1 answer
49 views

Java Streams to find elements in a list of mapLists

Can you help me converting the below logic to make use of streams. This works fine but i want to use streams instead of this List<Map<String, Object>> list1=new ArrayList<>(); List&...
naveen's user avatar
  • 21
0 votes
1 answer
71 views

Bucket definition in HashMap

I'm trying to understand how a bucket(index) is determined in a hashmap by the key and I've read 3 ways to determine it, but there can't be 3. 1) index = hashCode(key) & (n-1) 2) index = hashcode %...
Konstantin's user avatar
0 votes
1 answer
39 views

How to add as many instances of a Pane defined in a separate fxml file as there are entries in a HashMap into a ScrollPane?

The Pane (pane - fxml: deadline-example.fxml) has elements (Labels & a pie chart) that are set based on a specific instance of the Deadline class. I also have another scene (deadline-menu.fxml) ...
wan1796's user avatar
0 votes
2 answers
41 views

Can Rust use a HashMap as a key in another HashMap? [duplicate]

Example: let mut test: HashMap<HashMap<String, String>, String> = HashMap::new(); test.insert(HashMap::from([("test", "test")]), "test"); The compiler doesn'...
astonius's user avatar
-1 votes
1 answer
56 views

Search in Hashmap for a key potentially missing a char or having an extra char at the end

Looking for a way to look for a word where the user is not smart enough to spell it correctly, I have already handled many cases (like capitalizing the word so it match the string expected on the ...
Antonin GAVREL's user avatar
0 votes
2 answers
45 views

Iterate through Vec<&str> and accumulate value to a variable when condition is fullfilled

My current attempt: let fruits:Vec<&str> = vec!["Banana", "Peach"]; let fruits_hashmap: HashMap<_, _> = HashMap::from_iter([("Apple", 2),("Banana&...
Antonin GAVREL's user avatar
-3 votes
0 answers
37 views

Candy Store problem solving coding challenge

You are the owner of a candy store and you have a box of 2ºn candies. Each flavor is represented by a numeric value and to arrange the candies Into n pairs such that each pair has the same flavor. The ...
karim gaber's user avatar
-2 votes
2 answers
32 views

Resize in custom HashMap - test timed out

I am implementing hashmap from scratch. I have my constructor: public MyHashMap(int initialCapacity) { resizeFactor = 2; loadFactor = 0.75; bucketSize = initialCapacity; ...
w97802's user avatar
  • 105
0 votes
2 answers
43 views

Merge two map with different types

I hope all is good for you. I have two maps Map<Type1, Type2> and a Map<Type3, Type1>. I want to merge them and have at the end a Map<Type3, Type2>. How can I do that? I make this ...
Bourg's user avatar
  • 27
1 vote
2 answers
63 views

Why is my hashmap clearing some of its values?

I am trying to create a map for a tree. It maps the column number (horizontal depth) to the list of nodes with that horizontal depth. When I use the below code, somehow the map gets overwritten by the ...
Bernadette's user avatar
1 vote
1 answer
92 views

In Java, during Object#equals() call, do both objects necessarily have same hashCode ? Do we need to ever compare hashCode within equals()?

I have read somewhere, in context of HashMap : hashCode() allows sorting objects by their hash values, and then the Object#equals method only needs to be invoked when objects share the same hash value....
HyperVol's user avatar
  • 150
1 vote
2 answers
69 views

How do I correct my Sorter methods to allow for more user input?

I am trying to build a sorting algorithm for a few friends of mine, and I am making a test build for it right now. Eventually I will have it more dynamic, but currently I just have it to where it ...
L4w1i3t's user avatar
  • 41
0 votes
1 answer
67 views

GO, Map keys are being all updated

Is there something wrong in what I'm doing? I don't understand why the all the map keys are being updated, it should be only the 'ether' key. data := []byte(` [{".id":"*1",&...
Claudiu Mihai's user avatar
1 vote
2 answers
88 views

Python's collection.Counter equivalent in C# or .NET

I was solving some problems on LeetCode, while solving the problem in Python I often had to use Python's collections.Counter object. When I started solving the same problems in C# I couldn't find an ...
hammi's user avatar
  • 847
1 vote
2 answers
76 views

Two different HashMap returning the same hashCode

I have two different sets of HashMap ({u=0, h=3} and {t=3, i=0}), and it is returning the same hashCode (224). I don't understand this, hashCode needs to be different for different objects, and here ...
Anguraj Dinesh's user avatar
0 votes
0 answers
17 views

Remove duplicates from sorted Arraj Javascript Solution not working but I think it should? [duplicate]

I know I did something wrong, I'm just trying to figure out why my hashmap solution isn't giving me the right answer for this leetcode problem. The problem: https://leetcode.com/problems/remove-...
User9123's user avatar
  • 685
-1 votes
0 answers
20 views

LeetCode: Java anagram function not working for the last test case [duplicate]

I was solving this LeetCode problem and can't figure out why one of my solutions doesn't work for the last test case. public boolean isAnagram(String s, String t) { if (s.length() != t.length()) { ...
Cylinder6321's user avatar
1 vote
1 answer
35 views

Why doesn't my solution to LC 12 Integer to Roman work?

What I don't understand is when I pass tmp-=1 to the function instead as it is returning 'X' for numbers less than 10 and 'C' for numbers less than 100 and greater than 10 it loops infinitely. class ...
Dean Loyals's user avatar
0 votes
0 answers
53 views

All values of type String of all HashMap became {"bytes":"","empty":false} suddenly

An confusing error has occurred to one of my containers running stably in production environment. All values of type String of all HashMap became {"bytes":"","empty":...
holy potato's user avatar
0 votes
0 answers
36 views

I need a custom hash function for a dataclass that will produce the same hash for two instances of the class if any two of their attributes are equal

I need a hash function for the following class, similar to the eq method already implemented. The function should return the same hash value for two instances of the class if any of their attributes ...
natet94's user avatar
0 votes
1 answer
16 views

Database is null, cannot complete login page! (HashMap)

This is my database: public class Database { private Map<String, String[]> cardPinMap = new HashMap<>(); public void addCardInfo(String name, String cardNumber, String pin, ...
farisalisic's user avatar
2 votes
1 answer
63 views

What is the dead loop bug in HashMap in earlier versions? [duplicate]

I have been reading https://www.alibabacloud.com/blog/the-clever-design-of-java-map_597979 for the internal implementation of the HashMap and CHM. There is an interesting line for which I could not ...
ng.newbie's user avatar
  • 2,851
3 votes
1 answer
82 views

Trying to implement a thread-safe cache

I'm trying to implement a shared-state, thread-safe cache, using a HashMap behind a RwLock. Ideally, I would like my interface to expose a single function, which -- given the key -- will return a ...
Xophmeister's user avatar
  • 8,894
0 votes
3 answers
107 views

How to sort a map in C++ based on values?

Actually, I'm trying to sort the map by the values stored in them. The map by default has the sort function (greater<int>) applied to the key values but this is not providing the functionality ...
Soni-Sumit-Raghukant's user avatar
0 votes
1 answer
38 views

How do I keep track of top 5 values that I have stored in a Map till now while iterating a continuous stream?

I have a Java Map that has String for Keys and Integers for values. While iterating through a continuous stream and adding elements(or new Key-Value pairs) to the Map, I only want to keep the highest ...
Joe's user avatar
  • 11
0 votes
0 answers
26 views

Understanding Java Generics: Assigning Concrete Class to Interface [duplicate]

I'm trying to understand the behavior of Java generics when it comes to assigning a concrete class to an interface type. I have a scenario involving a HashMap where I want to assign instances of a ...
Fitri Halim's user avatar
0 votes
2 answers
103 views

Ordering list in C# in specific order provided

I am trying to arrange and output the elements of the list in specific order provided. The original list is as follows: var outcome = Result.ToArray() The Result returns elements in format based on ...
user14806829's user avatar
-1 votes
1 answer
42 views

HashMap extending to random length instead of 7 with for loop

I have two arrays for a card game one of type and another of color in Java. I want to run a for loop of length 7 to assert random values to the HashMaps which would be the card list for each player. ...
vardhiro's user avatar
0 votes
1 answer
47 views

Using Starts with to find the key of a List

I have a list of objects (Slack Bolt framework), one of them is appended dynamically upstream and then passed in an array list. I need to fetch out this key (it looks like this: status_block_EPOCH) ...
trever's user avatar
  • 961
-4 votes
2 answers
129 views

Finding the index of the first repeating item in an array in python

I was solving an arrays problem from GFG, where we need to find the index of the first repeating element. The question is as follows: Given an array arr[] of size n, find the first repeating element. ...
Darshika Khandelwal's user avatar
0 votes
1 answer
41 views

Set is keeping old object even after the new insertion

All my life I believed, Set will replace the existing Value when inserting new Value to maintain it's unique property. But today I am surprised that it's not, Code: enum Action { case edit ...
Youmate's user avatar
  • 23
-1 votes
0 answers
82 views

Using HashMap<String> with str key

TL;DR This question is similar to this one, but my adaptation of the @Shepmaster answer below is causing a misaligned pointer panic. // Basic idea of what's needed, but "devil in the details"...
Yuri Astrakhan's user avatar
0 votes
3 answers
57 views

One thread reading hashmap while other thread causing resizing

I understand that HashMap is not thread safe and resizing is triggered from an update operation. My question is what happens if there are two threads one performing get from HashMap and other thread ...
Manas Saxena's user avatar
  • 2,171
-2 votes
2 answers
46 views

I have solved the GROUP ANAGRAM question in leetcode in two ways.Why one of them is not giving correct result whereas the other one is returing null? [closed]

Given an array of strings strs, group the anagrams together. You can return the answer in any order. Solution 1:the correct one: public List<List<String>> groupAnagrams(String[] strs) { ...
Paurab Bhattacharjee's user avatar
0 votes
1 answer
39 views

Max Sum in array excluding adjacent numbers

maximum sum of an integer array such that if we consider an element a[i] then we should not consider a[i]-1 and a[i]+1. for example if array a = [1,1,1,1,1,2,2] the o/p = 5 and if a = [3,3,3,4,4,8,1] ...
Pavan kalyan's user avatar
1 vote
2 answers
51 views

Java return nested hashmap as string formatted as Json using Streams API

I have a nested HashMap declared as Map<String, Object>. Map<String,Object> m1 = new HashMap<>(); m1.put("name","mary"); m1.put("email",&...
thor's user avatar
  • 281
2 votes
2 answers
80 views

Returning a &HashMap from rust function

I am struggling to find an elegant to solution to access a nested map for read-only purposes in rust. I have a situation of this kind and ideally as example I could return a reference to an empty map (...
Redirectk's user avatar
  • 162
0 votes
0 answers
22 views

How can I add a Map widget in a Datarow list in Flutter?

void applyFilter(String query) { tableRow(); if (query.isEmpty) { setState(() { tableRow(); }...
Davide Resigotti's user avatar
0 votes
1 answer
52 views

How to read list of maps [closed]

I have a TestNG scenario method as @Then("User Enters Data") public void feedData(IDataReader dataTable) { List<Map<String,String>> data= dataTable.getAllRows(); } Data is ...
Pet's user avatar
  • 41
0 votes
1 answer
51 views

How to pass ids and names to d3 from rails

As with any rationalized database, the IDs, names and data are stored in separate tables. The current script (below) shows the IDs in the legend but I would like to pass in and show the names. The ...
ASing's user avatar
  • 45

1
2 3 4 5
305