2015-06-19 10:27:46 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: Skiplist implementation for the ReactOS Project
|
2017-09-29 17:18:19 +00:00
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
2015-06-19 10:27:46 +00:00
|
|
|
* PURPOSE: Interfaces for the Skiplist
|
2017-09-29 17:18:19 +00:00
|
|
|
* COPYRIGHT: Copyright 2015 Colin Finck (colin@reactos.org)
|
2015-06-19 10:27:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _REACTOS_SKIPLIST_H
|
|
|
|
#define _REACTOS_SKIPLIST_H
|
|
|
|
|
2015-09-04 14:03:00 +00:00
|
|
|
// Define SKIPLIST_LEVELS to a value between 1 and 31 before including this header.
|
2015-06-19 10:27:46 +00:00
|
|
|
// This specifies the maximum number of levels you want your Skiplist to have.
|
|
|
|
// A value of X is recommended for handling up to 2^X elements.
|
|
|
|
#ifndef SKIPLIST_LEVELS
|
2015-09-04 14:03:00 +00:00
|
|
|
#error Please define SKIPLIST_LEVELS to a value between 1 and 31.
|
2015-06-19 10:27:46 +00:00
|
|
|
#endif
|
|
|
|
|
2015-06-19 12:33:45 +00:00
|
|
|
C_ASSERT(SKIPLIST_LEVELS >= 1);
|
2015-09-04 14:03:00 +00:00
|
|
|
C_ASSERT(SKIPLIST_LEVELS <= 31);
|
2015-06-19 12:33:45 +00:00
|
|
|
|
2015-06-19 10:27:46 +00:00
|
|
|
// Function pointer definitions
|
|
|
|
typedef PVOID (WINAPI *PSKIPLIST_ALLOCATE_ROUTINE)(DWORD);
|
|
|
|
typedef int (WINAPI *PSKIPLIST_COMPARE_ROUTINE)(PVOID, PVOID);
|
|
|
|
typedef void (WINAPI *PSKIPLIST_FREE_ROUTINE)(PVOID);
|
|
|
|
|
|
|
|
// Structure definitions
|
|
|
|
typedef struct _SKIPLIST_NODE
|
|
|
|
{
|
|
|
|
DWORD Distance[SKIPLIST_LEVELS];
|
|
|
|
struct _SKIPLIST_NODE* Next[SKIPLIST_LEVELS];
|
|
|
|
PVOID Element;
|
|
|
|
}
|
|
|
|
SKIPLIST_NODE, *PSKIPLIST_NODE;
|
|
|
|
|
|
|
|
typedef struct _SKIPLIST
|
|
|
|
{
|
|
|
|
SKIPLIST_NODE Head;
|
|
|
|
CHAR MaximumLevel;
|
|
|
|
DWORD NodeCount;
|
|
|
|
PSKIPLIST_ALLOCATE_ROUTINE AllocateRoutine;
|
|
|
|
PSKIPLIST_COMPARE_ROUTINE CompareRoutine;
|
|
|
|
PSKIPLIST_FREE_ROUTINE FreeRoutine;
|
|
|
|
}
|
|
|
|
SKIPLIST, *PSKIPLIST;
|
|
|
|
|
|
|
|
// Function prototypes
|
|
|
|
void InitializeSkiplist(PSKIPLIST Skiplist, PSKIPLIST_ALLOCATE_ROUTINE AllocateRoutine, PSKIPLIST_COMPARE_ROUTINE CompareRoutine, PSKIPLIST_FREE_ROUTINE FreeRoutine);
|
|
|
|
BOOL InsertElementSkiplist(PSKIPLIST Skiplist, PVOID Element);
|
|
|
|
BOOL InsertTailElementSkiplist(PSKIPLIST Skiplist, PVOID Element);
|
|
|
|
PVOID DeleteElementSkiplist(PSKIPLIST Skiplist, PVOID Element);
|
|
|
|
PVOID LookupElementSkiplist(PSKIPLIST Skiplist, PVOID Element, PDWORD ElementIndex);
|
2015-06-25 13:12:01 +00:00
|
|
|
PSKIPLIST_NODE LookupNodeByIndexSkiplist(PSKIPLIST Skiplist, DWORD ElementIndex);
|
2015-06-19 10:27:46 +00:00
|
|
|
|
|
|
|
#endif
|