hashset

ordering a hashset example?

need an example on how to use a comparable class on a hashset to get an ascending order? Let say we have a hashset like: HashSet hs=new HashSet(); How can i get the hs to be in a ascending order?? ...

What is the performance impact on HashSet if you don't provide hashCode() methods to custom classes?

Hi, If I add custom class objects to HashSet and don't provide hashCode() methods on them, how does it impact the perfomance of hashing? Thanks, Ajay ...

O(1) maintained in hashset lookups when using alternative comparator?

If I define my own comparator for the generic HashSet<T> in System.Collections.Generic, and its runtime is O(1), is the lookup time of the hashset still O(1)? I would think no just because there doesn't appear to be a way to set the comparator. ...

HashSet load factor

If I use a HashSet with a initial capacity of 10 and a load factor of 0.5 then every 5 elements added the HashSet will be increased or first the HashSet is increased of 10 elements and after at 15 at 20 atc. the capacity will be increased? ...

JSTL <c:forEach items="${......" what are the type restrictions

I need to use a set to not allow duplicate values. I need to list them out using the JSTL <c:forEach items="${mySet}" var="set"> //Code work done here </c:forEach> Usually I use the standard array or List here but what are the type restrictions if I want to use a HashSet? ...

HashSet equality c#

I have a HashSet with it's own EqualityComparer, but I am wondering if a simple count of both sets is used before checking each element? I thought I would be able to answer this for myself in Reflector but I couldn't find any override of Equals in there. Cheers, Berryl EDIT ========== As Hans noted, it it the comparison of two sets ...

HashSet.Remove not working with EqualityComparer

I am expecting a HashSet that has been created with a specified EqualityComparer to use that comparer on a Remove operation. Especially since the Contains operations returns true! Here is the code I am using: public virtual IEnumerable<Allocation> Allocations { get { return _allocations; } } private ICollection<Allocation> _allocations...

Entity Framework - related ICollection getting materialized into HashSet

I use EntityFramework POCO + proxies + lazy loading in my project. Today I was pretty surprized to see that the class Transaction has its related collection Rows materialized into HashSet (instead of EntityCollection). I need EntityCollection for tracking changes in the collection. public class Transaction { public virtual ICollecti...

Thread-safe HashSet with Guava Collections

Hello everybody. Like the title says, i would like to get a thread-safe HashSet using Guava Collections. Can you help me? Thanks! ...

Internal implementation of .NET HashSet contains method?

Hello, I am writing a test for my library written in C#. And I want to test whether two list are same if and only if they have same elements(do not require elements in the same order). I try to convert list to hashset and check whether the two hashset are same. But the running result is not what I expected. Could anyone explain how the...

Help me understand how the conflict between immutability and running time is handled in Clojure.

Hello, Clojure truly piqued my interest, and I started going through a tutorial on it: http://java.ociweb.com/mark/clojure/article.html Consider these two lines mentioned under "Set": (def stooges (hash-set "Moe" "Larry" "Curly")) ; not sorted (def more-stooges (conj stooges "Shemp")) ; -> #{"Moe" "Larry" "Curly" "Shemp"} My first th...

HashSet does not seem to realize that two objects are the same.

I'm trying to use HashSet to store objects of a class that I created, but apparently the same objects seem to have two different hashes, which is why the contains method does not realize that the object is already in the HashSet. This leads to my program running out of heap memory. I don't think I'm doing anything wrong, but I wanted a ...

Serialize a HashSet<String> with LinQ

I'd like to take a HashSet<String> and elegantly convert it to a string. I can iterate like so: HashSet<String> words = new HashSet<string>() { "alpha", "beta", "delta" }; string joined = ""; foreach (var w in words) joined += w + ","; if(joined.Length > 0) joined = joined.SubString(0,joined.Length-1); // remove final comma Is ...

Is a hashset needed for contains with List(of String) Vb.net

Would the following: Dim stringlist As List(Of String) Dim stringlisthas = stringlist.Contains("thing1") be any slower than Dim stringlist As List(Of String) Dim stringlisthash As New HashSet(Of String)(stringlist) Dim stringlisthas = stringlisthash.Contains("thing1") Is a hashset needed for contains? ...

Select element index from hashset c#

At the moment I use a HashSet of type of my custom class. There's a point in the code when I select items under certain condition: var c = clusters.Where(x => x.Label != null It works fine and I get those elements. But is there a way that I could receive an index of that element in colletion to use with ElementAt method, intead of who...

Using base.Any(..) the warning is: 'HashSet' does not contain a definition for 'Any'.

A class inherits from HashSet to get a set of unique objects with custom EqualKeys(T x, T y) check instead of IEqualityComparer. public class UniqueSet<T> : HashSet<T> where T : IKey { public new void Add(T item) { // .. check item for null, empty key etc. if (base.Any(t => UniqueSet<T>.EqualKeys(t, item))) ...

How to remove all proper subsets?

Given a list of sets... var sets = new List<HashSet<int>>(numTags); How can I remove all the sets that are a proper subset of another? Is this the best way to do it? for (int i = 0; i < sets.Count; ++i) { for (int j = 0; j < sets.Count; ++j) { if (i != j && sets[i].IsProperSubsetOf(sets[j])) { se...

Substract HashSets (and return a copy)?

I've got a HashSet, var universe = new HashSet<int>(); And a bunch of subsets, var sets = new List<HashSet<int>>(numSets); I want to subtract a chunk, var remaining = universe.ExceptWith(sets[0]); It looks like ExceptWith is the function I want, but it works in-place. I don't want to modify the universe... I guess I should clone...

Lock a hashset in Java

I have a static HashSet of object references in my code, which has to disallow all write requests until a given method is running (which uses the hashset only for read purposes). I have read the Thread basics but am yet not clear how to proceed doing this. Can anyone please help me out ? ...

Efficient way to clone a HashSet<T> ?

A few days ago, I answered an interesting question on SO about HashSet<T>. A possible solution involved cloning the hashset, and in my answer I suggested to do something like this: HashSet<int> original = ... HashSet<int> clone = new HashSet<int>(original); Although this approach is quite straightforward, I suspect it's very inefficie...