Skip to content

Commit

Permalink
Merge pull request #7 from beautifulinteractions/feature/insert-strat…
Browse files Browse the repository at this point in the history
…egies

Add support for different insert behaviors
  • Loading branch information
adamhooper authored Apr 2, 2020
2 parents 24e90aa + bb5b699 commit 504ff95
Show file tree
Hide file tree
Showing 26 changed files with 277 additions and 35 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ This is the argument we would pass to
var compareNumbers = function(a, b) { return a - b; };
var set = new SortedSet({ comparator: compareNumbers });

How to handle insert conflicts? We'll also add a `onInsertConflict` option that
provides users with a way to specify what to do in case an item is inserted
that matches another item already present within the set. Such behavior
**must** be specified as a function taking in the conflicting items and
returning a replacement item for the previously inserted one. The `SortedSet`
class ships with three implementations such behavior:

SortedSet.OnInsertConflictThrow // throws an error
SortedSet.OnInsertConflictReplace // keeps the new item
SortedSet.OnInsertConflictIgnore // keeps the previous item

Unless differently specified through the `onInsertConflict` option, the
`SortedSet` class will default to `SortedSet.OnInsertConflictThrow`:

var set = new SortedSet({
onInsertConflict: SortedSet.OnInsertConflictThrow
});
set.insert("foo");
set.insert("foo"); // this will throw an error

Finally, some algorithms ask for really fast replacement mechanisms. So let's
add a `setValue()` method to the iterator, which puts the onus on the user to
keep things ordered.
Expand Down
13 changes: 12 additions & 1 deletion dist/SortedSet.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions dist/SortedSet.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/SortedSet/AbstractBinaryTreeStrategy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions dist/SortedSet/AbstractBinaryTreeStrategy.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions dist/SortedSet/AbstractSortedSet.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions dist/SortedSet/AbstractSortedSet.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions dist/SortedSet/ArrayStrategy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions dist/SortedSet/ArrayStrategy.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/SortedSet/BinaryTreeIterator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 504ff95

Please sign in to comment.