Questions tagged [hashset]

A HashSet encapsulates operations that allow for the comparison of elements in collections. HashSets are frequently used to determine overlapping and unique elements within a collection.

Filter by
Sorted by
Tagged with
1 vote
1 answer
91 views

Return a hashmap derived from an arraylist

I am trying to return a HashMap with the bus numbers and their stops. I have already created a method to return a HashSet by passing one of the stops into it. I feel like it can all come together, but ...
  • 13
0 votes
1 answer
29 views

how can we insert hash type data in redis sink connector

while utilising the redis sink connector. We wish to add hash-type data to Redis. but we obtain string type data. is there any possible to insert data in hash type using smt in settings. { "...
2 votes
1 answer
59 views

How to implement HashSet.GetOrAdd(T) extension method in .NET 6 or .NET 7 using CollectionsMarshal

On dotnet runtime Github repo there was a proposal for adding HashSet.GetOrAdd(T) - similar to public static T GetOrAdd<T>(this HashSet<T> hashSet, T equalValue) { if (hashSet....
  • 3,009
0 votes
2 answers
50 views

java Failed to convert int array to Set using Collectors.toSet() [duplicate]

i can't understand basic thing here i have : int[] arr = {2,5,2,4,6,6,1,5,4}; Set<Integer> orederSet = new HashSet<Integer>(Arrays.stream(arr).collect(Collectors.toSet())); side ...
  • 29.4k
0 votes
0 answers
43 views

Is HashSet faster than Set in Dart?

Some people uses HashSet instead of Set and I don't know the why, is it faster? The description in Dart is unclear for me and I have not found examples about their differences or reasons when to use ...
0 votes
1 answer
27 views

Use non-generic method of Hashset through reflection

I want to be able to call the Hashset.ExceptWith() method using reflection but I can't make it happen. I can't create a generic method. It seems it isn't a generic method. I also can't seem to call ...
  • 43
3 votes
2 answers
50 views

Intersect on HashSet results in compile error

I've been trying to write a program, in which I want to use the intersection of two HashSets. Therefore I wrote the following code (for test purposes): HashSet<int> test1 = new HashSet<int>...
  • 33
1 vote
1 answer
70 views

Implement unordered_map, unordered_set, map, set using vectors

This is more of an intellectual exercise, but are there battle-tested C++ libraries implementing hash map/set (std::unordered_map, std::unordered_set), red-back trees (std::map, std::set) using std::...
  • 1,208
6 votes
1 answer
88 views

Hash functions not sensitive to element order

I'm working with integer sequences with non-repeating elements, for some reasons I am tring to remove duplicates by building a hashset. int * a = {123, 145, 210, 77}; int * b = {145, 77, 123, 210}; // ...
0 votes
0 answers
40 views

Writing SQL Query for: User Entity with @ElementCollection HashSet (Spring security, postgreSQL, NativeQuery)

I have an Entity that i can persist into the Database. import jakarta.persistence.*; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority....
0 votes
1 answer
74 views

foreach loop with 2 hashset variables c# [closed]

I have the following variableAs = "A12,B12,C12" variableBs = "1.54,75.30,55.50" method (HashSet<string> variableAs, HashSet<double> variableBs) foreach (var ...
  • 387
0 votes
0 answers
55 views

Best approach for storing elements in C# that have within epsilon definition of equality

The program uses vertices in R^2 as nodes and there are edges between nodes, and ultimately more is built from there. There are a high number of circuitous ways that a point (x,y) in R^2 might be ...
1 vote
3 answers
88 views

Add unique elements in HashSet based on attributes of framework provided non-editable object classes

I am trying to generate a HashSet containing unique Employee instances. Uniqueness should be established based on the object properties. The problem is that I end up with having duplicates. Note that ...
-1 votes
1 answer
59 views

Time Complexity of .add() in HashSet of Vectors in Java

I have two java HashSets, as below: HashSet<Integer> H1 = new HashSet<>(); HashSet<Vector> H2 = new HashSet<>(); As the number of elements in each HashSet grows larger(and ...
0 votes
0 answers
10 views

How do we get immutable version of HashSet, List, and other stuffs

For example, I have hashSet like this Protected ReadOnly Property idsOfExistingOrder As HashSet(Of String) It's ReadOnly However, the ReadOnliness of that variable simple means that outsider cannot ...
  • 31.9k
-1 votes
1 answer
35 views

How do you remove a class object from a hashset?

Im quite new to programming so i apologise if this is a stupid question.. how do I remove an object from a hashset? I've tried to use .remove() but im doing something wrong because it doesn't work for ...
2 votes
2 answers
102 views

Is there a way to effectively use Map/Set in TypeScript/JavaScript with objects? [duplicate]

I am learning TypeScript with a background in Java, where I am used to being able to easily work with hashmaps and hashsets with objects by overriding the hashCode method. Is there a way to do a ...
  • 23
2 votes
2 answers
762 views

How do I make a HashSet from an iterator of chars?

I'm just starting to learn Rust and I'm still working on understanding its approach. The particular thing I'm working on is trying to find out if two strings have any characters in common. In another ...
  • 10.4k
0 votes
0 answers
25 views

C# creating LinkedPixels from a Bitmap in an Optimized way

I am doing image manipulation, I have a class that I've inherited that I can't change because it's referenced too many times to completely refactor. Here is the class as it stands. I have a Bitmap and ...
  • 448
0 votes
0 answers
23 views

In MongoEngine is there a way to override the hash function used by add_to_set? I would only like some specific object properties to be used for set

In my MongoEngine ORM I have an embedded document that looks like this: class Aggregate(EmbeddedDocument): date = StringField(required=True) quote = DictField() I am adding this aggregate ...
  • 99
0 votes
1 answer
117 views

Add value to a HashSet in Rust and add a reference to it to another datastructure

I'm trying to return a Vector from a function. This happens in a loop and I need the values to exist outside of the loop. Since I perform the return multiple times and I only need the unique values, I ...
0 votes
1 answer
65 views

containsAll returning different responses in case of Map and HashSet

Objective : Trying to replicate the behaviour of compareEmployeesMap in compareEmployees in a simpler way. However, I'm getting different response with what I tried. I have overridden the hashcode and ...
0 votes
0 answers
17 views

What hascode strategy should we use while comparing Set of custom objects in java? [duplicate]

I have this following code: class EmployeeDetails { private String designation; private int experience; public EmployeeDetails(String designation, int experience) { this....
  • 99
0 votes
1 answer
26 views

Error when trying to collect string ids (or simple string field) from collection of some objects

I have a class called Order. One of the field is id, which is just a unique identifier for an Order object. So I do something simple to get those Order Ids Dim myOrderIds = (From x In Orders ...
-1 votes
1 answer
97 views

Bloom Filter vs. Hashset

Bloomfilters are often less space efficient than hashsets if the key cardinality is small. Say we have 20bit keys and a set size of 1024 (10bit). A hashset with 1024 entries nees to store a 10-bit tag ...
0 votes
0 answers
33 views

While loop ending before the last condition with the HashSet in the loop body

Lost Permutation problem of codeforces, the loop only executes for n-1 iteration but the loop condition being for n iterations. This problem persists only when HashSet is in the main while loop body, ...
0 votes
1 answer
69 views

Remove duplicates from an unsorted linked list. I used ArrayList to solve

Given an unsorted linked list of N nodes. The task is to remove duplicate elements from this unsorted Linked List. When a value appears in multiple nodes, the node which appeared first should be kept, ...
  • 13
0 votes
2 answers
73 views

Java Unique List

I am currently trying to get a List with unique values. Technically, it should be really simple, and the obvious choice would be a HashSet. However, I want the properties of my "points" to ...
-1 votes
1 answer
68 views

How set (hashset) in python works, especially in comparison? [duplicate]

I am learning hash table and BST. I got confused when I compared (True) with True I have got True as an answer. But if I compare (True, True) == True, True I,m getting set: (False, True). Why it is ...
  • 9
2 votes
1 answer
57 views

How to make lazy Set?

new Set(getObjects()) getObjects returns an iterable object. Every iteration a new object is created. But Set gets and adds all of new objects immediately. How to make it so only when a new object is ...
0 votes
1 answer
30 views

Quiz Application returning duplicates

I'm relatively new to programming , and I'm creating a quiz application. The problem is it keeps on repeating questions Random random = new Random(); Set<Integer> set = new HashSet<>(); ...
-2 votes
1 answer
41 views

Which is faster? Concat 2 string then hashset contain or doing 2 hashset contains

I'm writing a high throughput java application and need your help settle a debate. The application process strings at a very high frequency and I need to be able to check if the input contains a ...
0 votes
1 answer
96 views

What hash functions does Typescript Object/Map/Set use to avoid collision?

I recently learned about hash table implementation and I am really interested in how Typescript implements it. I found that differnt languages might use different implementations for hashing. Does ...
0 votes
0 answers
9 views

There are several implementations of hashmap or hadhtable. What is the fastest hashtable?

There are algorithms for hashtable data structure, like bucketing for collisions, linear probing. Are there better or faster hashtable algorithms? I tried buckets, and linear probing
0 votes
0 answers
32 views

Replacing large hashset with new values from DB

I have a spring application, java 8, on startup I connect to DB to retrieve about 2 million records and I put them inside a HashSet of a specific bean and hold them in memory for various purposes. ...
  • 634
1 vote
1 answer
61 views

Time complexetiy for searching a list in a HashSet

Let's say I have a HashSet that stores lists HashSet<ArrayList<Integer>> hs = new HashSet<>(); ArrayList<Integer> a = new ArrayList<>(); ArrayList<Integer> b = new ...
0 votes
1 answer
82 views

cast set to linkedhashset

following is the scenario that I am encountering I have this set of string here Set<String> attributes = new LinkedHashSet<>(); yet I have another function with a signature LinkedHashSet ...
0 votes
2 answers
281 views

How to check which of multiple given sets are disjoint?

I want to write a method that uses the standard for loop to iterate through a given set of sets, and returns a hashmap that the disjoint sets are added to. I'm aware that the does not work correctly, ...
  • 11
0 votes
1 answer
45 views

How to retrive itrms froma set (hashset)

Good afternoon. I am stuck in helping my son in a Java program. Hope someone can help. Here is the problem. In Main i have, amoung other.... the read from scanner like this: Scanner in = new Scanner(...
-2 votes
1 answer
62 views

How to check if a set of object contains object with a particular attribute [closed]

Please look at the do while loop, I think the comment is self explanatory. I want to check if the set contains all the cards having symbol a,b,c,d (implementing it with help of array or anything else)....
1 vote
1 answer
57 views

PowerShell - array of type HashSet

I am trying to create an array of HashSets but it always comes out as simply a HashSet. Here is a test script I made: $arrHashSets = @(); $hs = New-Object System.Collections.Generic.HashSet[string]; $...
0 votes
0 answers
21 views

Leetcode 653. Two Sum IV - Input is a BST Why we need set?

I don't understand why how HashSet works in this question Here's the link to this problem https://leetcode.com/problems/two-sum-iv-input-is-a-bst/ Here's the solution to this problem the codes are ...
  • 11
0 votes
3 answers
437 views

How can I get the subset from an ArrayList?

I'm working on a problem that asks me to "Write a method that returns all of the subsets of the set formed by the integers 1 to N where N is passed to the method." If I pass N = 3 to the ...
1 vote
1 answer
30 views

Problem showing Linq IEnumerable Except to DataGridView

I have two hashsets that I want to except to get the distinct data: var dataA = new HashSet<string>(); var dataB = new HashSet<string>(); var exceptA = dataA.Except(dataB); var exceptB = ...
1 vote
1 answer
61 views

Is there a way to keep unique lists in HashSet [duplicate]

UPDATED HashSet<List<int>> hs = new HashSet<List<int>>(); List<int> list = new List<int>() { 1, 2, 3 }; hs.Add(new List<int>(){1, 2, 3}); hs.Add(list); If I ...
-4 votes
1 answer
162 views

Is Java HashSet add method thread-safe?

The Java HashSet add method combines a contains and an add method as it returns true or false if the element is already present in the collection. Is the add method atomic? I can use it in a multi-...
  • 429
6 votes
2 answers
195 views

Large size of HashSet throwing StackOverflow Error

I have 81K records of Long object and I am trying to store it in HashSet. My code snippet looks like this: private static HashSet<Long> hashSet = new HashSet<>(Arrays.asList(*81K records*))...
  • 71
-2 votes
3 answers
70 views

Checking if a user defined item exists in a HashSet

Im making a class called Book which contains the books name and price. If i insert those data into a HashSet, how would be i able to check if a book exists in that HashSet by only searching for the ...
-1 votes
1 answer
32 views

If I create a HashMap which contains only lowercase letter as key(max 26), what is the space complexity

Also for the Hashset has only lowerletter case. Is this O(1)/ or O(N) Not the performance. Eg: A leetcode problem Map<Character,Integer>store = new HashMap<>(); store only contains ...
-2 votes
1 answer
179 views

Get HashSet as value from HashMap in Rust

How can I get the value of a HashMap, which is a HashSet in Rust? Suppose I have ... #[derive(PartialEq, Eq, Hash)] struct A { name: String, } fn main() { let x: HashMap<i32, HashSet<A&...

1
2 3 4 5
45