Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 040a11b

Browse files
better docs
1 parent c644757 commit 040a11b

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

‎src/data-structures/sets/hash-set.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const HashMap = require('../maps/hash-maps/hashmap');
2+
23
/**
3-
* Set implemented with our HashMap to have sublinear times on all operations
4+
* Set implemented with our HashMap
5+
* Have an average of O(1) time on all operations
46
*/
57
class HashMapSet {
68
/**

‎src/data-structures/sets/tree-set.js‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// const Tree = require('../trees/avl-tree');
2-
const Tree = require('../trees/red-black-tree');
1+
// const Tree = require('../trees/avl-tree'); // faster lookups
2+
const Tree = require('../trees/red-black-tree');// faster insertion
33

44
/**
55
* TreeSet implements a Set (collection of unique values)
@@ -24,6 +24,7 @@ class TreeSet {
2424

2525
/**
2626
* Add a new value (duplicates will be added only once)
27+
* Runtime: O(log n)
2728
* @param {any} value
2829
*/
2930
add(value) {
@@ -33,37 +34,40 @@ class TreeSet {
3334
}
3435

3536
/**
36-
* check if value is already on the set
37+
* Check if value is already on the set
38+
* Runtime: O(log n)
3739
* @param {any} value
40+
* @returns {boolean} true if exists or false otherwise
3841
*/
3942
has(value) {
4043
return !!this.tree.get(value);
4144
}
4245

4346
/**
4447
* Delete a value from the set
48+
* Runtime: O(log n)
4549
* @param {any} value
4650
*/
4751
delete(value) {
4852
return this.tree.remove(value);
4953
}
5054

5155
/**
52-
* Get all the values on the Set
56+
* Default iterator for this set
5357
* @returns {iterator} values in ascending order
5458
*/
55-
* keys() {
59+
* [Symbol.iterator]() {
5660
for (const node of this.tree.inOrderTraversal()) {
5761
yield node.value;
5862
}
5963
}
6064

6165
/**
62-
* Default iterator for this set
66+
* Get all the values on the Set
6367
* @returns {iterator} values in ascending order
6468
*/
65-
* [Symbol.iterator]() {
66-
yield* this.keys();
69+
* keys() {
70+
yield* this;
6771
}
6872

6973
/**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /