Skip to content

Commit 3326c75

Browse files
Abduqodiri Qurbonzodailya-g
authored andcommitted
Rephrase persistent ordered hash map/set implementations description
1 parent 31f25cb commit 3326c75

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

proposal.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ Time complexity of operations:
210210
- `addAll(index, elements)`, `removeAll(elements)`, `removeAll(predicate)` - O(N M), optimizable to O(N+M), where M is the number of elements to be inserted/removed.
211211
- Iterating elements - O(N).
212212

213-
To optimize frequently used `add(element)` and `removeAt(size - 1)` operations rightmost leaf is referenced directly from the persistent list instance.
213+
To optimize frequently used `add(element)` and `removeAt(size - 1)` operations rightmost leaf
214+
is stored out of the trie structure and referenced directly from the persistent list instance.
214215
This allows to avoid path-copying and gives O(1) time complexity for these two operations.
215216

216217
Small persistent lists, with up to 32 elements, are backed by arrays of corresponding size.
@@ -234,21 +235,26 @@ Time complexity of operations:
234235
- `putAll(map)` - O(M log<sub>32</sub>N), where M is the number of elements added.
235236
- Iterating `keys`, `values`, `entries` - O(N).
236237

237-
#### Default persistent ordered hash set
238+
#### Default persistent ordered hash map
238239

239-
It's backed by the _persistent unordered hash map_, which maps every element in this set to the previous and next elements in insertion order.
240+
It's backed by the _persistent unordered hash map_, which maps every key in this map to a
241+
triple containing the corresponding value, the previous and the next keys in insertion order.
240242
241-
Every operation on this set turns into one or more operations on the backing map, e.g.:
242-
- `add(element)` turns into updating the next reference of the last element (new element becomes the next) and putting new entry with key equal to the specified element.
243-
- `remove(element)` turns into removing the entry with the key equal to the specified element and updating values for the next and previous elements.
244-
- `contains(element)` turns into `containsKey(element)`.
243+
Every operation on this map turns into one or more operations on the backing map, e.g.:
244+
- `put(key, value)` turns into updating the next of the last key (the new key becomes the next), and putting a new entry
245+
with the specified key and with value equal to a triple containing the specified value, the last key (as previous key) and null next key.
246+
- `remove(key)` turns into removing the entry with the specified key, and updating values for the next and previous keys.
247+
- `get(key)` gets delegated to the backing map.
245248
246-
Iterating elements in this set takes O(N log<sub>32</sub>N) time.
249+
Time complexity of all operations on this map, except iteration, is the same as in
250+
backing _persistent unordered hash map_,
251+
though with a bigger constant factor in case of modification operations.
252+
Iterating entries, keys, or values of this map takes O(N log<sub>32</sub>N) time.
247253
248-
#### Default persistent ordered hash map
254+
#### Default persistent ordered hash set
249255
250-
It is implemented the same way as the _persistent ordered hash set_,
251-
except that the backing map stores also value beside next and previous keys.
256+
It is implemented the same way as the _persistent ordered hash map_,
257+
except that the backing map maps every element to a pair containing the previous and the next elements.
252258
253259
#### Builders
254260

0 commit comments

Comments
 (0)