// 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 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.
csize = DEFAULT_INITIAL_CAPACITY;
<T>* data = new <T>[csize];
set_cache(new <T>IChunk(data, lo, lo, fnc, lo+csize));
<T>XPlex:: <T>XPlex(int chunksize)
if (chunksize == 0) error("invalid constructor specification");
<T>* data = new <T>[csize];
set_cache(new <T>IChunk(data, lo, lo, fnc, csize));
<T>* data = new <T>[csize];
set_cache(new <T>IChunk(data, chunksize, lo, fnc, fnc));
<T>XPlex:: <T>XPlex(int l, int chunksize)
if (chunksize == 0) error("invalid constructor specification");
<T>* data = new <T>[csize];
set_cache(new <T>IChunk(data, lo, lo, fnc, csize+lo));
<T>* data = new <T>[csize];
set_cache(new <T>IChunk(data, chunksize+lo, lo, fnc, fnc));
void <T>XPlex::make_initial_chunks(int up)
<T>* data = new <T> [csize];
<T>IChunk* h = new <T>IChunk(data, l, l, l+sz, l+csize);
<T>* data = new <T> [csize];
<T>IChunk* h = new <T>IChunk(data, hi-csize, hi-sz, hi, hi);
<T>XPlex:: <T>XPlex(int l, int hi, const <T&> initval, int chunksize)
<T>XPlex::<T>XPlex(const <T>XPlex& a)
for (int i = a.low(); i < a.fence(); a.next(i)) (*this)[i] = a[i];
void <T>XPlex::operator= (const <T>XPlex& a)
for (int i = a.low(); i < a.fence(); a.next(i)) (*this)[i] = a[i];
void <T>XPlex::cache(int idx) const
const <T>IChunk* tail = tl();
while (idx >= t->fence_index())
if (t == tail) index_error();
while (idx < t->low_index())
if (t == hd) index_error();
void <T>XPlex::cache(const <T>* p) const
const <T>IChunk* old = ch;
while (!t->actual_pointer(p))
if (t == old) index_error();
int <T>XPlex::owns(Pix px) const
const <T>IChunk* old = ch;
while (!t->actual_pointer(p))
if (t == old) { set_cache(t); return 0; }
<T>* <T>XPlex::dosucc(const <T>* p) const
const <T>IChunk* old = ch;
while (!t->actual_pointer(p))
int i = t->index_of(p) + 1;
if (i >= t->fence_index()) t = (t->next());
return (t->pointer_to(i));
<T>* <T>XPlex::dopred(const <T>* p) const
const <T>IChunk* old = ch;
while (!t->actual_pointer(p))
int i = t->index_of(p) - 1;
if (i < t->low_index()) t = (t->prev());
return (t->pointer_to(i));
int <T>XPlex::add_high(const <T&> elem)
if (t-><T>IChunk::empty() && one_chunk())
<T>* data = new <T> [csize];
t = (new <T>IChunk(data, fnc, fnc, fnc,fnc+csize));
*((t-><T>IChunk::grow_high())) = elem;
int <T>XPlex::del_high ()
if (empty()) empty_error();
t-><T>IChunk::shrink_high();
if (t-><T>IChunk::empty() && !one_chunk())
<T>IChunk* pred = t->prev();
int <T>XPlex::add_low (const <T&> elem)
if (t-><T>IChunk::empty() && one_chunk())
<T>* data = new <T> [csize];
hd = new <T>IChunk(data, lo-csize, lo, lo, lo);
*((t-><T>IChunk::grow_low())) = elem;
if (empty()) empty_error();
t-><T>IChunk::shrink_low();
if (t-><T>IChunk::empty() && !one_chunk())
<T>* lptr = loch->pointer_to(l);
<T>* hptr = hich->pointer_to(h);
if (++l >= loch->fence_index()) loch = loch->next();
if (--h < hich->low_index()) hich = hich->prev();
void <T>XPlex::fill(const <T&> x)
for (int i = lo; i < fnc; ++i) (*this)[i] = x;
void <T>XPlex::fill(const <T&> x, int l, int hi)
for (int i = l; i <= hi; ++i) (*this)[i] = x;
<T>IChunk* prv = t->prev();
int <T>XPlex::OK () const
int v = hd != 0 && ch != 0; // at least one chunk
v &= fnc == tl()->fence_index();// last chunk fence == plex fence
v &= lo == ((hd))-><T>IChunk::low_index(); // first lo == plex lo
int found_ch = 0; // to make sure ch is in list;
const <T>IChunk* t = (hd);
v &= t-><T>IChunk::OK(); // each chunk is OK
else // and has indices contiguous to succ
v &= t->top_index() == t->next()->base_index();
if (t != hd) // internal chunks full
v &= !t->can_grow_high();
if (!v) error("invariant failure");