Questions tagged [hashset]

A HashSet encapsulates operations that allow for the comparison of elements in collections. HashSets are frequently used to determine overlapping and unique elements within a collection.

HashSet<T> was introduced in .NET Framework 3.5 as part of the System.Collections.Generic namespace. HashSet is an unordered collection containing unique elements and provides a set of standard set operators such as intersection and union (plus many more). It has the standard collection operations Add (although this method returns a Boolean indicating whether or not that element already existed in the collection), Remove, and Contains, but because it uses a hash-based implementation for object identity, these operations are immediately accessible without looping the entire list as occurs with the List<T> collection for example (O(1) rather than O(n)).

Source: Linq to Objects using C# 4.0, Troy Magennis, Addison Wesley, 2010, Pearson Education Inc, ISBN-13: 978-0-321-63700-0

References

2277 questions
0
votes
1 answer

Exceptional return value of java.io.File.delete() ignored

i am facing the issue Exceptional return value of java.io.File.delete() ignored. when i delete the file if exist. Set sourceFiles = new HashSet(); sourceFile = path + folder + File.separator + fileName + ".txt"; sourceFiles.add(new…
Jony Mittal
  • 151
  • 6
  • 23
0
votes
1 answer

Iterating Hashsets

Good morning guys I have a hashset which has different objects Object has attributes GroupName MachineName EmailAddress Now from the HashSet I have to find the Object which has same MachineName and EmailAddress but different Group and add into an…
Makky
  • 17,117
  • 17
  • 63
  • 86
0
votes
1 answer

How can I add each instance of a scriptable object to a collection?

hello :) I wish to add each and every instante of an scriptable object class to a HashSet (which is in a static class in a separate script). I did this by creating a method that adds said class to the hashset and I called this method in the…
user12848525
0
votes
1 answer

cannot convert from 'ListMapColor.MyContainer' to 'System.Drawing.Color'

Im tryin to add a list with Hashset. what im tryin to do? Im Tryin to mapping Haset Color some piece of image Why ? Because i wanna to Compare Hashset list Colors in Real time and i need my own libary to gain process fast in real time for compare…
Maguim
  • 3
  • 2
0
votes
3 answers

Can someone please explain this HashSet question in Java?

import java.util.HashSet; import java.util.Set; public static boolean canTwoMoviesFillFlight(int[] movieLengths, int flightLength) { // movie lengths we've seen so far Set movieLengthsSeen = new HashSet<>(); for (int…
0
votes
1 answer

Replace HashSet value by looking up key in self

I have a map: HashSet and want to conditionally mutate each of the values. I want to lookup the new values in the same HashSet that I am mutating. How can I do it without borrow checker problems? fn main() { let mut map =…
Adamarla
  • 739
  • 9
  • 20
0
votes
2 answers

How do you use hashset with a binary reader in c#

I am trying to save a hashset to a database and then retrieve it, but I can not figure out how to use the binary reader for this. Here in #region Types TypeList = new Dictionary I have…
0
votes
0 answers

Java: How to create method createObject and eliminating duplication in HashSet?

this is my first post on this forum and have issue with HashSet. I have three classes: Class Car, Main and CarManager. Class Car has String a and String b to create objects in HashSet. The CarManager has method "public Car createCar(String a, String…
0
votes
0 answers

List> Except() List> Compare Lists of HashSets

I have two lists of HashSet and want to exclude one from the other. Should be able to achieve that using the Excepts extensions method. say List1 is [{1,2}, {2,3}] and List2 is [{2,3}] list1.Except(list2); should return [{1,2}] in my scenario.…
0
votes
1 answer

Scala: HashSet Intersection

I have a number of 2000+ lines of (ID1 ID2), which separated by blank space each line from a text file. The size for both ID1&2 is 100. //My load file codes def loadFile(file:Iterator[String]):Set[(Int,Int)] = { val z1 = file.map(line…
Marzack
  • 47
  • 8
0
votes
2 answers

Java HashSet contains value other than the intended one, not predefined value

I looked at this forum answer Java HashSet<> : Return false if HashSet contains values other than specified However in this forum answer, the options are predefined, for me it is not. I read from a Web Table and the other city name can be…
Sheikh Rahman
  • 895
  • 3
  • 14
  • 29
0
votes
1 answer

How the custom object is stored in HashMap

I have a problem in understanding below code how heavenlyBody.addSatellite(satellites ); is added into HashMap ? when HeavenlyBody planet1 = solarSystem.get("Mars"); is called the planet1.getSatellites() returns Phobos and Deimos satellites for…
Uday Kiran
  • 487
  • 2
  • 9
  • 29
0
votes
0 answers

C#: Is there an analog of IList for HashSets?

When I work with a List of an unknown type, I can use the IList interface like this: public void DoSomething(object o) { if (o is IList oAsList) { foreach (object listItem in oAsList) Console.WriteLine(listItem.ToString()); …
Aaginor
  • 4,516
  • 11
  • 51
  • 75
0
votes
1 answer

Automatically convert HashSet to concatenated string in Spring Boot

I'm fairly new to Spring Boot and am currently working on a form for a CMS to create an article. The article has keywords that are similar to SO's tag system. For now, it's a simple comma-separated list of keywords. However, I'm running into an…
Eric
  • 2,201
  • 5
  • 29
  • 35
0
votes
3 answers

What happens when you shift an int left

I'm trying to understand part of this code that was created here to create a my_hashset: https://leetcode.com/problems/design-hashset/discuss/548792/Java-solution-faster-than-99 class HashCode_from_leet { int[] bitArr; private static…
Katie Melosto
  • 1,047
  • 2
  • 14
  • 35