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.

HashSet<T> was introduced in .NET Framework 3.5 as part of the System.Collections.Generic namespace. HashSet is an unordered collection containing unique elements and provides a set of standard set operators such as intersection and union (plus many more). It has the standard collection operations Add (although this method returns a Boolean indicating whether or not that element already existed in the collection), Remove, and Contains, but because it uses a hash-based implementation for object identity, these operations are immediately accessible without looping the entire list as occurs with the List<T> collection for example (O(1) rather than O(n)).

Source: Linq to Objects using C# 4.0, Troy Magennis, Addison Wesley, 2010, Pearson Education Inc, ISBN-13: 978-0-321-63700-0

References

2277 questions
0
votes
0 answers

Fastest method to find empty slots in an array/list/hashtable or empty values in a Dictionary

I have n layers of classes representing data repositories, that store a value keyed on a tuple of DateTime and TimeSpan. The purpose of the "layers" is as a caching mechanism; the bottom-most layer is the slow data origin, and the top-most layer…
Alex Norcliffe
  • 2,439
  • 2
  • 17
  • 21
0
votes
2 answers

How to lookup inner hashset in dictionary and return key value in c#?

I am trying to store signalR groups in Dictionary> But i do not know how to lookup a string value in HashSet and return key string? var dict = new Dictionary>(); dict["GroupA"] = ["user1","user2","user3"]; …
user3565914
  • 51
  • 1
  • 9
0
votes
1 answer

Hashset toList() time complexity in kotlin, is it constant or not?

I'd imagine it could be O(1) but can't find any info on it online.
0
votes
2 answers

Adding elements to a HashSet while Iterating

So my program is a version of paint. It creates a canvas and allows me to paint over the canvas with my mouse by getting Point's from the mouse using a HashSet and Iterator. It also connects to another identical program via a DatagramSocket and…
shurda
  • 67
  • 8
0
votes
3 answers

Duplicates is coming in HashSet

In my android development I am getting particular data from api. And using that data I iterate to create HashSet. The purpose of this implementation is to remove the duplicates. But still duplicate is presenting. for(int i=0;i
deluxan
  • 372
  • 1
  • 5
  • 22
0
votes
3 answers

Proper use of HashSet.contains()?

I'm attempting to generate a maze using a version of Kruskal's algorithm. I need to check if some coordinates (in an int[] array, eg [1, 5]) are in an existing set. Here is a copy of the part of the code; // find sets containing cells to be…
0
votes
2 answers

Strange behavior while using HashSet

I'm using a HashSet to store objects of a new type that I wrote. The type definition is of the following sort: class Node{ Node arr[] = new Node[5]; boolean flag = false; } I rewrote hashCode as follows: int hash =…
efficiencyIsBliss
  • 3,043
  • 7
  • 38
  • 44
0
votes
2 answers

Java Collision in Hashset collection

How I can prove by jUnit test that HashSet handled collision. For example I can fill HashSet with 10000 elements in for loop, but which parameter should show me that I have collision, I suppose to think about collection size, but not pretty sure…
0
votes
0 answers

How to sum elements in a vector whose index is in a HashSet?

I would like to sum elements in a vector whose index exists in a hashset. I assume there is a combination of iterator adaptors I could use to achieve this, but can't seem to figure out what to use. I know I could create a function and use a for…
Michael Hall
  • 2,834
  • 1
  • 22
  • 40
0
votes
1 answer

How to check if a HashSet> contains duplicate values of a List in C#?

I do have a HashSet in C# which looks like following: HashSet> _hash = new HashSet>(); Now, I have inserted a value into it as below: _hash.add(new List {1,7}); When I write following code after the code…
Lost
  • 12,007
  • 32
  • 121
  • 193
0
votes
1 answer

Hibernate PersistenceSet and Lombok EqualsAndHashCode issue

I have an entity, let's say an item which uses a Lombok annotation @EqualsAndHashCode(callSuper = true) which autogenerates equals() and hashCode() methods. The entities are put inside a HashSet collection. The problem is that when I am getting the…
PrzemyslawP
  • 190
  • 1
  • 13
0
votes
1 answer

Loop through HashSet of Objects Java

I am trying to loop through a HashSet of Enum Objects in Java 8 to see if a value is equal to a specific string. I have tried both equals and == but its not returning true. HashSet looks like: I have tried the following: for(Object g : groups){ …
0
votes
1 answer

How to write bytebuddy code for private HashMap> hm;?

If I write bytebuddy code .defineProperty("hm",TypeDescription.Generic.Builder.parameterizedType(HashMap.class, String.class, HashSet.class).build()) like this ,Then result is private HashMap hm; but my requirement is private…
0
votes
3 answers

Create Intersect of HashSet and remove Items from class structure with extracted ID's

lets assume I have the following classes: public class ServiceStatistics { public string LocalId { get; set; } public string OrganizationId { get; set; } public List Elements { get; } = new…
Martin Felber
  • 121
  • 17
0
votes
4 answers

Unable to call a method from classes within a HashSet

What I am trying to do is sum up the impact values in Hazard Class For example it will go through a list of occupants, find a hazard and get the impact amount from it. Then sum the total impact of all hazards and return that value to me. Below I…