I am exploring the HashSet<T> type, but I don't understand where it stands in collections.
Can one use it to replace a List<T>? I imagine the performance of a HashSet<T> to be better, but I couldn't see individual access to its elements.
Is it only for enumeration?
...
Let's say I have a class called myclass.
In my code I have two instances of myclass, myclass1 and myclass2.
Everything about them is (public and private) properties are identical.
If I try to add both of them to a HashSet will it add both or only one?
If it adds both and I don't want it to, can I overidde equals in the myclass definiti...
I have a hashset that I want to serialize to a SQL Server table. When serialized hashset looks like this...
<InstallerContactIds>
<int>153771</int>
<int>209572</int>
</InstallerContactIds>
I am using the following to insert the XML into the table...
INSERT INTO dbo.cv_AssessorActionPlanInstallers
SELECT @AssessorActionPlanId...
I'm writing a plug-in for a 3D modeling program. There is a a feature of the API where you can intercept the display pipeline and insert additional geometry that will be displayed with out actually being in the model (you can see it but you can't select/move/delete etc. etc..).
Part of this feature of the API is a method that gets calle...
Hi, I am building and sort of RSS reader in java as my first object-oriented program and would love some OO design tips.
I have a Reader class with a list of Feed objects for RSS feeds, and each Feed downloads news items into Article objects in an Articles list.
What I want to do is find a way to relate articles from multiple sources....
I am new to C++ and STL. I am stuck with the following simple example of a hash set storing custom data structures:
#include <iostream>
#include <ext/hash_set>
using namespace std;
using namespace __gnu_cxx;
struct trip {
int trip_id;
int delta_n;
int delta_secs;
trip(int trip_id, int delta_n, int delta_secs){
th...
I've always loved trees, that nice O(n*lg(n)) and the tidyness of them. However, every software engineer I've ever known has asked me pointedly why I would use a treeset. From a CS background, I don't think it matters all that much which you use, and I don't care to mess around with hash functions and buckets (in the case of Java).
In w...
I'm looking for insight into the heads of HashSet designers. As far as I am aware, my question applies to both Java and C# HashSets, making me think there must be some good reason for it, though I can't think of any myself.
After I have inserted an item into a HashSet, why is it impossible to retrieve that item without enumeration, hard...
I need a HashSet that preserves insertion ordering, are there any implementations of this in the framework?
...
I have an immutable Value Object, IPathwayModule, whose value is defined by:
(int) Block;
(Entity) Module, identified by (string) ModuleId;
(enum) Status; and
(entity) Class, identified by (string) ClassId - which may be null.
Here's my current IEqualityComparer implementation which seems to work in a few unit tests. However, I d...
I'm trying to create the extension method AddRange for HashSet so I can do something like this:
var list = new List<Item>{ new Item(), new Item(), new Item() };
var hashset = new HashSet<Item>();
hashset.AddRange(list);
This is what I have so far:
public static void AddRange<T>(this ICollection<T> collection, List<T> list)
{
fore...
HashSet does not have an AddRange method, so I want to write an extension method for it. This is what I have:
public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T> list)
{
foreach (var item in list)
{
collection.Add(item);
}
}
I have a base class, Media, and a derived class, Photo. This is t...
How do I convert a HashSet<T> to an array in .NET?
...
Hi,
I have a pretty big (100'000s of entries) HashMap. Now, I need a HashSet containing all the keys from this HashMap. Unfortunately, HashMap only has a keySet() method which returns a Set but not a HashSet.
What would be an efficient way to generate such a HashSet using Java?
...
Ok Apparently I'm missing something here. I cannot seem to get a HashSet to work. I'd imagine it's probably something easy I'm just overlooking.
import testing.Subclass;
import java.util.HashSet;
public class tester{
public static void main(String[] args) throws Exception{
HashSet<Subclass> set = new HashSet<Subclass>();
set....
I have been trying to understand the internal implementation of java.util.HashMap and java.util.HashSet.
Following are the doubts popping in my mind for a while:
Whats is the importance of the @Override public int hashcode() in a HashMap/HashSet? Where is this hash code used internally?
I have generally seen the key of the HashMap be ...
Hello,
I'm using a ListBox to maintain a list of items in a WPF application. The ListBox data source is a HashSet wrapped in an ObservableCollection. ie, I have the following code :
this.shackSet = new ObservableCollection<Shack>(new HashSet<Shack>());
this.shackListing.ItemsSource = this.shackSet;
... where shackListing is a ListB...
I am working on a project that involves me using a HashSet of a class I made, which I will name Test. I defined the stated HashSet like so:
HashSet<Test> t = new HashSet<Test>();
t.add(new Test("asdf", 1));
t.add(new Test("hello", 2));
t.add(new Test("hello", 3));
I tried using
t.contains(new Test("asdf", 1));
but it returns false....
I have this code in a reserved word boolean format:
private boolean isIdent(String t) {
if (equals(t, "final") || equals(t, "int") || equals(t, "while")
|| equals(t, "if") || equals(t, "else") || equals(t, "print")) return false;
if (t!=null && t.length() > 0 && Character.isLetter(t.charAt(0))) return true;
...
Ive managed to parse the entire contents of a given input text file and store each word in a hash set. But now i need to find the frequenct of each of these words in this input file, any suggestions as to how I can go about? :)
...