Git Product home page Git Product logo

skiplist's Introduction

skiplist

When skiplist meets list head, something interesting might happen...Code less than z_set in Redis.

skiplist's People

Contributors

begeekmyfriend avatar guotie avatar newmsz 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

skiplist's Issues

random_level() 随机算法为什么要这样写?

static int random_level(void)
{
        int level = 1;
        const double p = 0.25;
        while ((random() & 0xffff) < 0xffff * p) {
                level++;
        }
        return level > MAX_LEVEL ? MAX_LEVEL : level;
}

这种随机算法的用意是?虽然比纯粹 { return random() % MAX_LEVEL + 1; } 好,但不知道为什么

wrong header file include

in order to use gettimeofday, you should include

<sys/time.h>

instead of

<time.h> which must be included when you want to use timespec which is another tool for timing

timespec is highly recommended for you to get an accurate timing result

Maybe there is something wrong with skiplist_search_by_rank()

I srand six numbers, This is result of skiplist_search_by_key(), it is correct:

Now search each node by key...
key:0x0000047e value:0x0000047e
key rank:1
key:0x000078c0 value:0x000078c0
key rank:6
key:0x00007477 value:0x00007477
key rank:5
key:0x00002dec value:0x00002dec
key rank:3
key:0x0000381f value:0x0000381f
key rank:4
key:0x00001355 value:0x00001355
key rank:2 

But skiplist_search_by_rank() seems not right. Maybe I will check code later.

Now search each node by rank...
rank:1 value:0x00002dec
rank:2 value:0x00001355
rank:3 value:0x00002dec
rank:4 value:0x00007477
rank:5 value:0x00007477
rank:6 value:0x000078c0

OS: windows10 x86

Seems bug on remove

Hi,

struct skiplist *list = skiplist_new();
skiplist_insert(list, 5, 10);
skiplist_insert(list, 7, 10);
skiplist_dump(list);

skiplist_remove(list, 5);
skiplist_dump(list);

The above code produces

Total 2 nodes: 
level:2 key:0x00000007 value:0x0000000a
level:1 key:0x00000005 value:0x0000000a
level:1 key:0x00000007 value:0x0000000a

Total 2 nodes: 
level:2 key:0x00000007 value:0x0000000a
level:1 key:0x00000005 value:0x0000000a
level:1 key:0x00000007 value:0x0000000a

Seems 5 is not removed from the list. Would you be able to check it out?

need use static_cast to be more compatible

node = malloc(sizeof(*node) + level * sizeof(struct sk_link));

the right hand returned is void *. many compliers may give you an error that void * can not be assigned to a variable of type skipnode*. so, please use this instead:

node = (struct skipnode *)malloc(sizeof(*node) + level * sizeof(struct sk_link));

likewise, you should

list = (struct skiplist *)malloc(sizeof(*list));

Maybe "remove_in_rank" has bug

struct skiplist *list = skiplist_new();
skiplist_insert(list, 1, 1);
skiplist_insert(list, 2, 2);
skiplist_insert(list, 3, 3);
remove_in_rank(list,1,1);
//list->count becomes 0.

Things seems went well like this:

struct skiplist *list = skiplist_new();
skiplist_insert(list, 3, 1);
skiplist_insert(list, 2, 2);
skiplist_insert(list, 1, 3);
remove_in_rank(list,1,1);
//list->count becomes 2.

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.