GithubHelp home page GithubHelp logo

fbuihuu / libtree Goto Github PK

View Code? Open in Web Editor NEW
165.0 165.0 46.0 193 KB

A library which implements a couple of famous binary search trees.

License: GNU Lesser General Public License v2.1

C 100.00%

libtree's People

Contributors

fbuihuu avatar rmanfredi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libtree's Issues

no working sample code

Hello,

I tried to run basic robustness test on libtree inserting 1k random keys comparing the order in a list of these numbers and the tree.

Unfortunately, the compare fails.

Maybe there is some off-by-one error somewhere and I am comparing uninitialized value or there is some issue with my understanding of the walk function in libtree.

Anyway, here is the code I tried git://gist.github.com/2045182.git

Note that I get assert on 5th element for which I have visually inspected my list implementation to produce seemingly correct order with this number sequence.

inserting 1536452766 2219981191 2013842191 206515713 3973769363 breaks bstree and splay tree

<- 1536452766
1536452766 <- 2219981191
1536452766 2219981191 <- 2013842191
1536452766 2013842191 2219981191 <- 206515713
206515713 1536452766 2013842191 2219981191 <- 3973769363
206515713 1536452766 2013842191 2219981191 3973769363
bs tree: item 0 (3973769363) != 206515713
inserted items:
1536452766 2219981191 2013842191 206515713 3973769363
Aborted

<- 1536452766
1536452766 <- 2219981191
1536452766 2219981191 <- 2013842191
1536452766 2013842191 2219981191 <- 206515713
206515713 1536452766 2013842191 2219981191 <- 3973769363
206515713 1536452766 2013842191 2219981191 3973769363
splay tree: item 0 (3973769363) != 206515713
inserted items:
1536452766 2219981191 2013842191 206515713 3973769363

The sequence for avl and rb tree is longer but again the last inserted item appears first:

1536452766 2219981191 2013842191 206515713 3973769363 2195571548 1470591614 99517740 3346335896 1968000334 2824163306 825862710 593949289 3087228942 9464287 3502443898 1825977738 4200665288

<- 1536452766
1536452766 <- 2219981191
1536452766 2219981191 <- 2013842191
1536452766 2013842191 2219981191 <- 206515713
206515713 1536452766 2013842191 2219981191 <- 3973769363
206515713 1536452766 2013842191 2219981191 3973769363 <- 2195571548
206515713 1536452766 2013842191 2195571548 2219981191 3973769363 <- 1470591614
206515713 1470591614 1536452766 2013842191 2195571548 2219981191 3973769363 <- 99517740
99517740 206515713 1470591614 1536452766 2013842191 2195571548 2219981191 3973769363 <- 3346335896
99517740 206515713 1470591614 1536452766 2013842191 2195571548 2219981191 3346335896 3973769363 <- 1968000334
99517740 206515713 1470591614 1536452766 1968000334 2013842191 2195571548 2219981191 3346335896 3973769363 <- 2824163306
99517740 206515713 1470591614 1536452766 1968000334 2013842191 2195571548 2219981191 2824163306 3346335896 3973769363 <- 825862710
99517740 206515713 825862710 1470591614 1536452766 1968000334 2013842191 2195571548 2219981191 2824163306 3346335896 3973769363 <- 593949289
99517740 206515713 593949289 825862710 1470591614 1536452766 1968000334 2013842191 2195571548 2219981191 2824163306 3346335896 3973769363 <- 3087228942
99517740 206515713 593949289 825862710 1470591614 1536452766 1968000334 2013842191 2195571548 2219981191 2824163306 3087228942 3346335896 3973769363 <- 9464287
9464287 99517740 206515713 593949289 825862710 1470591614 1536452766 1968000334 2013842191 2195571548 2219981191 2824163306 3087228942 3346335896 3973769363 <- 3502443898
9464287 99517740 206515713 593949289 825862710 1470591614 1536452766 1968000334 2013842191 2195571548 2219981191 2824163306 3087228942 3346335896 3502443898 3973769363 <- 1825977738
9464287 99517740 206515713 593949289 825862710 1470591614 1536452766 1825977738 1968000334 2013842191 2195571548 2219981191 2824163306 3087228942 3346335896 3502443898 3973769363 <- 4200665288
9464287 99517740 206515713 593949289 825862710 1470591614 1536452766 1825977738 1968000334 2013842191 2195571548 2219981191 2824163306 3087228942 3346335896 3502443898 3973769363 4200665288
avl tree: item 0 (4200665288) != 9464287
inserted items:
1536452766 2219981191 2013842191 206515713 3973769363 2195571548 1470591614 99517740 3346335896 1968000334 2824163306 825862710 593949289 3087228942 9464287 3502443898 1825977738 4200665288
Aborted

The implementation of bstree_replace() may incorrect

It should maintain "thread" pointers by updating them to point to the new node as well.
For instance:

set_next(new, get_prev(old)); // NOTE: it just telling the point, not necessary to be correct

In my test program, an infinite lookup loop comes up easily with random datasets and with using bstree_replace(). But everything was fine without bstree_replace().

license problematic

COPYING says LGPL 2.1, source files say Library general public license 2 (a license that does not exist, see http://www.gnu.org/licenses/old-licenses/old-licenses.html#LGPL). This is a problem

Do you mean to license under LGPL 2.1+, if so, change the headers of your source files to the fallowing:

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.