Skip to content

Conversation

@utanapishtim
Copy link
Contributor

Adds the ability to compare and swap on a key in a Hyperbee. In particular, if we have:

  • a hyperbee: bee
  • a key: key
  • a value we want to set: value
  • the current value in bee at key: current
  • a value we want to compare against current: test
  • and a predicate that will compare test and the current value in bee at key: compare

Then Hyperbee.cas() compares current and test through compare and:

if true: sets key at value in bee and returns current
if false: return null

The default compare function encodes test through bee.valueEncoding and compares against the encoded value of current.

@utanapishtim
Copy link
Contributor Author

@mafintosh do I need to grab the lock for this like in _put?

@mafintosh mafintosh merged commit d02b8bc into holepunchto:master May 26, 2022
@mafintosh
Copy link
Contributor

1.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants