File tree Expand file tree Collapse file tree 3 files changed +9
-6
lines changed Expand file tree Collapse file tree 3 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -9,12 +9,12 @@ const Tree = require('../../trees/red-black-tree'); // fast insertion
99 *
1010 * Implementing a Map with a tree, TreeMap,
1111 * has a couple of advantages over a HashMap:
12- * • Keys are always sorted.
13- * • Statistical data can be easily obtained like median,
12+ * • Keys are always sorted.
13+ * • Statistical data can be easily obtained like median,
1414 * highest, lowest key.
15- * • Collisions are not a concern so in the worst case is
15+ * • Collisions are not a concern so in the worst case is
1616 * still O(log n).
17- * • Trees are more space efficient and doesn’t need to
17+ * • Trees are more space efficient and doesn’t need to
1818 * allocate memory beforehand (e.g. HashMap’s initial capacity)
1919 * nor you have to rehash when is getting full.
2020 *
Original file line number Diff line number Diff line change @@ -17,14 +17,16 @@ class HashMapSet {
1717
1818 /**
1919 * Add a new value (duplicates will be added only once)
20+ * Avg. Runtime: O(1)
2021 * @param {any } value
2122 */
2223 add ( value ) {
2324 this . hashMap . set ( value ) ;
2425 }
2526
2627 /**
27- * check if value is already on the set
28+ * Check if value is already on the set
29+ * Avg. Runtime: O(1)
2830 * @param {any } value
2931 */
3032 has ( value ) {
@@ -40,6 +42,7 @@ class HashMapSet {
4042
4143 /**
4244 * Delete a value from the set
45+ * Avg. Runtime: O(1)
4346 * @param {any } value
4447 */
4548 delete ( value ) {
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ class TreeSet {
4040 * @returns {boolean } true if exists or false otherwise
4141 */
4242 has ( value ) {
43- return ! ! this . tree . get ( value ) ;
43+ return this . tree . has ( value ) ;
4444 }
4545
4646 /**
You can’t perform that action at this time.
0 commit comments