hashset

Haskell: Data.HashSet (from unordered-container) Performance for Large Sets

不打扰是莪最后的温柔 提交于 2019-12-23 08:13:36
问题 The data First of all, let's generate some input so we have concrete data to talk about: python -c 'for f in xrange(4000000): print f' > input.txt this will generate a file input.txt containing the numbers from 0 to 3999999, each on its own line. That means we should have a file with 4,000,000 lines, adding up to 30,888,890 bytes, roughly 29 MiB. Everything as a list Right, let's load everything into memory as a [Text] : import Data.Conduit import Data.Text (Text) import Control.Monad.Trans

Haskell: Data.HashSet (from unordered-container) Performance for Large Sets

被刻印的时光 ゝ 提交于 2019-12-23 08:13:07
问题 The data First of all, let's generate some input so we have concrete data to talk about: python -c 'for f in xrange(4000000): print f' > input.txt this will generate a file input.txt containing the numbers from 0 to 3999999, each on its own line. That means we should have a file with 4,000,000 lines, adding up to 30,888,890 bytes, roughly 29 MiB. Everything as a list Right, let's load everything into memory as a [Text] : import Data.Conduit import Data.Text (Text) import Control.Monad.Trans

What is the fastest/safest method to iterate over a HashSet?

拈花ヽ惹草 提交于 2019-12-23 07:48:27
问题 I'm still quite new to C#, but noticed the advantages through forum postings of using a HashSet instead of a List in specific cases. My current case isn't that I'm storing a tremendous amount of data in a single List exectly, but rather than I'm having to check for members of it often. The catch is that I do indeed need to iterate over it as well, but the order they are stored or retrieved doesn't actually matter. I've read that for each loops are actually slower than for next, so how else

In C# why is it faster to Create a HashSet from a List, instead of starting with a HashSet?

假如想象 提交于 2019-12-23 07:21:22
问题 I have a method that takes an upper limit, and returns a list of primes numbers up to that limit. public static List<int> AllPrimesUnder(int upperLimit) I later decided that I really just needed to do lookups on the list, often just asking the question "Is This Prime". Since I was dealing with all primes under values like a million, I realized that HashSet was the structure I should be using. Certainly the lookup using the result of the method was faster, but the method its self was slower .

Does Linq Contains() check for HashSet?

拥有回忆 提交于 2019-12-23 07:06:08
问题 Sometimes a HashSet is exposed through a property as an IEnumerable. It is well known that for enumerable.Count() the code checks if it is a collection, so it doesn't enumerate the whole list, but takes a shortcut. Is there any similar check for using the Linq version of enumerable.Contains(x) and HashSets? 回答1: From the reference source, yes it does, though not directly: public static bool Contains<TSource>(this IEnumerable<TSource> source, TSource value) { ICollection<TSource> collection =

Is there any way to look up in HashSet by only the value the type is hashed on?

与世无争的帅哥 提交于 2019-12-22 10:04:40
问题 I have a struct that has, among other data, a unique id : struct Foo { id: u32, other_data: u32, } I want to use the id as the key and keep it inside of the struct: use std::collections::HashSet; use std::hash::{Hash, Hasher}; impl PartialEq for Foo { fn eq(&self, other: &Foo) -> bool { self.id == other.id } } impl Eq for Foo {} impl Hash for Foo { fn hash<H: Hasher>(&self, state: &mut H) { self.id.hash(state); } } This works: pub fn bar() { let mut baz: HashSet<Foo> = HashSet::new(); baz

HashSet contains() method

让人想犯罪 __ 提交于 2019-12-22 05:18:37
问题 I executed below code and found the output was false . import java.util.Set; import java.util.HashSet; public class Name { private String first, last; public Name(String first, String last) { this.first = first; this.last = last; } public boolean equals(Object o) { if (!(o instanceof Name)) return false; Name n = (Name) o; return n.first.equals(first) && n.last.equals(last); } public static void main(String[] args) { Set<Name> s = new HashSet<Name>(); s.add(new Name("Donald", "Duck")); System

Entity Framework - related ICollection getting materialized into HashSet

柔情痞子 提交于 2019-12-21 04:52:29
问题 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 ICollection<TransactionRow> Rows { get; set; } } However other entity classes have their related collection materialized into EntityCollection . I am loading the

Java : HashSet vs. HashMap

拜拜、爱过 提交于 2019-12-20 14:06:30
问题 I have a program working on enormous data sets. The objects are best stored on hash implemented containers since the program keeps seeking for objects in the container. The first idea was to use HashMap since the methods get and remove of this container are more suitable to the uses I need. But, I came to see the use of HashMap is pretty memory consumable which is a major problem, so i thought switching to HashSet will be better because it only uses <E> , and not <K,V> per element, but when I

Converting from HashSet<String> to String[]

断了今生、忘了曾经 提交于 2019-12-20 09:57:54
问题 What's the best way to convert HashSet<String> to String[] ? 回答1: set.toArray(new String[set.size()]); 回答2: Answer of JB Nizet is correct, but in case you did this to transform to a CSV like string, with Java 8 you can now do: Set<String> mySet = new HashSet<>(Arrays.asList("a", "b", "c")); System.out.println(String.join(", ", mySet)); Output is: a, b, c This allows to bypass arrays. 来源: https://stackoverflow.com/questions/5474656/converting-from-hashsetstring-to-string