Skip to content

Commit

Permalink
Explained ObjectStrorage in README + removed bench/ and old tests sin…
Browse files Browse the repository at this point in the history
…ce they don't work anymore
  • Loading branch information
thisredone committed Apr 10, 2020
1 parent 1438832 commit 193b5b8
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 1,105 deletions.
51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ item =

#### Results

`all()`, `search()` and `checkCollisions()` functions return a `GrowingArray` which implements an iterator. For maximum performance though you need to iterate manually:
`all()`, `search()` and `checkCollisions()` functions return a `GrowingArray` which implements an iterator.

```javascript
for(let item of tree.search([0, 0, 1, 1])) {
// do something
}
```

For maximum performance though you need to iterate manually:

```coffeescript
result = tree.search([0, 0, 1, 1])
Expand Down Expand Up @@ -77,6 +85,47 @@ for i in [0...currentLen] by 2
```



#### ObjectStorage

This is the underlying structure that holds `tree.nonStatic` objects as well as `tree.leafNodes`. The purpose of it is to be able to store objects that change a lot in an array without paying much of the GC and CPU cost but using more memory. By calling `storage.remove(item)` objects are marked as `_removed` which makes them ignored in further iteration.

Periodically calling `storage.maybeCondense(threshold)` or directly `storage.condense()`, for example if `storage.removalCount` is higher than some value, migrates the not `_removed` objects to an auxiliary array and swaps them afterwards. For `tree.nonStatic` objects a version of this process is integrated into `tree.checkCollisions()`. Since all are iterated anyway the cost of condensing is minimal.

###### API

```coffeescript
storage = new ObjectStorage(startingSize = 64)

storage.push(item)

item = storage.pop()

storage.clear()

# calls .condense() if .removalsCount > threshold
# by default threshold is the bigger of 50 or 10% of .currentLen
storaget.maybeCondense(threshold)

# get's rid of holes created by removing items
storage.condense()

# iteration with a iterator (in JS it's `in` instead of `from`)
for item from storage
# do stuff

# manual iteration
{ current, currentLen } = storage
for i in [0...currentLen]
item = current[i]
if not item._removed
# do stuff
```





Original readme below
------------

Expand Down
17 changes: 0 additions & 17 deletions bench/bulk.bench.js

This file was deleted.

34 changes: 0 additions & 34 deletions bench/bulksearch.bench.js

This file was deleted.

24 changes: 0 additions & 24 deletions bench/gendata.js

This file was deleted.

19 changes: 0 additions & 19 deletions bench/insert.bench.js

This file was deleted.

81 changes: 0 additions & 81 deletions bench/perf.js

This file was deleted.

36 changes: 0 additions & 36 deletions bench/search.bench.js

This file was deleted.

Loading

0 comments on commit 193b5b8

Please sign in to comment.