Category : OS/2 Files
Archive   : GPPDEV8F.ZIP
Filename : SKIPSET.CCP
/*
Copyright (C) 1991 Free Software Foundation
This file is part of the GNU C++ Library. This library is free
software; you can redistribute it and/or modify it under the terms of
the GNU Library General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version. This library is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Sets implemented via William Pugh SkipList algorithms.
* CACM, June 1990, p 668-676.
*
*/
#include
#include
#include "
MLCG*
int
static int countbits(long bits)
{
int n = 0;
while(bits>>=1L) n++;
return n;
}
: level(0),
header(new
max_levels (countbits(size)+1),
random_bits(gen->asLong()),
randoms_left(BITS_IN_RANDOM / 2)
{
count = 0;
while (trav > buffer_start)
*--trav = (
}
: level (0),
header (new
max_levels (b.max_levels),
random_bits (gen->asLong()),
randoms_left (BITS_IN_RANDOM / 2)
{
count = 0;
while (trav > buffer_start)
*--trav = (
for (
add(t->item);
}
/* relationals */
int
{
if (count != y.count)
return 0;
else
{
for (;;)
{
if (t == 0)
return 1;
else if (!
return 0;
else
{
t = succ(t);
u = y.succ(u);
}
}
}
}
int
{
if (count > y.count)
return 0;
else
{
for (;;)
{
if (t == 0)
return 1;
else if (u == 0)
return 0;
int cmp =
if (cmp == 0)
{
t = succ(t);
u = y.succ(u);
}
else if (cmp < 0)
return 0;
else
u = y.succ(u);
}
}
}
void
{
if (&y == this) return;
while (u != 0)
{
add(u->item);
u = y.succ(u);
}
}
void
{
if (y.count == 0)
clear();
else if (&y != this && count != 0)
{
while (t != 0)
{
if (y.seek(t->item) == 0) del(t->item);
t = s;
}
}
}
void
{
if (&y == this)
clear();
else if (y.count != 0)
{
while (t != 0)
{
if (y.seek(t->item) != 0) del(t->item);
t = s;
}
}
}
Pix
{
int l = level;
do
{
while ((temp = curr->forward[l])!=header &&
curr = temp;
update[l] = curr;
}
while (--l >= 0);
if (temp != header &&
return Pix(temp);
if ((l = random_level ()) > level)
{
l = ++level;
update[l] = (
};
temp = new
do
{
temp_forward[l] = curr_forward[l];
curr_forward[l] = temp;
}
while (--l >= 0);
count++;
delete update;
return Pix(temp);
}
void
{
int l = level;
int curr_level = level;
do
{
while ((temp = curr->forward[l])!=header
&&
curr = temp;
update[l] = curr;
}
while (--l >= 0);
if (
{
for (l = 0;
l <= curr_level && (curr = update[l])->forward[l] == temp;
l++)
curr->forward[l] = temp_forward[l];
delete temp;
while (forward[curr_level]==header && curr_level > 0)
curr_level--;
level = curr_level;
count--;
delete update;
return;
}
}
{
int l = level;
do
while ((temp = curr->forward[l])!=header)
curr = temp;
while (--l >= 0);
return temp==header ? 0 : temp;
}
{
int l = level;
do
while ((temp = curr->forward[l])!=t)
curr = temp;
while (--l >= 0);
return curr == header ? 0 : curr;
}
void
{
while (p != header)
{
delete p;
p = q;
}
}
void
{
_kill();
count = 0;
while (trav > buffer_start)
*--trav = (
}
Pix
{
int l = level;
do
{
while ((temp = curr->forward[l])!=header &&
curr = temp;
}
while (--l >= 0);
if (
return 0;
else
{
return Pix(temp);
}
}
/*
* random function for probabilistic balancing
*
* Hardwired for p = .25. Not too flexible,
* but fast. Changing this would require a constructor
* that would accept a different value for p, etc.
* Perhaps someone else would like to implement this?
*
*/
int
{
int rlevel = 0;
int b;
do
{
b = random_bits & 3L;
if (!b)
rlevel++;
random_bits >>= 2;
if (--randoms_left == 0)
{
random_bits = gen->asLong();
randoms_left = BITS_IN_RANDOM / 2;
};
}
while (!b);
return rlevel > max_levels ? max_levels : rlevel;
}
int
{
int v = 1;
if (header == 0)
v = 0;
else
{
int n = 0;
if (trail) t = succ(trail);
if (t) n++;
while (t != 0)
{
++n;
v &=
trail = t;
t = succ(t);
}
v &= n == count;
}
if (!v) error("invariant failure");
return v;
}
{
if (!count)
count++;
}
{
count--;
if (!count)
delete
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/