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.
2,282
questions
0
votes
1
answer
39
views
Linear probing hash set - efficient way to know if value is already inserted, just not in its hashed index
I am implementing a hash set in C and am using linear probing to deal with collisions. My question is, what happens when you have something like this:
a set with capacity of 32
value a has hash 14, ...
0
votes
1
answer
51
views
Using clear() vs copy() in a hashset
I was solving this problem on lintcode
I came up with the following solution first and i failed some test cases
from typing import List
class Solution:
def wallsAndGates(self, rooms: List[List[...
1
vote
1
answer
42
views
Searching Time in HashSet vs. Searching Time in TreeSet in Java
I have read that searching time in TreeSet is of the order of log(N) and in HashSet is of the order of 1 (Constant). Now, to test this in a program I have written a Java program.
import java.util....
-1
votes
2
answers
56
views
Why is a private variable of type HashSet is being shared among object instances of the class? [closed]
I recently stumbled upon this weird behaviour of Java where a variable of type Hashset, which is declared private in the parent class, is not unique for each instance of the child. Instead, all the ...
-1
votes
0
answers
120
views
Why is a HashSet allowing duplicates even though they're the same? [duplicate]
I'm writing a library for graphs (graph theory) and I'm currently working on an undirected simple graph. As such, I want the edges in a Set since there shouldn't be any duplicates allowed.
Graph.java
...
0
votes
2
answers
33
views
what difference of hashSetOf() and mutableSetOf() method in kotlin
when or where use hashSetOf() or mutableSetOf() method in kotlin or what difference of these?
I know the hashSetOf() or mutableSetOf() are the mutable but in programming when or where we use them.
val ...
0
votes
1
answer
50
views
Cleanest Way to Get a Set in Redis where Individual Elements Expire in 30 Days?
I need a data structure similar to a Python set in redis, with the additional capability of individual elements automatically expiring (getting popped) from the set 30 days after insertion. Basically, ...
-1
votes
0
answers
31
views
Java HashSet advanced for loop returns Object instead of Integer [duplicate]
Having the following issue on Leetcode problem 2215.
Tutorials for iterating using an advanced for loop seem to use the exact same syntax. What am I doing wrong here?
Compile Error
Line 15: error: ...
-1
votes
2
answers
79
views
I made a program that should send me two "best phones" from a list of phones in a text file, but only shows one?
This is a link to my java project: https://github.com/Mundanest/Java-files/tree/main/Lab%207
(This is my first time using github, as I'm not sure how else to link a java project folder so I might have ...
0
votes
0
answers
71
views
Compare a HashSet<string> with an array of strings in LINQ?
I have a List called LabelFilter. Label has a Name field which is just a string such as "Test1" or "Test2" ect. I can easily convert this list into an Array of type string or a ...
0
votes
1
answer
48
views
What is the difference between hashSet.add(n) and myList.append(n) in terms of Time Complexity? [duplicate]
Starting to leetcode and get Time Exceed Limit error.
Here is the function:
def containsDuplicate(nums: list[int]) -> bool:
tempset = []
for n in nums:
if n in tempset:
...
1
vote
1
answer
44
views
How to Find best match using hashset(Of String) ignore case
I found the following function to compare text to a list(Of String). Now I want to know if it's possible to make it ignore case in the comparison & if so how would I change this code?
Public ...
-1
votes
1
answer
57
views
How to free the memory of one element in a HashSet?
If I had a code like this:
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt(); //an integer
...
2
votes
1
answer
64
views
I am using klib library Can i use (khash) KHASH_SET_INIT_INT64() negative values for key. Because i saw in header file its using unsigned long int
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "klib/khash.h"
KHASH_SET_INIT_INT64(bin_value);
int counter = 1;
int main() {
khash_t(bin_value) *...
1
vote
0
answers
33
views
How to troubleshoot the performance of a multi-threaded algorithm using a lock-free hashset?
So, I am currently working on graph sampling and developed an algorithm to do this on multiple CPU cores. It uses a lock-free hash set and a locking job queue. Basically, a thread gets a job from the ...
1
vote
0
answers
19
views
What is the best way to process a vast number of strings keeping unique ones only?
My program produces a very large number (billions) of fixed-size strings (about 110 characters long) from which I want to extract the unique ones, expecting there to be about 100-200 million.
I cannot ...
0
votes
2
answers
69
views
HashSet iterator() is linear not constant complexity?
I came across that iterator() of HashSet takes too much time. Here is some code example which proves the observation:
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream....
0
votes
1
answer
31
views
How should i store user and user_sessions as HKEY in Redis?
I have Users table which holds passwords, role, profile id and etc. Also i have table User_sessions which holds user_id, session_id, expiry date, user_role and few other data.
Question is i want to ...
0
votes
1
answer
51
views
LeetCode problem 2503 Python optimization
I was trying to solve problem 2503 on LeetCode using Python. I came up with a solution using breadth-first search and a min-heap. However, I ran into time complexity issues with a version of my code. ...
0
votes
0
answers
94
views
what is faster, std::sort then set_intersection, or std::unordered_map with double for-loop find?
what is a faster?
sort two vectors and then do set_intersection... or
auto intersection = std::make_shared<MediaItems>();
std::sort(m_currentSearchResults->begin(), m_currentSearchResults->...
3
votes
1
answer
97
views
When does unordered_set invoke operator==?
In my thought,
This was how unordered_set insertion was working.
When insert was called, hash function is called.
In my code below I hash first and second value in pair<string, string> each.
-&...
3
votes
3
answers
116
views
Compound `HashSet` operations in Rust OR How to get an explicit difference/union of `HashSet`s in Rust
I want perform the following, in pseudocode:
(a, b, c) = (HashSet(...), HashSet(...), HashSet(...))
(a, b, c) = (a - b - c, b - a - c, c - a - b)
In Rust I tried something like this:
fn ...
0
votes
1
answer
60
views
Max Sum in array excluding adjacent numbers
maximum sum of an integer array such that if we consider an element a[i] then we should not consider a[i]-1 and a[i]+1. for example if array a = [1,1,1,1,1,2,2] the o/p = 5 and if a = [3,3,3,4,4,8,1] ...
1
vote
1
answer
168
views
Is it a good practice to instantiate a HashSet from an IEnumerable before using Contains()? [closed]
The piece of code below filters an IEnumerable<T> with another, used as a blacklist. The filtered collection iterates over content fetched remotely (lazy loading, YouTube API).
IEnumerable<...
0
votes
0
answers
38
views
Powershell: Extraction of AAD group membership, comparing membership and deleting users
I have a list of groups names in a .yaml file. I need to aggregate the membership of these groups into a single Hash set (Hashset $Yaml_Members)
I have a different group and I need to populate a ...
0
votes
1
answer
63
views
Why do cast hashsets not allow comparisons?
I am using identifier classes in my project to keep track of certain variables. During writing of unit tests for these classes I noticed that the set actions did not behave as expected.
A minimal ...
-1
votes
2
answers
82
views
How to create a "keyless" HashSet and HashMap in Rust?
The implementations of HashMap and HashSet found in std::collections both store the keys being hashed, and not just the hash. This is useful in most situations, but not all.
I am making sets and maps ...
0
votes
0
answers
158
views
Flask cache with redis
I need to cache the modules using Redis and each module cache data need to be in separate hash table. Let me say, I have 2 modules:
employee
company
Now the API's related to employee module need to ...
1
vote
1
answer
123
views
My application on Windows Forms goes into break when I try to call these functions
I have files on my computer containing all cards within a deck. What I want to do is generate all 54 numbers and give 7 of them to the user in the form of buttons so they can play these cards, another ...
1
vote
2
answers
120
views
Get hashcode of a HashSet based on the items present in the HashSet
I have a HashSet<T> and I want to get the hashcode of the HashSet<T> based on the items it contains. I am trying to identify a HashSet<T> based on it's values. I know I can use set ...
-1
votes
1
answer
58
views
INSERT action ON CONFLICT on a postgres table with a hash UNIQUE SHA256 geom
I have a PostGIS table with a Unique Index geom column.
CREATE UNIQUE INDEX IF NOT EXISTS idx_uniquegeometry_geom ON environment.fires(SHA256(ST_Normalize(geom)));"""
I am trying ...
0
votes
0
answers
36
views
Updating entities with OneToMany mappings: Spring Data JPA
I have a requirement where I need to update the entities on either side of a ManyToMany mapping.
I have a InsurancePolicy entity-
@Entity
@Table(name = "insurance_policy")
@Setter
@...
-1
votes
3
answers
150
views
How can I check for null at a specific index of a String Array to change its value?
I am trying to print an array of randomly generated sets of three numbers. Sometimes the sets include a null value when they are printed to the console.
Curiously,
it is only and always,
two of the ...
1
vote
3
answers
106
views
Java HashSet unique elements
About HashSet .... The method add() returns true if this set did not already contain the specified element.
But if I write:
HashSet<Car> hash = new HashSet<Car>();
Car a = new Car("...
2
votes
4
answers
112
views
How to convert List<Object> to Map<Integer,Set<Set<String>> in Java 8 stream
class Employee{
private Integer employeeId;
private Integer projectId;
private String mobileNumbers;
}
I want to convert List of employees to Map of projectId & mobile ...
1
vote
0
answers
100
views
type method not resolved in @Type annotation of hibernate. unable to persist Set of strings in hibernate
We are trying to persist a Set to a column "errors" in postgres db using hibernate.
As per schema definition, bytea is the data type of column "errors"
There is no mapping like ...
0
votes
0
answers
305
views
ModelMapper error-org.hibernate.AssertionFailure: force initializing collection loading: Spring Boot and JPA
I am working on a Spring Boot Project. I have 3 entities-
@Entity
@Data
public class Author {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="Author_id")
...
1
vote
3
answers
162
views
HashSet adding same list objects 2 times
I am new the the java HashSet and having problem understanding the following thing.
In HashSet duplicate objects are not allowed, and when we try to add duplicate objects it gives false as output.
...
2
votes
2
answers
70
views
What is the key in the Set's underlying HashMap: hash code or the object itself?
Is this sentence from an OCP book correct?
A HashSet stores its elements in a hash table, which means the keys
are a hash and the values are an Object.
I have created below code snippet:
class A
{
...
2
votes
1
answer
131
views
CS Mines Flood Fill problem - Java solution times out while Cpp and python succeeds (Performance improvement)
Working to solve this problem
https://mines20.kattis.com/problems/mines20.paintbucket
Java solution using TreeSet times out with time limit of less than 3 seconds
public class ...
1
vote
1
answer
70
views
Is a ISet<T> sort of "guaranteed" to have O(1) lookup speed?
Sometimes I have a method that I want to accept a broad IEnumerable<T> as input, but I'm doing an operation that might have O(2^n) impact if it's not a HashSet<T>.
Even worse when it's a ...
-1
votes
3
answers
74
views
How to write a test (of e.g. the .size() if an ArrayList that's been put into a HashSet that has a nested for each loop in it?
I'm new to Java, on an apprenticeship, and struggling really.
I'm wanting to write a junit5 test for this:
(I should add, this project is not finished, I'm working my way through trying to create a ...
-1
votes
1
answer
61
views
Filtering Records from List or Array
I am trying to filter records in C# list or array based on following conditions -
We have unique sender and multiple Receivers.
Considering Sender value as 1,
If Sender is 1 and Receiver is 2 as well ...
0
votes
0
answers
16
views
Errors in including .c and .h files in a c++ program
I am implementing a hashset in c++. I have a c linkedlist implementation that I want to include in my hashset that is comprised of a .c and a .h file. When I compile my .c and .h files together, I don'...
-1
votes
1
answer
99
views
Handling millions of records in a collection
I'm currently facing the issue of having large xmls with millions of datasets. After reading and deserializing them (which does not take too much time), the data needs to be written to the database (...
-1
votes
2
answers
58
views
Error java.lang.NumberFormatException if i try to insert 2 words into a single string (Java) [duplicate]
Error java.lang.NumberFormatException if i try to insert 2 words into a single string (Java) !!
ERROR shown is:
Enter item Chicken rice Enter amount(Dinar)
Exception in thread "main" java....
0
votes
2
answers
138
views
Getting the sum of elements of a HashSet (Java)
** I am not sure how to get the sum of certain elements from a hashset please help**
i need to add the amount from the expense
i am not sure about the line - System.out.println("Total Amount ...
1
vote
1
answer
129
views
Return a hashmap derived from an arraylist
I am trying to return a HashMap with the bus numbers and their stops.
I have already created a method to return a HashSet by passing one of the stops into it.
I feel like it can all come together, but ...
0
votes
1
answer
90
views
how can we insert hash type data in redis sink connector
while utilising the redis sink connector. We wish to add hash-type data to Redis. but we obtain string type data.
is there any possible to insert data in hash type using smt in settings.
{
"...
2
votes
1
answer
146
views
How to implement HashSet.GetOrAdd(T) extension method in .NET 6 or .NET 7 using CollectionsMarshal
On dotnet runtime Github repo there was a proposal for adding HashSet.GetOrAdd(T) - similar to
public static T GetOrAdd<T>(this HashSet<T> hashSet, T equalValue)
{
if (hashSet....