Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

braidjs bug? #29

Open
iacore opened this issue Sep 29, 2024 · 1 comment
Open

braidjs bug? #29

iacore opened this issue Sep 29, 2024 · 1 comment

Comments

@iacore
Copy link

iacore commented Sep 29, 2024

The output doesn't match what the readme says.

> var sequence = require('./antimatter').sequence_crdt
undefined
> var root_node = sequence.create_node('alice1', 'hello')
undefined
> console.log(sequence.generate_braid(root_node, 'alice1', x => false)) // outputs [0, 0, "hello"]
[]
undefined
@dglittle
Copy link
Collaborator

dglittle commented Sep 30, 2024

Thanks! This is definitely an issue. Part of the issue is with the readme. The readme claims that sequence.generate_braid will generate [0, 0, 'hello']. There are two problems with this. First, it should generate an array within an array: [[0, 0, 'hello']]. Second, as it stands, it returns []; this can be fixed with this new code:

var sequence = require('./antimatter').sequence_crdt

// modified line:
var root_node = sequence.create_node('root', '')

// new line:
sequence.add_version(root_node, 'alice1', [[0, 0, 'hello']], null, x => true)

console.log(sequence.generate_braid(root_node, 'alice1', x => false))

This code adds a line with add_version. This creates a tree with two nodes: "root" and "alice1", whereas the original readme code creates a tree with just one node "alice1".

This issue is that generate_braid treats the root node in a special way, and in particular, never includes the root node text in the returned splices.

I say "part of the issue" is with the readme because another part may be with this decision to treat the root node in a special way.. I'll need to ponder that a bit. If it makes sense to not treat the root node in a special way, then the readme can stay the same, except for the array-within-an-array [[...]] bit which I have just fixed.

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

No branches or pull requests

2 participants