hashset

Java: fast disk-based hash set

隐身守侯 提交于 2019-12-20 09:45:06
问题 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 than SQL) embedded free and without nasty licensing (no Berkeley DB). LGPL fine. no false positive and no false negative, so things like disk-based Bloom Filters

is Java HashSet thread-safe for read only?

痴心易碎 提交于 2019-12-20 09:29:47
问题 If I have an instance of an HashSet after I ran it through Collections.unmodifiableSet(), is it thread-safe? I'm asking this since Set documentation states that it's not, but I'm only performing read operations. 回答1: From the Javadoc: Note that this implementation is not synchronized. If multiple threads access a hash set concurrently, and at least one of the threads modifies the set, it must be synchronized externally Reading doesn't modify a set, therefore you're fine. 回答2: HashSet will be

Why is HashMap faster than HashSet?

删除回忆录丶 提交于 2019-12-20 09:19:15
问题 I have been reading/researching the reason why HashMap is faster than HashSet . I am not quite understanding the following statements: HashMap is faster than HashSet because the values are associated to a unique key. In HashSet , member object is used for calculating hashcode value which can be same for two objects so equals() method is used to check for equality. If it returns false , that means the two objects are different. In HashMap , the hashcode value is calculated using the key object

Is there an AddRange equivalent for a HashSet in C#

女生的网名这么多〃 提交于 2019-12-20 08:52:32
问题 With a list you can do: list.AddRange(otherCollection); There is no add range method in a HashSet . What is the best way to add another collection to a HashSet? 回答1: For HashSet<T> , the name is UnionWith. This is to indicate the distinct way the HashSet works. You cannot safely Add a set of random elements to it like in Collections , some elements may naturally evaporate. I think that UnionWith takes its name after "merging with another HashSet ", however, there's an overload for IEnumerable

How to implement IEquatable<T> when mutable fields are part of the equality - Problem with GetHashCode

…衆ロ難τιáo~ 提交于 2019-12-20 05:28:04
问题 I am using Entity Framework in my application. I implemented with the partial class of an entity the IEquatable<T> interface: Partial Class Address : Implements IEquatable(Of Address) 'Other part generated Public Overloads Function Equals(ByVal other As Address) As Boolean _ Implements System.IEquatable(Of Address).Equals If ReferenceEquals(Me, other) Then Return True Return AddressId = other.AddressId End Function Public Overrides Function Equals(ByVal obj As Object) As Boolean If obj Is

Set class with mathematical set equality by default [closed]

99封情书 提交于 2019-12-20 00:20:16
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 10 months ago . HashSet does not use set equality semantics for the default equality operation. var a = new HashSet<int> { 1, 2, 3 }; var b = new HashSet<int> { 3, 2, 1 }; This evaluates to false : var c = a == b; whereas in a mathematical sense, the two sets are equal. We can of course use

Create a HashMap with a fixed Key corresponding to a HashSet. point of departure

泪湿孤枕 提交于 2019-12-19 11:17:35
问题 My aim is to create a hashmap with a String as the key, and the entry values as a HashSet of Strings. OUTPUT This is what the output looks like now: Hudson+(surname)=[Q2720681], Hudson,+Quebec=[Q141445], Hudson+(given+name)=[Q5928530], Hudson,+Colorado=[Q2272323], Hudson,+Illinois=[Q2672022], Hudson,+Indiana=[Q2710584], Hudson,+Ontario=[Q5928505], Hudson,+Buenos+Aires+Province=[Q10298710], Hudson,+Florida=[Q768903]] According to my idea, it should look like this: [Hudson+(surname)=[Q2720681

HashSet order and difference with JDK 7 / 8

不问归期 提交于 2019-12-19 09:04:31
问题 This is a two part question: Does HashSet implement some hidden ordering mechanic or it just, to quote the documentation: It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time. tells me that the order MIGHT change sometimes in the future and/or depending on memory usage? Why am I getting completely different 'ordering' (dare I say) when I switch between JDKs? Take this example: for (int i = 0; i < 1000;

Why does HashSet allow equal items if hashcodes are different?

不打扰是莪最后的温柔 提交于 2019-12-19 07:35:35
问题 The HashSet class has an add(Object o) method, which is not inherited from another class. The Javadoc for that method says the following: Adds the specified element to this set if it is not already present. More formally, adds the specified element e to this set if this set contains no element e2 such that (e==null ? e2==null : e.equals(e2)) . If this set already contains the element, the call leaves the set unchanged and returns false . In other words, if two objects are equal, then the

A Set in java never allows duplicates, but it takes StringBuffer objects with the same argument. Why?

给你一囗甜甜゛ 提交于 2019-12-19 07:01:52
问题 public static void main(String[] args) { HashSet set = new HashSet(); set.add(new StringBuffer("abc")); set.add(new StringBuffer("abc")); set.add(new StringBuffer("abc")); set.add(new StringBuffer("abc")); System.out.println(set); } Output: [abc,abc,abc,abc] Here in above code I added object of StringBuffer("abc") many times and Set adds it but Set never adds duplicates. 回答1: StringBuffer does not override Object#equals() and Object#hashCode(), so identity of StringBuffer instances is based