home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GEMini Atari
/
GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso
/
files
/
gnu
/
g__lib
/
rplex.hp
< prev
next >
Wrap
Text File
|
1993-07-23
|
6KB
|
230 lines
// This may look like C code, but it is really -*- C++ -*-
/*
Copyright (C) 1988 Free Software Foundation
written by Doug Lea (dl@rocky.oswego.edu)
based on code by Marc Shapiro (shapiro@sor.inria.fr)
This file is part of GNU CC.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. No author or distributor
accepts responsibility to anyone for the consequences of using it
or for whether it serves any particular purpose or works at all,
unless he says so in writing. Refer to the GNU CC General Public
License for full details.
Everyone is granted permission to copy, modify and redistribute
GNU CC, but only under the conditions described in the
GNU CC General Public License. A copy of this license is
supposed to have been given to you along with GNU CC so you
can know your rights and responsibilities. It should be in a
file named COPYING. Among other things, the copyright notice
and this notice must be preserved on all copies.
*/
#ifndef _<T>RPlex_h
#pragma once
#define _<T>RPlex_h 1
#include "<T>.Plex.h"
// minimum number of chunks to index
#ifndef MIN_NCHUNKS
#define MIN_NCHUNKS 16
#endif
class <T>RPlex: public <T>Plex
{
int base; // base index of lowest chunk
int lch; // index of lowest used chunk
int fch; // 1 + index of highest used chunk
int maxch; // max chunks in array
<T>IChunk** chunks; // array of chunks
<T>IChunk* ch; // cached chunk
void make_initial_chunks(int up = 1);
void cache(int idx);
void cache(const <T>* p);
<T>* dopred(<T>* p);
<T>* dosucc(<T>* p);
public:
<T>RPlex(); // set low = 0;
// fence = 0;
// csize = default
<T>RPlex(int ch_size); // low = 0;
// fence = 0;
// csize = ch_size
<T>RPlex(int lo, // low = lo;
int ch_size); // fence=lo
// csize = ch_size
<T>RPlex(int lo, // low = lo
int hi, // fence = hi+1
const <T&> initval,// fill with initval,
int ch_size = 0); // csize= ch_size
// or fence-lo if 0
<T>RPlex(const <T>RPlex&);
~<T>RPlex();
void operator= (const <T>RPlex&);
// virtuals
<T>& high_element ();
<T>& low_element ();
Pix first();
Pix last();
void prev(Pix& ptr);
void next(Pix& ptr);
int owns(Pix p);
<T>& operator () (Pix p);
int low();
int high();
int valid(int idx);
void prev(int& idx);
void next(int& x);
<T>& operator [] (int index);
int Pix_to_index(Pix p);
Pix index_to_Pix(int idx);
int can_add_high();
int can_add_low();
int full();
int add_high(const <T&> elem);
int del_high ();
int add_low (const <T&> elem);
int del_low ();
void fill(const <T&> x);
void fill(const <T&> x, int from, int to);
void clear();
int reset_low(int l);
void reverse();
void append(const <T>Plex& a);
void prepend(const <T>Plex& a);
int OK ();
};
inline void <T>RPlex::prev(int& idx)
{
--idx;
}
inline void <T>RPlex::next(int& idx)
{
++idx;
}
inline int <T>RPlex::full ()
{
return 0;
}
inline int <T>RPlex::can_add_high()
{
return 1;
}
inline int <T>RPlex::can_add_low()
{
return 1;
}
inline int <T>RPlex::valid (int idx)
{
return idx >= lo && idx < fnc;
}
inline int <T>RPlex::low()
{
return lo;
}
inline int <T>RPlex::high()
{
return fnc - 1;
}
inline <T>& <T>RPlex::low_element ()
{
if (empty()) index_error();
return *(hd->pointer_to(lo));
}
inline <T>& <T>RPlex::high_element ()
{
if (empty()) index_error();
return *(tl()->pointer_to(fnc - 1));
}
inline int <T>RPlex::Pix_to_index(Pix p)
{
if (!ch->actual_pointer(p)) cache(p);
return ch->index_of(p);
}
inline Pix <T>RPlex::index_to_Pix(int idx)
{
if (!ch->actual_index(idx)) cache(idx);
return (Pix)(ch->pointer_to(idx));
}
inline Pix <T>RPlex::first()
{
return Pix(hd-><T>IChunk::first_pointer());
}
inline Pix <T>RPlex::last()
{
return Pix(tl()-><T>IChunk::last_pointer());
}
inline void <T>RPlex::prev(Pix& p)
{
Pix q = Pix(ch-><T>IChunk::pred((<T>*)p));
p = (q == 0)? Pix(dopred((<T>*)p)) : q;
}
inline void <T>RPlex::next(Pix& p)
{
Pix q = Pix(ch-><T>IChunk::succ((<T>*)p));
p = (q == 0)? Pix(dosucc((<T>*)p)) : q;
}
inline <T>& <T>RPlex:: operator () (Pix p)
{
return *((<T>*)p);
}
inline void <T>RPlex::cache(int idx)
{
if (idx < lo || idx >= fnc) index_error();
ch = chunks[(idx - base) / csize];
}
inline <T>& <T>RPlex:: operator [] (int idx)
{
cache(idx); return *(ch->pointer_to(idx));
}
inline <T>RPlex::~<T>RPlex()
{
delete chunks;
}
#endif