19 #include <config-htmesh.h>
26 result =
static_cast<double>( rand() );
29 result =
static_cast<double>( random() );
43 while ( (newLevel < maxLevel - 1) && (
drand48() < probability) )
50 : myProbability(probability)
76 for(i=myHeader->
getLevel(); i>=0; i--) {
78 while( (nextElement !=
NIL) && (nextElement->
getKey() < searchKey) ) {
89 if( (element !=
NIL) && (element->
getKey() == searchKey) ) {
98 if (newLevel > myHeader->
getLevel() ) {
100 for (i=myHeader->
getLevel() + 1; i<=newLevel; i++) {
110 for (i=0; i<= newLevel; i++ ) {
129 for(i=myHeader->
getLevel(); i>=0; i--) {
131 while( (nextElement !=
NIL) && (nextElement->
getKey() < searchKey) ) {
143 retKey = element->
getKey();
160 for(i=myHeader->
getLevel(); i>=0; i--) {
162 while( (nextElement !=
NIL) && (nextElement->
getKey() <= searchKey) ) {
170 element = nextElement;
172 retKey = element->
getKey();
191 for(i=myHeader->
getLevel(); i>=0; i--) {
193 while( (nextElement !=
NIL) && (nextElement->
getKey() < loKey) ) {
201 while( (element !=
NIL) && (element->
getKey() <= hiKey) ) {
204 element = nextElement;
219 for(i=myHeader->
getLevel(); i>=0; i--) {
221 while( (nextElement !=
NIL) && (nextElement->
getKey() < searchKey) ) {
233 if( (element !=
NIL) && (element->
getKey() == searchKey) ) {
234 for(i=0; i<=myHeader->
getLevel(); i++) {
261 while( (nextElement !=
NIL) ) {
266 std::cout <<
"Have number of elements ... " << count << std::endl;
267 std::cout <<
"Size ..................... " << myLength << std::endl;
272 long totalPointers, usedPointers;
279 while( (nextElement !=
NIL) ) {
294 if(hist[i] > 0) std::cout << std::setw(2) << i <<
": " << std::setw(6) << hist[i] << std::endl;
295 usedPointers += hist[i] * (1 + i);
297 std::cout <<
"Used pointers " << usedPointers << std::endl;
298 std::cout <<
"Total pointers " << totalPointers <<
" efficiency = " <<
299 (double) usedPointers / (
double) totalPointers << std::endl;
SkipListElement * getElement(long level)
get next element in level
void setLevel(long level)
Set level of element.
void setKey(Key key)
set key of element
#define SKIPLIST_MAXLEVEL
SkipList(float probability=0.5)
Key getKey() const
get key of element
void free(const Key searchKey)
free element with key
void setElement(long level, SkipListElement *element)
set next element in level
long getLevel() const
get level of element
void freeRange(const Key loKey, const Key hiKey)
void setValue(Value value)
set value of element
Key findMAX(const Key searchKey) const
search element with key NGT searchKey
void insert(const Key searchKey, const Value value)
insert new element
long getNewLevel(long maxLevel, float probability)
Key findMIN(const Key searchKey) const
search element with key NLT searchKey