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
1 answer

Implemented hashCode() but retainAll() still isn't working as expected

I have a doctor object and each object has a unique attribute "docMobile"(primary key). I made two different LinkedHashSets (doctorsByLoc & doctorsByAvail) of doctors. Now when i do a doctorsByLoc.retainAll(doctorsByAvail) on the two sets it…
Sanath Kumar
  • 163
  • 1
  • 12
0
votes
1 answer

using unordered_set custom hash and find

I have a hash function for my unordered_set and I want to use find functionality of set but I'm getting error. How can I use the find functionality of set using the custom hash function? I wanted to store a pair in the unordered set and for that I…
Isan Sahoo
  • 384
  • 2
  • 10
0
votes
0 answers

HashSet Remove false

Hello Im trying to remove an elemento from a HashSet that have an entity created by me that is called "Product" this is the code: Set listaItemsTrans = this.getTransaction().getTransactionItems(); HashSet listaIteratorI = new HashSet(); …
0
votes
1 answer

What is the syntax for a lambda expression that compares two elements from the same set?

I'm trying to use a lambda expression to compare each element in a hashset to all of the others. Here is an example of what I am trying to do. I have a class of type Implication. Implication has two properties - antecedent and consequent. If one…
Mikutus
  • 83
  • 1
  • 10
0
votes
1 answer

Restrain the type while inheriting

I created a java project to apply my GraphTheory course and enhance my java skills. In this project : I created a class Sommet(Vertex in English) with an attribute Id with a generic type called . I created a class Arc(Edge in English) with…
0
votes
0 answers

Java Hashset with own objects. Why not working?

I have my own class: public class Coord { int x; int y; public Coord(int x, int y) { this.x = x; this.y = y; } @Override public int hashCode() { int hash = (x + "-" + y).hashCode(); return…
mcfly soft
  • 11,289
  • 26
  • 98
  • 202
0
votes
1 answer

Set Operation Calculator using Java - Calculator part is not working

Im having trouble creating this set calculator, it was working okay at one point but I somehow messed it all up and now it doesn't actually find the Union, intersection, difference and complement anymore. Also my +n just prints a 1 instead of the…
Dez Lo
  • 13
  • 2
0
votes
1 answer

HashSet item can be changed into same item in Set

I have a Node class : public class Node : INode { public object Value { get; set; } } And I have EqualityComparer for this Node class like this : public class INodeEqualityComparer : EqualityComparer { private…
Parsa
  • 7,995
  • 2
  • 27
  • 37
0
votes
0 answers

HashSet initial capacity argument means number of buckets or number elements I expect to store?

HashSet(int initialCapacity) Constructs a new, empty set; the backing HashMap instance has the specified initial capacity and default load factor (0.75). But the term "initial capacity" is never disclosed. Some sources say it is the actual…
caasdads
  • 409
  • 4
  • 12
0
votes
1 answer

Efficient conversion of HashSet list to a single HashSet

I'm wondering what's the most efficient (edit: fastest) way of converting IEnumerable> to a single Hashset with all its elements. Sample situation: Providing: class Rectangle { public HashSet PointSet { get; set;…
eduherminio
  • 1,514
  • 1
  • 15
  • 31
0
votes
1 answer

Call a method when an object is added to HashSet property

I am writing a Graph library in C#. Here is my Graph.cs : public class Graph : IGraph { public HashSet Nodes { get; set; } public HashSet Edges { get; set; } } Rule 1 : When a Node is deleted, I want to all edges that…
Parsa
  • 7,995
  • 2
  • 27
  • 37
0
votes
3 answers

HashSet of ByteBuffer(actually integers) to separate unique & non unique elements from a ByteBuffer array

I have an array of ByteBuffers(which actually represent integers). I want to the separate unique & non unique ByteBuffers (i.e integers) in the array. Thus I am using HashSet of this type: HashSet columnsSet = new…
Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294
0
votes
2 answers

Overloading boost::hash_value for custom object pointer

Introduction Hello everyone, i try to use boost::unordered_set for a custom class type. The class stores information about coordinates and several other values but only the coordinates are used to create the hash value. Now if i want to insert a…
Yastanub
  • 1,227
  • 8
  • 19
0
votes
0 answers

Wrong Return Type/Scanner

emphasized textI am currently trying to run this code (with two different files). One file is just a dictionary of words and the other is just a file with some text. When I run this code, my code outputs the entire text of the file that is provided…
A.Torres
  • 413
  • 1
  • 6
  • 16
0
votes
2 answers

Why hashset solution is accepted whereas using hashmap getting timeout error-Finding pairs in array with difference K?

I was going through a question where the problem was to find the number of pairs which makes a difference K.Below is the code for the same.In the below code I have used hashmap however it gave correct answer but for few of the scenario's I got…
Pratyush Mayank
  • 173
  • 1
  • 1
  • 10
1 2 3
99
100