In some library code, I have a List that can contain 50,000 items or more.
Callers of the library can invoke methods that result in strings being added to the list. How do I efficiently check for uniqueness of the strings being added?
Currently, just before adding a string, I scan the entire list and compare each string to the to-be...
I have this Hash Set code and when I try to run my compile method on it I get the Null Pointer Exception: null error on it. Here is the code:
private void initKeywords() {
keywords = new HashSet<String>();
keywords.add("final");
keywords.add("int");
keywords.add("while");
keywords.add("if");
...
I understand that the Set returned from a Map's keySet() method does not guarantee any particular order.
My question is, does it guarantee the same order over multiple iterations. For example
Map<K,V> map = getMap();
for( K k : map.keySet() )
{
}
...
for( K k : map.keySet() )
{
}
In the above code, assuming that the map is not mo...
I have a method that goes through the possible states in a board and stores them in a HashMap
void up(String str){
int a = str.indexOf("0");
if(a>2){
String s = str.substring(0,a-3)+"0"+str.substring(a-2,a)+str.charAt(a-3)+str.substring(a+1);
add(s,map.get(str)+1);
if(s.equals("123456780")) {
System.out.println("The sol...
How can I efficiently get a reference to a string in a HashSet<string> if I know the string exists?
i.e.
hashSet.Contains(myString) == true
string stringRef = ???
Thanks!
...
Is it possible to use a Fluent NHibernate convention to map all ICollections as sets? I have an entity like so:
public class NoahsArk
{
public virtual ICollection<Animal> Animals { get; set; }
public NoahsArk()
{
Animals = new HashSet<Animal>();
}
}
With fluent mappings, this property would be mapped as HasMan...
I have a list of ~9000 products, and some of which may have duplicates.
I wanted to make a HashTable of these products with the products serial number as their key so I can find duplicates easily.
How would one go about using a HashTable in C#/.NET? Would a HashSet be more appropriate?
Eventually I would like a list like:
Key-Seri...
Hello StackOverflow...
Could anybody tell me how I can override HashSet's contains() method to use a regex match instead of just equals()?
Or if not overriding, how I can add a method to use a regex pattern? Basically, I want to be able to run regex on a HashSet containing strings, and I need to match substrings using regex.
If my met...
I've got a whitelist of URLs I'm using, inside a HashSet<string>. I'm trying to find if the url starts with any of the items in the white list (it has to be that way round).
Edit: The previous example was a bit misleading and had a typo - I already have a base url like yahoo.com, the whitelist is just the path.
HashSet<string> whiteLis...
hello.
I want to use HashSet in my program.
but I couldn't declare HashSet.
My Computer was installed Microsoft .Net FrameWork 3.5.
and also I declared namespace. (using System.Collections.Generic)
But It didn't work.
How i fix this problem?
i am use visual studio 2005(c#) and Windows 7.
thanks.
...
Hello,
I need to create a Set with initial values.
Set<String> h = new HashSet<String>();
h.add("a");
h.add("b");
Is there a way to do it in one command?
Thanks
...
Looking at the source of Java 6, HashSet<E> is actually implemented using HashMap<E,Object>, using dummy object instance on every entry of the Set.
I think that wastes 4 byte (on 32-bit machines) for the size of the entry itself.
But, why is it still used? Is there any reason to use it besides making it easier to maintain the codes?
...
I am wondering since the HashSet is implemented via a HashMap instance , what would be the key that would be used to put data into HashSet.
i gone through the link http://www.coderanch.com/t/251832/Programmer-Certification-SCJP/certification/Difference-HashMap-HashSet...
which i dint understood properly..
Can anybody help me to underst...
I need to check that specific string contains in the set of others:
private bool Contains(string field)
{
return this.Fields.Contains(field); // HashSet<string> local property
}
What is the best type of container to use if only one task of it - to hold a number of strings and check does another one is into or does not?
...
According to the HashSet javadoc, HashSet.contains only returns a boolean. How can I "find" an object in a hashSet and modify it (it's not a primitive data type)?
I see that HashTable has a get() method, but I would prefer to use the set.
...
I need to store a big hash set, able to contain up to approx 200 millions 40 bit values. Storing it as 200 millions 64 bit value would be acceptable (despite the 200 millions * 16 bits loss).
The requirements are:
tiny memory footprint (disk space ain't an issue, memory is)
fast contains(long l) and add(long l) methods (much faster t...
I have the following code:
private static final Set<String> allowedParameters;
static {
Set<String> tmpSet = new HashSet();
tmpSet.add("aaa");
allowedParameters = Collections.unmodifiableSet(tmpSet);
}
And it cause:
Note: mygame/Game.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for detai...
I am calculating intersection, union and differences of sets.
I have a typedef of my set type:
typedef set<node_type> node_set;
When it is replaced with
typedef hash_set<node_type> node_set;
The results are different. It's a complicated program, and before I start debugging - am I doing it right? When I use functions like this:
s...
I've got a HashSet with a bunch of (you guessed it) integers in it. I want to turn it into an array, but calling
hashset.toArray();
returns an array of Object type. This is fine, but is there a better way to cast it to an array of int, other than iterating through every element manually? A method I want to pass it to
void doSomething...
I was wondering whether the .Net HashSet<T> is based completely on hash codes or whether it uses equality as well?
I have a particular class that I may potentially instantiate millions of instances of and there is a reasonable chance that some hash codes will collide at that point.
I'm considering using HashSet's to store some instance...