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: proposal.md
+17-11Lines changed: 17 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -210,7 +210,8 @@ Time complexity of operations:
210
210
- `addAll(index, elements)`, `removeAll(elements)`, `removeAll(predicate)` -O(NM), optimizable to O(N+M), where Mis the number of elements to be inserted/removed.
211
211
-Iterating elements -O(N).
212
212
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.
214
215
This allows to avoid path-copying and gives O(1) time complexity for these two operations.
215
216
216
217
Small persistent lists, with up to 32 elements, are backed by arrays of corresponding size.
@@ -234,21 +235,26 @@ Time complexity of operations:
234
235
- `putAll(map)` -O(M log<sub>32</sub>N), where Mis the number of elements added.
235
236
-Iterating `keys`, `values`, `entries` -O(N).
236
237
237
-
#### Default persistent ordered hash set
238
+
#### Default persistent ordered hash map
238
239
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.
240
242
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.
245
248
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.
247
253
248
-
#### Default persistent ordered hash map
254
+
#### Default persistent ordered hash set
249
255
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.
0 commit comments