Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
7 views

How can I insert hashmap values only into Treeset or HashSet

This is my main class: public class Main { public static void main(String[] args) throws BookNotFoundException { // TODO Auto-generated method stub //Library library = new Library(); ...
Elakkiya's user avatar
0 votes
1 answer
51 views

How can the accuracy of a Bloom filter be improved by introducing other data structures?

Suppose I have a very large dataset (for example, 1 billion keys), and I want to determine if a particular key is in this dataset. In this case, a Bloom filter is a good choice (with a time complexity ...
Kato Megumi's user avatar
0 votes
1 answer
60 views

Is RefCell::as_ptr guaranteed to stay the same for a given RefCell?

I am looking for a way to impl Hash for MyStruct where MyStruct contains `Rc<RefCell> (yes, it's a linked list of a sort). This answer suggests std::ptr::hash(self.next.as_ref()), but I have ...
De Cay's user avatar
  • 3
0 votes
0 answers
70 views

how to solve borrowing problem for HashSet

I'm making a tokenizer and have encountered some difficulties. To better understand the problem, I’ll briefly describe the components of the tokenizer: Token. There are 3 types - Constant (fixed, ...
Daniel Fillirini's user avatar
0 votes
1 answer
75 views

A hash function that maintains mathematical equality (especially for sets)

I'm working on a little math-based programming language (written in Rust) that uses sets instead of types. In it, a variable or value belongs to a set of values (eg. x : {1, 2, 3} or msg : Str). The ...
Apuji's user avatar
  • 5
0 votes
1 answer
54 views

Does EFCore Where( ... set.Contains(...)) care whether Set is List or HashSet?

Suppose I an using EFCore to query a SQL DB, and I write: myTableDbSet.Where(entity => filterSet.Contains(entity.Id)) Then does it make any difference (e.g. to performance) what the concrete type ...
Brondahl's user avatar
  • 8,507
0 votes
2 answers
102 views

What is the time complexity of populating a HashSet with n elements?

I was working on the Leetcode problem "Reverse Vowels of a String." Here is my first solution: class Solution { public String reverseVowels(String s) { String vowels = "...
Tea17_Xi's user avatar
1 vote
1 answer
89 views

Obtaining a Vec<X> from a &HashSet<X> [closed]

Assume I have some function do_stuff that takes a &HashSet<X> and wants to collect the items into a Vec<X> by copying all the elements. What is the canonical way to do that? I have ...
Smiley1000's user avatar
-1 votes
2 answers
68 views

Why is a HashSet faster than an Array in this Duplicate Integers problem? [duplicate]

I am new to learning data structures and algorithms and am starting NeetCode 150 problems. The first problem I encountered was not difficult, I understand why it works, but I am curious to why the ...
Hisham Issa's user avatar
0 votes
1 answer
91 views

C# HashSet but Want to Force Exception When Adding Duplicates

I want to use a HashSet but worry that it "silently" absorbs duplicates (by returning true/false) but not by throwing an Exception. I'm interested in an equivalent data structure that does ...
Eugene's user avatar
  • 143
0 votes
0 answers
21 views

Unexpected values in HashSet before method invocation in Java

package main; import java.io.*; import java.util.*; public class IsBSTTree { Set<Integer> set = new HashSet<>(); public static void main(String[] args) throws IOException {...
Yaduska Thambiaiyah's user avatar
1 vote
2 answers
82 views

How to build a Set in C# that compares items only by reference equality, instead of HashCode used by HashSet?

For example, what if I want to have a set of strings with different references, allowing them to have the same values? String s1 = "String1"; String s2 = "String1"; Console....
2474101468's user avatar
0 votes
0 answers
41 views

How is traversal is working on hashsets and hashmaps? [duplicate]

I realize we can use a for loop to iterate over elements of hashset. e.g. Set set = new HashSet(); for(Object object : set) { String element = (String) object; } I am not able to figure out how ...
akshay Sharma's user avatar
0 votes
0 answers
35 views

How to take care of Visited points (in 2D (x,y) ) in Java

In a subproblem, I want to get the total number of points in x-y plane i have visited. and every point must be unique. ie. if you have already visited (1,2) and if you again encounter this you won't ...
jayant rajput's user avatar
1 vote
1 answer
58 views

runtime error because of " unsigned int "

trying to solve 217. Contains Duplicate in C with HashSet. after i tried to make the calculated index to be always (+) i get an error. #define BUCKET_SIZE 1000 typedef struct ListNodes { int val; ...
Maam maam's user avatar
0 votes
0 answers
20 views

Xml serialization not working with hashset c# [duplicate]

I have a xml which is using the following structure <projects> <project> <id>1</id> <pnames>110988</pnames> </project> <project> <...
Techgeeks1's user avatar
0 votes
2 answers
112 views

HashSet: Why valueType.Equals(Object) is so slow

Having this method: public void RunFD(object fileObj, ISet<object> visited) { if (!visited.Add(fileObj)) return; if (fileObj is IEnumerable enumerablFileObj ) { foreach (var ...
user23787413's user avatar
-6 votes
1 answer
99 views

Can't print simple HashSet<int[]> elements in java [duplicate]

I try to print simple HashSet in java 20 without success what am i missing here ? public static void main(String[] args) { int[] a1 = {1,3,6,8,10,11,14,17,21}; int[] a2 = {2,4,8,9,12,14,15}; ...
user63898's user avatar
  • 30.9k
0 votes
0 answers
31 views

Fastest way to check if a GUID of set size has been encountered before

There are many questions on checking finding a GUID in a list etc. But I could not find any for just determining if a message was seen before or not. I have an API which receives requests with a ...
pooya13's user avatar
  • 2,611
0 votes
1 answer
292 views

Get an Array from HashSet in c# with operator [..]

Are these range operator and indexer? I have never seen them used like this [..h]. Line 6 in this code: public static void Main(string[] args) { int[] a ={1,2,3,4,5,6,7,8,9}; HashSet<int>...
user23569772's user avatar
0 votes
1 answer
32 views

C# Grabbing subset of table based off a Hashset if Ints

I have an Order and OrderMaster table. First I query the Master table, I then create a hashset of a column of Ints from that table. Lastly I want to get all orders that have those values. When I do ...
kaielx's user avatar
  • 49
0 votes
0 answers
57 views

Code using ArrayList and HashSet in Java i too slow

I'm trying to solve a problem at open.kattis.com (https://open.kattis.com/problems/lexicography). You get a list of words and an index and you make a list of all the anagrams of the word and return ...
Mårten Ask's user avatar
2 votes
1 answer
78 views

Why is my HashSet being serialized incorrectly in ORMLite? It appears to be serialized with the wrong size

I am saving a field in my app as a HashSet<String>, defined as such: @DatabaseField(dataType = DataType.SERIALIZABLE) private HashSet<String> allUsers; Some devices are occasionally ...
user23368169's user avatar
0 votes
1 answer
82 views

Rust ownership for pushing to a vector whose members are referenced

TL;DR: I want a vector of immutable elements that allows for short-lived immutable references to its members, while being able to push to it. I'm making a crate for exact arithmetic to be used as drop-...
Fee's user avatar
  • 736
0 votes
3 answers
105 views

Problem with altering property's value of an object that is inside a HashSet in JAVA [duplicate]

I'm studying java and facing a really weird problem, i think it's easier to explain this along with my code So this is my class: class Node { private int val; public Node(int val) { ...
JakeQ's user avatar
  • 19
2 votes
1 answer
474 views

Efficient way to check if a ReadOnlyMemory<char> contains in a Hashset in C#

I've been looking for some efficient and precise way to check if a ReadOnlyMemory<char> in C# contains in a Hashset of ReadOnlyMemory or any other collection. I saw some suggestions to convert ...
edwp's user avatar
  • 61
0 votes
1 answer
252 views

Difference between a HashSet in C# and HashSet in Java. Any alternatives

I came across this strange behaviour in C# vs Java. The HashSet in Java seems to compare the contents in an object and reject duplicates or gives out a boolean value for when it is checked for ...
Vishal A's user avatar
  • 175
2 votes
0 answers
66 views

CSVHelper doesn't store HashSet fields

I'm working on a software project where the program has a data storage and a UI that lets you manipulate this data. I use multiple data types, some of which contain HashSets. I don't do anything ...
Anthony Spendlove's user avatar
0 votes
1 answer
136 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, ...
boreddad420's user avatar
0 votes
1 answer
69 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[...
user1010101's user avatar
  • 1,658
1 vote
1 answer
56 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....
zam_22's user avatar
  • 21
-1 votes
2 answers
85 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 ...
ACP's user avatar
  • 1
0 votes
2 answers
468 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 ...
saeedasack's user avatar
0 votes
1 answer
250 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, ...
Della's user avatar
  • 1,602
-1 votes
2 answers
122 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 ...
Tariq's user avatar
  • 36
0 votes
0 answers
79 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 ...
Lisa's user avatar
  • 283
0 votes
1 answer
67 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: ...
Alex's user avatar
  • 39
1 vote
1 answer
57 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 ...
Hugh Self Taught's user avatar
-1 votes
1 answer
71 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 ...
Rook's user avatar
  • 9
2 votes
1 answer
125 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) *...
Frozen_Blood's user avatar
1 vote
0 answers
49 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 ...
Manatee Pink's user avatar
1 vote
0 answers
21 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 ...
Gordon Royle's user avatar
0 votes
2 answers
111 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....
olzh13's user avatar
  • 3
0 votes
1 answer
82 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 ...
Ilgar Hidayatov's user avatar
0 votes
0 answers
74 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. ...
Joshtray's user avatar
0 votes
0 answers
100 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->...
chrisg's user avatar
  • 200
3 votes
1 answer
107 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. -&...
codeDog's user avatar
  • 53
3 votes
3 answers
564 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 ...
maestroviktorin's user avatar
0 votes
1 answer
167 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] ...
Pavan kalyan's user avatar
2 votes
1 answer
269 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<...
Amessihel's user avatar
  • 6,314

1
2 3 4 5
46