Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set type: size call does not return the correct size and returns either 1 or 0 #130

Open
janand1977 opened this issue Oct 2, 2024 · 1 comment

Comments

@janand1977
Copy link

import { Heap,Set, Dictionary } from 'typescript-collections';
import * as Collections from 'typescript-collections';

class Emp {
constructor(public sal: number, public id: string) {}

valueOf() {
return this.sal;
}

toString() {
Collections.util.makeString(this);
}
}

const useSet =() => {

let objA = new Emp(109, 'adn');
let objB = new Emp(110, 'adn');
let objC = new Emp(106, 'adn');
let objD = new Emp(106, 'adn');

let mySet:Set = new Set();
mySet.add(objA);
mySet.add(objB);
mySet.add(objC);
mySet.add(objD);

console.log(mySet.contains(objA));
console.log(mySet.size());

// if (mySet.contains(objD)){ // checking for value equality
// console.log('found');
// }

// size is returning wrong value
mySet.remove(objA);
mySet.remove(objB);
mySet.remove(objC);
mySet.remove(objD);

console.log(mySet.size());
}

@janand1977 janand1977 changed the title Set function size call does not return the correct size and returns either 1 or 0 Set type: size call does not return the correct size and returns either 1 or 0 Oct 2, 2024
@baloian
Copy link

baloian commented Dec 8, 2024

@janand1977 I implemented a new version of this lib with modern approach. Feel free to use it. See: https://github.com/baloian/typescript-ds-lib/tree/master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants