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

feat: B-Tree added #2677

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

feat: B-Tree added #2677

wants to merge 11 commits into from

Conversation

gfant
Copy link
Contributor

@gfant gfant commented Aug 11, 2024

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

Added B-Tree structure so data can be mantained ordered without using too much operations.

@gfant gfant requested review from a team as code owners August 11, 2024 20:09
@gfant gfant requested review from ajnavarro and thehowl and removed request for a team August 11, 2024 20:09
@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Aug 11, 2024
Copy link

codecov bot commented Aug 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.12%. Comparing base (f6bd2d3) to head (618630c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2677      +/-   ##
==========================================
+ Coverage   63.08%   63.12%   +0.04%     
==========================================
  Files         563      563              
  Lines       79254    79362     +108     
==========================================
+ Hits        49998    50099     +101     
- Misses      25896    25905       +9     
+ Partials     3360     3358       -2     
Flag Coverage Δ
contribs/gnodev 60.62% <ø> (ø)
contribs/gnofaucet 14.82% <ø> (ø)
gno.land 67.56% <ø> (ø)
gnovm 67.25% <ø> (ø)
misc/genstd 79.72% <ø> (ø)
misc/logos 19.45% <ø> (ø)
tm2 62.29% <ø> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gfant gfant changed the title B-Tree added [feat] B-Tree added Aug 22, 2024
@gfant gfant changed the title [feat] B-Tree added Feat: B-Tree added Aug 22, 2024
@gfant gfant changed the title Feat: B-Tree added feat: B-Tree added Aug 22, 2024
@gfant
Copy link
Contributor Author

gfant commented Aug 23, 2024

Is there something I could do to help with the merging of this PR, @thehowl , @ajnavarro @leohhhn ? (Thank you in advance!)

examples/gno.land/p/demo/btree/btree.gno Outdated Show resolved Hide resolved
examples/gno.land/p/demo/btree/btree.gno Outdated Show resolved Hide resolved
@gfant
Copy link
Contributor Author

gfant commented Aug 30, 2024

Updated test to adapt to new error message.

@Kouteki Kouteki added review/triage-pending PRs opened by external contributors that are waiting for the 1st review and removed review/triage-pending PRs opened by external contributors that are waiting for the 1st review labels Oct 3, 2024
Copy link
Contributor

@wyhaines wyhaines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bug in the implementation, likely in the delete/fill/merge handling.

If you insert a large number of entries into the tree, and then start deleting them, you will run into a situation where you get a .: test pkg: panic: slice index out of bounds: 3 (len=3) type error.

This is likely related to the recursion near the bottom of the delete function, but there is interplay with the fill/merge functionality. Something is just not quite right, and while it's possible to fix the slice out of bounds, when one does that, after doing a number of deletes, one starts to get keys that are no longer reachable.

This is an incomplete test, but it serves to illustrate the problem:

func TestStress(t *testing.T) {
  tree, _ := NewBTree(4)

  for j := 0; j < 1000; j++ {
    tree.Insert(Content{Key: j, Value: j})
  }

  if tree.GetSize() != 1000 {
    t.Errorf("Expected size of 1000; got %d\n", tree.GetSize())
  }

  for j := 0; j < 1000; j++ {
    found, err := tree.Search(j)
    if found.Key != j {
      t.Errorf("Search for %d expected to find %d, but got %d\n", j, j, found.Key)
    }
  }

  for j := 0; j < 1000; j += 2 {
    tree.Delete(j)
  }
}

@wyhaines
Copy link
Contributor

This still breaks when subjected to the stress test above:

=== RUN   TestStress
.: test pkg: panic: slice index out of bounds: 3 (len=3)
stack:
goroutine 1 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:26 +0x5e
main.runTestFiles.func1()
        /media/wyhaines/home/wyhaines/ghq/github.com/wyhaines/gno/gnovm/cmd/gno/test.go:439 +0x58
panic({0xd99c20?, 0xc004b18c90?})
        /usr/local/go/src/runtime/panic.go:785 +0x132
github.com/gnolang/gno/gnovm/pkg/gnolang.(*SliceValue).GetPointerAtIndexInt2(0xc00ba13560, {0x11e4e10?, 0xc0000cce60?}, 0xc0003a81e0?, {0x11d2f10?, 0xc00057e1e0?})
        /media/wyhaines/home/wyhaines/ghq/github.com/wyhaines/gno/gnovm/pkg/gnolang/values.go:442 +0x1be
github.com/gnolang/gno/gnovm/pkg/gnolang.(*TypedValue).GetPointerAtIndex(0xc0003a81b8, 0xc009ceb201?, {0x11e4e10, 0xc0000cce60}, 0xc0003a81e0)
        /media/wyhaines/home/wyhaines/ghq/github.com/wyhaines/gno/gnovm/pkg/gnolang/values.go:1997 +0xa45
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).PopAsPointer(0xc00cc39550?, {0x11d9708?, 0xc00053a1e0?})
        /media/wyhaines/home/wyhaines/ghq/github.com/wyhaines/gno/gnovm/pkg/gnolang/machine.go:2130 +0x193
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).doOpAssign(0xc0003a2488)
        /media/wyhaines/home/wyhaines/ghq/github.com/wyhaines/gno/gnovm/pkg/gnolang/op_assign.go:35 +0x247
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).Run(0xc0003a2488)
        /media/wyhaines/home/wyhaines/ghq/github.com/wyhaines/gno/gnovm/pkg/gnolang/machine.go:1537 +0xd73
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).Eval(0xc0003a2488, {0x11d94e8, 0xc00cb647e0})
        /media/wyhaines/home/wyhaines/ghq/github.com/wyhaines/gno/gnovm/pkg/gnolang/machine.go:884 +0x63c
main.runTestFiles(0xc0003a2488, 0xc000011698, {0xc00047cd40, 0x6}, 0x1, 0x0, 0x0, {0x0, 0x0}, {0x11dbe80, ...})
        /media/wyhaines/home/wyhaines/ghq/github.com/wyhaines/gno/gnovm/cmd/gno/test.go:468 +0x3a5
main.gnoTestPkg({0x11baba0, 0x1}, {0xc0004822d0?, 0x1, 0x8?}, {0x0, 0x0, 0x0?}, 0xc000478780, {0x11dbe80, ...})
        /media/wyhaines/home/wyhaines/ghq/github.com/wyhaines/gno/gnovm/cmd/gno/test.go:309 +0x12b0
main.execTest(0xc000478780, {0xc0004822b0?, 0x1?, 0x1?}, {0x11dbe80, 0xc0003cb720})
        /media/wyhaines/home/wyhaines/ghq/github.com/wyhaines/gno/gnovm/cmd/gno/test.go:207 +0x428
main.newTestCmd.func1({0x0?, 0xc000034130?}, {0xc0004822b0?, 0xc00047af00?, 0x0?})
        /media/wyhaines/home/wyhaines/ghq/github.com/wyhaines/gno/gnovm/cmd/gno/test.go:101 +0x30
github.com/gnolang/gno/tm2/pkg/commands.(*Command).Run(0xc000307ea8?, {0x11cdc60?, 0x18bcce0?})
        /media/wyhaines/home/wyhaines/ghq/github.com/wyhaines/gno/tm2/pkg/commands/command.go:255 +0x18e
github.com/gnolang/gno/tm2/pkg/commands.(*Command).Run(0xc0003971e0?, {0x11cdc60?, 0x18bcce0?})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: In Progress
Status: In Review
Development

Successfully merging this pull request may close these issues.

4 participants