Skip to content

Commit 87416da

Browse files
README.md: added sections on usage.
1 parent 181823d commit 87416da

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ All objects (except primitives) used as keys must implement a <code>hashCode</co
99
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>
1010
An example of usage can be found [here](examples/HashMapExample.html).
1111

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.
14+
15+
```
16+
<script src="https://cdn.jsdelivr.net/gh/LieutenantPeacock/[email protected]/src/HashMap.js" integrity="sha384-AD+fe06BloScT8iK5vgKw2FW3imLYjVLP6P9OS+zKpI8vIaNrBTKnQ4TCa4poj2F" crossorigin="anonymous"></script>
17+
```
18+
1219
### Constructor
1320

1421
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
4148
<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>
4249
</tr>
4350
<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>
4552
</tr>
4653
<tr>
4754
<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
6875
[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>
6976
Note that <code>HashSet</code> instances are iterable, so <code>[...myHashSet]</code> will return an array containing the elements in the <code>HashSet</code>.
7077

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.
80+
81+
```
82+
<script src="https://cdn.jsdelivr.net/gh/LieutenantPeacock/[email protected]/src/HashMap.js" integrity="sha384-AD+fe06BloScT8iK5vgKw2FW3imLYjVLP6P9OS+zKpI8vIaNrBTKnQ4TCa4poj2F" crossorigin="anonymous"></script>
83+
<script src="https://cdn.jsdelivr.net/gh/LieutenantPeacock/[email protected]/src/HashSet.js" integrity="sha384-eEGZyLlAVNsmA+/PWbSLgZR1wO9z2AWkHyVtLzr1vCenlCZ2wb9wLxNKY7Ib5lK5" crossorigin="anonymous"></script>
84+
```
85+
7186
### Constructor
7287
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>.
7388

@@ -110,6 +125,13 @@ const mySet2 = new HashSet([1, 2, 3]); // creates a HashSet containing the eleme
110125
[ArrayList.js](src/ArrayList.js) implements an dynamically-sized list with a <code>hashCode</code> and <code>equals</code> method. <br>
111126
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).
112127

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.
130+
131+
```
132+
<script src="https://cdn.jsdelivr.net/gh/LieutenantPeacock/[email protected]/src/ArrayList.js" integrity="sha384-Uz+oGp/Q3Lfeq6ESB4bvbOAHw0hF1RjSBPHQqjpikrVrFjF6SDx6JMV9rI3mBBFr" crossorigin="anonymous"></script>
133+
```
134+
113135
### Constructor
114136
The constructor accepts an optional iterable object to use to fill the list initially. If not specified, an empty <code>ArrayList</code> is constructed.
115137

@@ -175,6 +197,13 @@ const myList2 = new ArrayList([1, 2, 3]); // creates an ArrayList containing the
175197
[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
176198
in a <code>HashSet</code>.<br>
177199

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.
202+
203+
```
204+
<script src="https://cdn.jsdelivr.net/gh/LieutenantPeacock/[email protected]/src/HashedObject.js" integrity="sha384-RBqyEB5bCB2ci4e3ZKiBp4W87K7LYay1qXMFO/9cUq7TndRlQKLSZ4/iFN1bMbRl" crossorigin="anonymous"></script>
205+
```
206+
178207
### Constructor
179208
The constructor takes the object to wrap, the hash function, and the equals function as arguments. <br>
180209
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

Comments
 (0)