Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

tsplay.c File Reference

#include <stdio.h>
#include "nt.h"
#include "ntrtl.h"

Go to the source code of this file.

Classes

struct  _TREE_NODE

Typedefs

typedef _TREE_NODE TREE_NODE
typedef TREE_NODEPTREE_NODE

Functions

ULONG RtlRandom (IN OUT PULONG Seed)
PTREE_NODE TreeInsert (IN PTREE_NODE Root, IN PTREE_NODE Node)
VOID PrintTree (IN PTREE_NODE Node)
int _CDECL main (int argc, char *argv[])

Variables

TREE_NODE Buffer [2048]


Typedef Documentation

typedef TREE_NODE* PTREE_NODE
 

Definition at line 32 of file tsplay.c.

Referenced by main().

typedef struct _TREE_NODE TREE_NODE
 


Function Documentation

int _CDECL main int  argc,
char *  argv[]
 

Definition at line 49 of file tsplay.c.

References Buffer, DbgPrint, NULL, PrintTree(), PTREE_NODE, RtlRandom(), Seed, TreeInsert(), and TRUE.

00053 { 00054 PTREE_NODE Root; 00055 ULONG i; 00056 ULONG Seed; 00057 00058 DbgPrint("Start SplayTest()\n"); 00059 00060 Root = NULL; 00061 Seed = 0; 00062 for (i=0; i<2048; i++) { 00063 Buffer[i].Data = RtlRandom(&Seed); 00064 Buffer[i].Data = Buffer[i].Data % 512; 00065 RtlInitializeSplayLinks(&Buffer[i].Links); 00066 Root = TreeInsert(Root, &Buffer[i]); 00067 } 00068 00069 PrintTree(Root); 00070 00071 DbgPrint("End SplayTest()\n"); 00072 00073 return TRUE; 00074 00075 }

VOID PrintTree IN PTREE_NODE  Node  ) 
 

Definition at line 149 of file tsplay.c.

References DbgPrint, NULL, and RtlRealSuccessor().

00153 { 00154 PRTL_SPLAY_LINKS Temp; 00155 ULONG LastValue; 00156 00157 if (Node == NULL) { 00158 return; 00159 } 00160 00161 // 00162 // find smallest value 00163 // 00164 00165 while (RtlLeftChild(&Node->Links) != NULL) { 00166 Node = CONTAINING_RECORD(RtlLeftChild(&Node->Links), TREE_NODE, Links); 00167 } 00168 LastValue = Node->Data; 00169 //DbgPrint("%u\n", Node->Data); 00170 00171 // 00172 // while the is a real successor we print the successor value 00173 // 00174 00175 while ((Temp = RtlRealSuccessor(&Node->Links)) != NULL) { 00176 Node = CONTAINING_RECORD(Temp, TREE_NODE, Links); 00177 if (LastValue >= Node->Data) { 00178 DbgPrint("TestSplay Error\n"); 00179 } 00180 LastValue = Node->Data; 00181 //DbgPrint("%u\n", Node->Data); 00182 } 00183 00184 }

ULONG RtlRandom IN OUT PULONG  Seed  ) 
 

Definition at line 72 of file rtl/random.c.

00078 : 00079 00080 An every better random number generator based on MacLaren and Marsaglia. 00081 00082 Arguments: 00083 00084 Seed - Supplies a pointer to the random number generator seed. 00085 00086 Return Value: 00087 00088 ULONG - returns a random number uniformly distributed over [0..MAXLONG] 00089 00090 --*/ 00091 00092 { 00093 ULONG X; 00094 ULONG Y; 00095 ULONG j; 00096 ULONG Result; 00097 00098 RTL_PAGED_CODE(); 00099 00100 X = UniformMacro(Seed); 00101 Y = UniformMacro(Seed); 00102 00103 j = Y % 128; 00104 00105 Result = RtlpRandomConstantVector[j]; 00106 00107 RtlpRandomConstantVector[j] = X; 00108 00109 return Result; 00110 00111 } }

PTREE_NODE TreeInsert IN PTREE_NODE  Root,
IN PTREE_NODE  Node
 

Definition at line 78 of file tsplay.c.

References NULL, RtlDelete(), RtlSplay(), and TRUE.

00083 { 00084 PRTL_SPLAY_LINKS Temp; 00085 00086 if (Root == NULL) { 00087 00088 //DbgPrint("Add as root %u\n", Node->Data); 00089 return Node; 00090 00091 } 00092 00093 while (TRUE) { 00094 00095 if (Root->Data == Node->Data) { 00096 00097 //DbgPrint("Delete %u\n", Node->Data); 00098 00099 Temp = RtlDelete(&Root->Links); 00100 if (Temp == NULL) { 00101 return NULL; 00102 } else { 00103 return CONTAINING_RECORD(Temp, TREE_NODE, Links); 00104 } 00105 00106 } 00107 00108 if (Root->Data < Node->Data) { 00109 00110 // 00111 // Go right 00112 // 00113 00114 if (RtlRightChild(&Root->Links) == NULL) { 00115 00116 //DbgPrint("Add as right child %u\n", Node->Data); 00117 RtlInsertAsRightChild(&Root->Links, &Node->Links); 00118 return CONTAINING_RECORD(RtlSplay(&Node->Links), TREE_NODE, Links); 00119 00120 } else { 00121 00122 Root = CONTAINING_RECORD(RtlRightChild(&Root->Links), TREE_NODE, Links); 00123 00124 } 00125 00126 } else { 00127 00128 // 00129 // Go Left 00130 // 00131 00132 if (RtlLeftChild(&Root->Links) == NULL) { 00133 00134 //DbgPrint("Add as left child %u\n", Node->Data); 00135 RtlInsertAsLeftChild(&Root->Links, &Node->Links); 00136 return CONTAINING_RECORD(RtlSplay(&Node->Links), TREE_NODE, Links); 00137 00138 } else { 00139 00140 Root = CONTAINING_RECORD(RtlLeftChild(&Root->Links), TREE_NODE, Links); 00141 00142 } 00143 00144 } 00145 } 00146 }


Variable Documentation

TREE_NODE Buffer[2048]
 

Definition at line 34 of file tsplay.c.


Generated on Sat May 15 19:45:49 2004 for test by doxygen 1.3.7