mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 13:35:47 +00:00
Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers into modules, and delete rossubsys.
This commit is contained in:
parent
b94e2d8ca0
commit
c2c66aff7d
24198 changed files with 0 additions and 37285 deletions
98
sdk/lib/skiplist/skiplist_test.c
Normal file
98
sdk/lib/skiplist/skiplist_test.c
Normal file
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* PROJECT: Skiplist implementation for the ReactOS Project
|
||||
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
||||
* PURPOSE: A simple program for testing the Skiplist implementation
|
||||
* COPYRIGHT: Copyright 2015 Colin Finck (colin@reactos.org)
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include "skiplist.h"
|
||||
|
||||
void
|
||||
DumpSkiplist(PSKIPLIST Skiplist)
|
||||
{
|
||||
CHAR i;
|
||||
DWORD j;
|
||||
PSKIPLIST_NODE pNode;
|
||||
|
||||
printf("======= DUMPING SKIPLIST =======\n");
|
||||
|
||||
for (i = Skiplist->MaximumLevel + 1; --i >= 0;)
|
||||
{
|
||||
pNode = &Skiplist->Head;
|
||||
printf("H");
|
||||
|
||||
while (pNode->Next[i])
|
||||
{
|
||||
printf("-");
|
||||
|
||||
// By using the Distance array for painting the lines, we verify both the links and the distances for correctness.
|
||||
for (j = 1; j < pNode->Distance[i]; j++)
|
||||
printf("---");
|
||||
|
||||
printf("%02lu", (DWORD)pNode->Next[i]->Element);
|
||||
|
||||
pNode = pNode->Next[i];
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("================================\n\n");
|
||||
}
|
||||
|
||||
PVOID WINAPI
|
||||
MyAlloc(DWORD Size)
|
||||
{
|
||||
return HeapAlloc(GetProcessHeap(), 0, Size);
|
||||
}
|
||||
|
||||
int WINAPI
|
||||
MyCompare(PVOID A, PVOID B)
|
||||
{
|
||||
return (DWORD)A - (DWORD)B;
|
||||
}
|
||||
|
||||
void WINAPI
|
||||
MyFree(PVOID Ptr)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, Ptr);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
DWORD Element;
|
||||
DWORD ElementIndex;
|
||||
DWORD i;
|
||||
SKIPLIST Skiplist;
|
||||
PSKIPLIST_NODE pNode;
|
||||
|
||||
system("mode con cols=300");
|
||||
InitializeSkiplist(&Skiplist, MyAlloc, MyCompare, MyFree);
|
||||
|
||||
// Insert some random elements with random numbers.
|
||||
for (i = 0; i < 40; i++)
|
||||
InsertElementSkiplist(&Skiplist, (PVOID)(rand() % 100));
|
||||
|
||||
// Delete all with index 0 to 29.
|
||||
for (i = 0; i < 30; i++)
|
||||
DeleteElementSkiplist(&Skiplist, (PVOID)i);
|
||||
|
||||
// Insert some more random elements.
|
||||
for (i = 0; i < 40; i++)
|
||||
InsertElementSkiplist(&Skiplist, (PVOID)(rand() % 100));
|
||||
|
||||
// Output the third element (with zero-based index 2).
|
||||
pNode = LookupNodeByIndexSkiplist(&Skiplist, 2);
|
||||
printf("Element = %lu for index 2\n", (DWORD)pNode->Element);
|
||||
|
||||
// Check if an element with number 44 is in the list and output its index.
|
||||
Element = (DWORD)LookupElementSkiplist(&Skiplist, (PVOID)44, &ElementIndex);
|
||||
printf("Element = %lu, ElementIndex = %lu\n\n", Element, ElementIndex);
|
||||
|
||||
DumpSkiplist(&Skiplist);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue