KYSDK_SKIPLIST_SEARCH(3)

NAME
kysdk_skiplist_search - 根据给定的key搜索data内容

SYNOPSIS
br

#include <skip_linklist.h>

  Functions

  kysdk_listdata kysdk_skiplist_search (kysdk_skiplist * list, int key)

根据给定的key搜索data内容

Parameters
    list 需要操作的链表
    key 键

Returns
    kysdk_listdata， 当搜索的key不存在时，data.num值为-1 typedef union _kysdk_listdata {
        void *ptr;
        int num;
    } kysdk_listdata;

Link with -lkydatastruct.

Detailed Description

接口的主要功能是根据给定的key搜索data内容

EXAMPLES
    #include <skip_linklist.h>
    #include <stdlib.h>
    #include <time.h>
    #include <stdio.h>
    #include <unistd.h>
    #define ARRAY_SIZE    20
    int array[ARRAY_SIZE];
    int del_flag[ARRAY_SIZE] = {0};
    void print_list(kysdk_skiplist *list)
    {
        for (int i = list->max_levels - 1; i >= 0; i --)
        {
            kysdk_skiplist_node *curnode = list->children[i];
            printf("Level[%d]: ", i);
            while (curnode)
            {
                printf("%d->", curnode->key);
                curnode = curnode->next[i];
            }
            printf("NULL);
        }
    }
    int test_list_delete(kysdk_skiplist *list)
    {
        for (int i = 0; i < ARRAY_SIZE; i ++)
        {
            if (random() % 2)
            {
                del_flag[i] = 1;
                kysdk_skiplist_delete(list, array[i]);
                printf("Deleted %d, array[i]);
            }
        }
        for (int i = 0; i < ARRAY_SIZE; i ++)
        {
            if (del_flag[i] && kysdk_skiplist_search(list, array[i]).num != -1)
            {
                printf("Skiplist delete test failed.);
                return -1;
            }
        }
        printf("Skiplist order test pass.);
        return 0;
    }
    int main()
    {
        kysdk_skiplist *list = kysdk_create_skiplist();
        kysdk_skiplist_setmaxlevels(list, 5);

        srand(time(NULL));
        for (int i = 0; i < ARRAY_SIZE; i ++)
        {
            array[i] = i;
            kysdk_skiplist_insert(list, i, (kysdk_listdata)i);
            printf("%d has been insert., i);
            sleep(1);
        }

        print_list(list);
        int res = test_list_delete(list);
        print_list(list);
        kysdk_destroy_skiplist(list);
        return res;
    }

CONFORMING TO
These functions are as per the withdrawn POSIX.1e draft specification. The following functions are Linux extensions: kysdk_create_skiplist(), kysdk_destroy_skiplist(), kysdk_skiplist_setmaxlevels(), kysdk_skiplist_insert() and kysdk_skiplist_delete().

SEE ALSO
kysdk_create_skiplist(3), kysdk_destroy_skiplist(3), kysdk_skiplist_setmaxlevels(3), kysdk_skiplist_insert(3) and kysdk_skiplist_delete(3).

Author

Generated automatically by Doxygen for skip_linklist.h from the source code.