You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-1Lines changed: 30 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,13 @@ All objects (except primitives) used as keys must implement a <code>hashCode</co
9
9
Note that <code>HashMap</code> instances are iterable, so <code>[...myHashMap]</code> will return an array of arrays, where each inner array consists of the key and value for a mapping (in that order). <br>
10
10
An example of usage can be found [here](examples/HashMapExample.html).
11
11
12
+
### Usage
13
+
Include the script before code that uses <code>HashMap</code>. The script can be loaded via CDN or a local downloaded copy.
The constructor accepts an optional <code>HashMap</code>, which will copy the contents. Alternately, it will create an empty <code>HashMap</code>.
@@ -41,7 +48,7 @@ const myMap2 = new HashMap(myMap); // create HashMap from other HashMap
41
48
<td><code>containsValue(value)</code></td><td>Returns <code>true</code> if there is at least one key mapped to the given <code>value</code>.</td>
42
49
</tr>
43
50
<tr>
44
-
<td><code>clear()<code></td><td>Removes all mappings in the <code>HashMap</code>.</td>
51
+
<td><code>clear()</code></td><td>Removes all mappings in the <code>HashMap</code>.</td>
45
52
</tr>
46
53
<tr>
47
54
<td><code>remove(key)</code></td><td>Removes the mapping for the given <code>key</code> and returns its value.</td>
@@ -68,6 +75,14 @@ const myMap2 = new HashMap(myMap); // create HashMap from other HashMap
68
75
[HashSet.js](src/HashSet.js) implements an unordered collection with unique elements. Similar to <code>HashMap</code>, each element (except primitives) stored in a <code>HashSet</code> must implement a <code>hashCode</code> and <code>equals</code> method. To use <code>HashSet</code>, <code>HashMap</code> must be included first. <br>
69
76
Note that <code>HashSet</code> instances are iterable, so <code>[...myHashSet]</code> will return an array containing the elements in the <code>HashSet</code>.
70
77
78
+
### Usage
79
+
Include HashMap.js and HashSet.js before code that uses <code>HashSet</code>. The scripts can be loaded via CDN or local downloaded copies.
The constructor accepts an optional iterable object, all elements of which will be initially added to the <code>HashSet</code>. If the first parameter is not provided, it constructs an empty <code>HashSet</code>.
73
88
@@ -110,6 +125,13 @@ const mySet2 = new HashSet([1, 2, 3]); // creates a HashSet containing the eleme
110
125
[ArrayList.js](src/ArrayList.js) implements an dynamically-sized list with a <code>hashCode</code> and <code>equals</code> method. <br>
111
126
Note that <code>ArrayList</code> instances are iterable, so <code>[...myArrayList]</code> will return an array containing the elements in the <code>ArrayList</code> (in order).
112
127
128
+
### Usage
129
+
Include the script before code that uses <code>ArrayList</code>. The script can be loaded via CDN or a local downloaded copy.
The constructor accepts an optional iterable object to use to fill the list initially. If not specified, an empty <code>ArrayList</code> is constructed.
115
137
@@ -175,6 +197,13 @@ const myList2 = new ArrayList([1, 2, 3]); // creates an ArrayList containing the
175
197
[HashedObject.js](src/HashedObject.js) provides a wrapper for an object that allows specifying an <code>equals</code> and <code>hashCode</code> function. This wrapped object can then be used as a key in a <code>HashMap</code> or stored
176
198
in a <code>HashSet</code>.<br>
177
199
200
+
### Usage
201
+
Include the script before code that uses <code>HashedObject</code>. The script can be loaded via CDN or a local downloaded copy.
The constructor takes the object to wrap, the hash function, and the equals function as arguments. <br>
180
209
The <code>equals</code> function must take two objects as parameters and return a boolean indicating whether they are equal. If not equals function is specified, the default is strict equality comparison.<br>
0 commit comments