./g++-include/ 40755 0 1 0 5522122646 11457 5ustar rootdaemon./g++-include/gen/ 40755 0 1 0 5522122630 12221 5ustar rootdaemon./g++-include/gen/AVLMap.ccP100644 0 1 31233 5522102330 14042 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include "..AVLMap.h" /* constants & inlines for maintaining balance & thread status in tree nodes */ #define AVLBALANCEMASK 3 #define AVLBALANCED 0 #define AVLLEFTHEAVY 1 #define AVLRIGHTHEAVY 2 #define LTHREADBIT 4 #define RTHREADBIT 8 static inline int bf(AVLNode* t) { return t->stat & AVLBALANCEMASK; } static inline void set_bf(AVLNode* t, int b) { t->stat = (t->stat & ~AVLBALANCEMASK) | (b & AVLBALANCEMASK); } static inline int rthread(AVLNode* t) { return t->stat & RTHREADBIT; } static inline void set_rthread(AVLNode* t, int b) { if (b) t->stat |= RTHREADBIT; else t->stat &= ~RTHREADBIT; } static inline int lthread(AVLNode* t) { return t->stat & LTHREADBIT; } static inline void set_lthread(AVLNode* t, int b) { if (b) t->stat |= LTHREADBIT; else t->stat &= ~LTHREADBIT; } /* traversal primitives */ AVLNode* AVLMap::leftmost() { AVLNode* t = root; if (t != 0) while (t->lt != 0) t = t->lt; return t; } AVLNode* AVLMap::rightmost() { AVLNode* t = root; if (t != 0) while (t->rt != 0) t = t->rt; return t; } AVLNode* AVLMap::succ(AVLNode* t) { AVLNode* r = t->rt; if (!rthread(t)) while (!lthread(r)) r = r->lt; return r; } AVLNode* AVLMap::pred(AVLNode* t) { AVLNode* l = t->lt; if (!lthread(t)) while (!rthread(l)) l = l->rt; return l; } Pix AVLMap::seek( key) { AVLNode* t = root; if (t == 0) return 0; for (;;) { int cmp = CMP(key, t->item); if (cmp == 0) return Pix(t); else if (cmp < 0) { if (lthread(t)) return 0; else t = t->lt; } else if (rthread(t)) return 0; else t = t->rt; } } /* The combination of threads and AVL bits make adding & deleting interesting, but very awkward. We use the following statics to avoid passing them around recursively */ static int _need_rebalancing; // to send back balance info from rec. calls static * _target_item; // add/del_item target static AVLNode* _found_node; // returned added/deleted node static int _already_found; // for deletion subcases void AVLMap:: _add(AVLNode*& t) { int cmp = CMP(*_target_item, t->item); if (cmp == 0) { _found_node = t; return; } else if (cmp < 0) { if (lthread(t)) { ++count; _found_node = new AVLNode(*_target_item, def); set_lthread(_found_node, 1); set_rthread(_found_node, 1); _found_node->lt = t->lt; _found_node->rt = t; t->lt = _found_node; set_lthread(t, 0); _need_rebalancing = 1; } else _add(t->lt); if (_need_rebalancing) { switch(bf(t)) { case AVLRIGHTHEAVY: set_bf(t, AVLBALANCED); _need_rebalancing = 0; return; case AVLBALANCED: set_bf(t, AVLLEFTHEAVY); return; case AVLLEFTHEAVY: { AVLNode* l = t->lt; if (bf(l) == AVLLEFTHEAVY) { if (rthread(l)) t->lt = l; else t->lt = l->rt; set_lthread(t, rthread(l)); l->rt = t; set_rthread(l, 0); set_bf(t, AVLBALANCED); set_bf(l, AVLBALANCED); t = l; _need_rebalancing = 0; } else { AVLNode* r = l->rt; set_rthread(l, lthread(r)); if (lthread(r)) l->rt = r; else l->rt = r->lt; r->lt = l; set_lthread(r, 0); set_lthread(t, rthread(r)); if (rthread(r)) t->lt = r; else t->lt = r->rt; r->rt = t; set_rthread(r, 0); if (bf(r) == AVLLEFTHEAVY) set_bf(t, AVLRIGHTHEAVY); else set_bf(t, AVLBALANCED); if (bf(r) == AVLRIGHTHEAVY) set_bf(l, AVLLEFTHEAVY); else set_bf(l, AVLBALANCED); set_bf(r, AVLBALANCED); t = r; _need_rebalancing = 0; return; } } } } } else { if (rthread(t)) { ++count; _found_node = new AVLNode(*_target_item, def); set_rthread(t, 0); set_lthread(_found_node, 1); set_rthread(_found_node, 1); _found_node->lt = t; _found_node->rt = t->rt; t->rt = _found_node; _need_rebalancing = 1; } else _add(t->rt); if (_need_rebalancing) { switch(bf(t)) { case AVLLEFTHEAVY: set_bf(t, AVLBALANCED); _need_rebalancing = 0; return; case AVLBALANCED: set_bf(t, AVLRIGHTHEAVY); return; case AVLRIGHTHEAVY: { AVLNode* r = t->rt; if (bf(r) == AVLRIGHTHEAVY) { if (lthread(r)) t->rt = r; else t->rt = r->lt; set_rthread(t, lthread(r)); r->lt = t; set_lthread(r, 0); set_bf(t, AVLBALANCED); set_bf(r, AVLBALANCED); t = r; _need_rebalancing = 0; } else { AVLNode* l = r->lt; set_lthread(r, rthread(l)); if (rthread(l)) r->lt = l; else r->lt = l->rt; l->rt = r; set_rthread(l, 0); set_rthread(t, lthread(l)); if (lthread(l)) t->rt = l; else t->rt = l->lt; l->lt = t; set_lthread(l, 0); if (bf(l) == AVLRIGHTHEAVY) set_bf(t, AVLLEFTHEAVY); else set_bf(t, AVLBALANCED); if (bf(l) == AVLLEFTHEAVY) set_bf(r, AVLRIGHTHEAVY); else set_bf(r, AVLBALANCED); set_bf(l, AVLBALANCED); t = l; _need_rebalancing = 0; return; } } } } } } & AVLMap::operator [] ( item) { if (root == 0) { ++count; root = new AVLNode(item, def); set_rthread(root, 1); set_lthread(root, 1); return root->cont; } else { _target_item = &item; _need_rebalancing = 0; _add(root); return _found_node->cont; } } void AVLMap::_del(AVLNode* par, AVLNode*& t) { int comp; if (_already_found) { if (rthread(t)) comp = 0; else comp = 1; } else comp = CMP(*_target_item, t->item); if (comp == 0) { if (lthread(t) && rthread(t)) { _found_node = t; if (t == par->lt) { set_lthread(par, 1); par->lt = t->lt; } else { set_rthread(par, 1); par->rt = t->rt; } _need_rebalancing = 1; return; } else if (lthread(t)) { _found_node = t; AVLNode* s = succ(t); if (s != 0 && lthread(s)) s->lt = t->lt; t = t->rt; _need_rebalancing = 1; return; } else if (rthread(t)) { _found_node = t; AVLNode* p = pred(t); if (p != 0 && rthread(p)) p->rt = t->rt; t = t->lt; _need_rebalancing = 1; return; } else // replace item & find someone deletable { AVLNode* p = pred(t); t->item = p->item; t->cont = p->cont; _already_found = 1; comp = -1; // fall through below to left } } if (comp < 0) { if (lthread(t)) return; _del(t, t->lt); if (!_need_rebalancing) return; switch (bf(t)) { case AVLLEFTHEAVY: set_bf(t, AVLBALANCED); return; case AVLBALANCED: set_bf(t, AVLRIGHTHEAVY); _need_rebalancing = 0; return; case AVLRIGHTHEAVY: { AVLNode* r = t->rt; switch (bf(r)) { case AVLBALANCED: if (lthread(r)) t->rt = r; else t->rt = r->lt; set_rthread(t, lthread(r)); r->lt = t; set_lthread(r, 0); set_bf(t, AVLRIGHTHEAVY); set_bf(r, AVLLEFTHEAVY); _need_rebalancing = 0; t = r; return; case AVLRIGHTHEAVY: if (lthread(r)) t->rt = r; else t->rt = r->lt; set_rthread(t, lthread(r)); r->lt = t; set_lthread(r, 0); set_bf(t, AVLBALANCED); set_bf(r, AVLBALANCED); t = r; return; case AVLLEFTHEAVY: { AVLNode* l = r->lt; set_lthread(r, rthread(l)); if (rthread(l)) r->lt = l; else r->lt = l->rt; l->rt = r; set_rthread(l, 0); set_rthread(t, lthread(l)); if (lthread(l)) t->rt = l; else t->rt = l->lt; l->lt = t; set_lthread(l, 0); if (bf(l) == AVLRIGHTHEAVY) set_bf(t, AVLLEFTHEAVY); else set_bf(t, AVLBALANCED); if (bf(l) == AVLLEFTHEAVY) set_bf(r, AVLRIGHTHEAVY); else set_bf(r, AVLBALANCED); set_bf(l, AVLBALANCED); t = l; return; } } } } } else { if (rthread(t)) return; _del(t, t->rt); if (!_need_rebalancing) return; switch (bf(t)) { case AVLRIGHTHEAVY: set_bf(t, AVLBALANCED); return; case AVLBALANCED: set_bf(t, AVLLEFTHEAVY); _need_rebalancing = 0; return; case AVLLEFTHEAVY: { AVLNode* l = t->lt; switch (bf(l)) { case AVLBALANCED: if (rthread(l)) t->lt = l; else t->lt = l->rt; set_lthread(t, rthread(l)); l->rt = t; set_rthread(l, 0); set_bf(t, AVLLEFTHEAVY); set_bf(l, AVLRIGHTHEAVY); _need_rebalancing = 0; t = l; return; case AVLLEFTHEAVY: if (rthread(l)) t->lt = l; else t->lt = l->rt; set_lthread(t, rthread(l)); l->rt = t; set_rthread(l, 0); set_bf(t, AVLBALANCED); set_bf(l, AVLBALANCED); t = l; return; case AVLRIGHTHEAVY: { AVLNode* r = l->rt; set_rthread(l, lthread(r)); if (lthread(r)) l->rt = r; else l->rt = r->lt; r->lt = l; set_lthread(r, 0); set_lthread(t, rthread(r)); if (rthread(r)) t->lt = r; else t->lt = r->rt; r->rt = t; set_rthread(r, 0); if (bf(r) == AVLLEFTHEAVY) set_bf(t, AVLRIGHTHEAVY); else set_bf(t, AVLBALANCED); if (bf(r) == AVLRIGHTHEAVY) set_bf(l, AVLLEFTHEAVY); else set_bf(l, AVLBALANCED); set_bf(r, AVLBALANCED); t = r; return; } } } } } } void AVLMap::del( item) { if (root == 0) return; _need_rebalancing = 0; _already_found = 0; _found_node = 0; _target_item = &item; _del(root, root); if (_found_node) { delete(_found_node); if (--count == 0) root = 0; } } void AVLMap::_kill(AVLNode* t) { if (t != 0) { if (!lthread(t)) _kill(t->lt); if (!rthread(t)) _kill(t->rt); delete t; } } AVLMap::AVLMap(AVLMap& b) :Map(b.def) { root = 0; count = 0; for (Pix i = b.first(); i != 0; b.next(i)) (*this)[b.key(i)] = b.contents(i); } int AVLMap::OK() { int v = 1; if (root == 0) v = count == 0; else { int n = 1; AVLNode* trail = leftmost(); AVLNode* t = succ(trail); while (t != 0) { ++n; v &= CMP(trail->item, t->item) < 0; trail = t; t = succ(t); } v &= n == count; } if (!v) error("invariant failure"); return v; } ./g++-include/gen/AVLSet.ccP100644 0 1 42130 5522102331 14057 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include ".AVLSet.h" #include /* constants & inlines for maintaining balance & thread status in tree nodes */ #define AVLBALANCEMASK 3 #define AVLBALANCED 0 #define AVLLEFTHEAVY 1 #define AVLRIGHTHEAVY 2 #define LTHREADBIT 4 #define RTHREADBIT 8 static inline int bf(AVLNode* t) { return t->stat & AVLBALANCEMASK; } static inline void set_bf(AVLNode* t, int b) { t->stat = (t->stat & ~AVLBALANCEMASK) | (b & AVLBALANCEMASK); } static inline int rthread(AVLNode* t) { return t->stat & RTHREADBIT; } static inline void set_rthread(AVLNode* t, int b) { if (b) t->stat |= RTHREADBIT; else t->stat &= ~RTHREADBIT; } static inline int lthread(AVLNode* t) { return t->stat & LTHREADBIT; } static inline void set_lthread(AVLNode* t, int b) { if (b) t->stat |= LTHREADBIT; else t->stat &= ~LTHREADBIT; } /* traversal primitives */ AVLNode* AVLSet::leftmost() { AVLNode* t = root; if (t != 0) while (t->lt != 0) t = t->lt; return t; } AVLNode* AVLSet::rightmost() { AVLNode* t = root; if (t != 0) while (t->rt != 0) t = t->rt; return t; } AVLNode* AVLSet::succ(AVLNode* t) { AVLNode* r = t->rt; if (!rthread(t)) while (!lthread(r)) r = r->lt; return r; } AVLNode* AVLSet::pred(AVLNode* t) { AVLNode* l = t->lt; if (!lthread(t)) while (!rthread(l)) l = l->rt; return l; } Pix AVLSet::seek( key) { AVLNode* t = root; if (t == 0) return 0; for (;;) { int cmp = CMP(key, t->item); if (cmp == 0) return Pix(t); else if (cmp < 0) { if (lthread(t)) return 0; else t = t->lt; } else if (rthread(t)) return 0; else t = t->rt; } } /* The combination of threads and AVL bits make adding & deleting interesting, but very awkward. We use the following statics to avoid passing them around recursively */ static int _need_rebalancing; // to send back balance info from rec. calls static * _target_item; // add/del_item target static AVLNode* _found_node; // returned added/deleted node static int _already_found; // for deletion subcases static AVLNode** _hold_nodes; // used for rebuilding trees static int _max_hold_index; // # elements-1 in _hold_nodes void AVLSet:: _add(AVLNode*& t) { int cmp = CMP(*_target_item, t->item); if (cmp == 0) { _found_node = t; return; } else if (cmp < 0) { if (lthread(t)) { ++count; _found_node = new AVLNode(*_target_item); set_lthread(_found_node, 1); set_rthread(_found_node, 1); _found_node->lt = t->lt; _found_node->rt = t; t->lt = _found_node; set_lthread(t, 0); _need_rebalancing = 1; } else _add(t->lt); if (_need_rebalancing) { switch(bf(t)) { case AVLRIGHTHEAVY: set_bf(t, AVLBALANCED); _need_rebalancing = 0; return; case AVLBALANCED: set_bf(t, AVLLEFTHEAVY); return; case AVLLEFTHEAVY: { AVLNode* l = t->lt; if (bf(l) == AVLLEFTHEAVY) { if (rthread(l)) t->lt = l; else t->lt = l->rt; set_lthread(t, rthread(l)); l->rt = t; set_rthread(l, 0); set_bf(t, AVLBALANCED); set_bf(l, AVLBALANCED); t = l; _need_rebalancing = 0; } else { AVLNode* r = l->rt; set_rthread(l, lthread(r)); if (lthread(r)) l->rt = r; else l->rt = r->lt; r->lt = l; set_lthread(r, 0); set_lthread(t, rthread(r)); if (rthread(r)) t->lt = r; else t->lt = r->rt; r->rt = t; set_rthread(r, 0); if (bf(r) == AVLLEFTHEAVY) set_bf(t, AVLRIGHTHEAVY); else set_bf(t, AVLBALANCED); if (bf(r) == AVLRIGHTHEAVY) set_bf(l, AVLLEFTHEAVY); else set_bf(l, AVLBALANCED); set_bf(r, AVLBALANCED); t = r; _need_rebalancing = 0; return; } } } } } else { if (rthread(t)) { ++count; _found_node = new AVLNode(*_target_item); set_rthread(t, 0); set_lthread(_found_node, 1); set_rthread(_found_node, 1); _found_node->lt = t; _found_node->rt = t->rt; t->rt = _found_node; _need_rebalancing = 1; } else _add(t->rt); if (_need_rebalancing) { switch(bf(t)) { case AVLLEFTHEAVY: set_bf(t, AVLBALANCED); _need_rebalancing = 0; return; case AVLBALANCED: set_bf(t, AVLRIGHTHEAVY); return; case AVLRIGHTHEAVY: { AVLNode* r = t->rt; if (bf(r) == AVLRIGHTHEAVY) { if (lthread(r)) t->rt = r; else t->rt = r->lt; set_rthread(t, lthread(r)); r->lt = t; set_lthread(r, 0); set_bf(t, AVLBALANCED); set_bf(r, AVLBALANCED); t = r; _need_rebalancing = 0; } else { AVLNode* l = r->lt; set_lthread(r, rthread(l)); if (rthread(l)) r->lt = l; else r->lt = l->rt; l->rt = r; set_rthread(l, 0); set_rthread(t, lthread(l)); if (lthread(l)) t->rt = l; else t->rt = l->lt; l->lt = t; set_lthread(l, 0); if (bf(l) == AVLRIGHTHEAVY) set_bf(t, AVLLEFTHEAVY); else set_bf(t, AVLBALANCED); if (bf(l) == AVLLEFTHEAVY) set_bf(r, AVLRIGHTHEAVY); else set_bf(r, AVLBALANCED); set_bf(l, AVLBALANCED); t = l; _need_rebalancing = 0; return; } } } } } } Pix AVLSet::add( item) { if (root == 0) { ++count; root = new AVLNode(item); set_rthread(root, 1); set_lthread(root, 1); return Pix(root); } else { _target_item = &item; _need_rebalancing = 0; _add(root); return Pix(_found_node); } } void AVLSet::_del(AVLNode* par, AVLNode*& t) { int comp; if (_already_found) { if (rthread(t)) comp = 0; else comp = 1; } else comp = CMP(*_target_item, t->item); if (comp == 0) { if (lthread(t) && rthread(t)) { _found_node = t; if (t == par->lt) { set_lthread(par, 1); par->lt = t->lt; } else { set_rthread(par, 1); par->rt = t->rt; } _need_rebalancing = 1; return; } else if (lthread(t)) { _found_node = t; AVLNode* s = succ(t); if (s != 0 && lthread(s)) s->lt = t->lt; t = t->rt; _need_rebalancing = 1; return; } else if (rthread(t)) { _found_node = t; AVLNode* p = pred(t); if (p != 0 && rthread(p)) p->rt = t->rt; t = t->lt; _need_rebalancing = 1; return; } else // replace item & find someone deletable { AVLNode* p = pred(t); t->item = p->item; _already_found = 1; comp = -1; // fall through below to left } } if (comp < 0) { if (lthread(t)) return; _del(t, t->lt); if (!_need_rebalancing) return; switch (bf(t)) { case AVLLEFTHEAVY: set_bf(t, AVLBALANCED); return; case AVLBALANCED: set_bf(t, AVLRIGHTHEAVY); _need_rebalancing = 0; return; case AVLRIGHTHEAVY: { AVLNode* r = t->rt; switch (bf(r)) { case AVLBALANCED: if (lthread(r)) t->rt = r; else t->rt = r->lt; set_rthread(t, lthread(r)); r->lt = t; set_lthread(r, 0); set_bf(t, AVLRIGHTHEAVY); set_bf(r, AVLLEFTHEAVY); _need_rebalancing = 0; t = r; return; case AVLRIGHTHEAVY: if (lthread(r)) t->rt = r; else t->rt = r->lt; set_rthread(t, lthread(r)); r->lt = t; set_lthread(r, 0); set_bf(t, AVLBALANCED); set_bf(r, AVLBALANCED); t = r; return; case AVLLEFTHEAVY: { AVLNode* l = r->lt; set_lthread(r, rthread(l)); if (rthread(l)) r->lt = l; else r->lt = l->rt; l->rt = r; set_rthread(l, 0); set_rthread(t, lthread(l)); if (lthread(l)) t->rt = l; else t->rt = l->lt; l->lt = t; set_lthread(l, 0); if (bf(l) == AVLRIGHTHEAVY) set_bf(t, AVLLEFTHEAVY); else set_bf(t, AVLBALANCED); if (bf(l) == AVLLEFTHEAVY) set_bf(r, AVLRIGHTHEAVY); else set_bf(r, AVLBALANCED); set_bf(l, AVLBALANCED); t = l; return; } } } } } else { if (rthread(t)) return; _del(t, t->rt); if (!_need_rebalancing) return; switch (bf(t)) { case AVLRIGHTHEAVY: set_bf(t, AVLBALANCED); return; case AVLBALANCED: set_bf(t, AVLLEFTHEAVY); _need_rebalancing = 0; return; case AVLLEFTHEAVY: { AVLNode* l = t->lt; switch (bf(l)) { case AVLBALANCED: if (rthread(l)) t->lt = l; else t->lt = l->rt; set_lthread(t, rthread(l)); l->rt = t; set_rthread(l, 0); set_bf(t, AVLLEFTHEAVY); set_bf(l, AVLRIGHTHEAVY); _need_rebalancing = 0; t = l; return; case AVLLEFTHEAVY: if (rthread(l)) t->lt = l; else t->lt = l->rt; set_lthread(t, rthread(l)); l->rt = t; set_rthread(l, 0); set_bf(t, AVLBALANCED); set_bf(l, AVLBALANCED); t = l; return; case AVLRIGHTHEAVY: { AVLNode* r = l->rt; set_rthread(l, lthread(r)); if (lthread(r)) l->rt = r; else l->rt = r->lt; r->lt = l; set_lthread(r, 0); set_lthread(t, rthread(r)); if (rthread(r)) t->lt = r; else t->lt = r->rt; r->rt = t; set_rthread(r, 0); if (bf(r) == AVLLEFTHEAVY) set_bf(t, AVLRIGHTHEAVY); else set_bf(t, AVLBALANCED); if (bf(r) == AVLRIGHTHEAVY) set_bf(l, AVLLEFTHEAVY); else set_bf(l, AVLBALANCED); set_bf(r, AVLBALANCED); t = r; return; } } } } } } void AVLSet::del( item) { if (root == 0) return; _need_rebalancing = 0; _already_found = 0; _found_node = 0; _target_item = &item; _del(root, root); if (_found_node) { delete(_found_node); if (--count == 0) root = 0; } } // build an ordered array of pointers to tree nodes back into a tree // we know that at least one element exists static AVLNode* _do_treeify(int lo, int hi, int& h) { int lh, rh; int mid = (lo + hi) / 2; AVLNode* t = _hold_nodes[mid]; if (lo > mid - 1) { set_lthread(t, 1); if (mid == 0) t->lt = 0; else t->lt = _hold_nodes[mid-1]; lh = 0; } else { set_lthread(t, 0); t->lt = _do_treeify(lo, mid-1, lh); } if (hi < mid + 1) { set_rthread(t, 1); if (mid == _max_hold_index) t->rt = 0; else t->rt = _hold_nodes[mid+1]; rh = 0; } else { set_rthread(t, 0); t->rt = _do_treeify(mid+1, hi, rh); } if (lh == rh) { set_bf(t, AVLBALANCED); h = lh + 1; } else if (lh == rh - 1) { set_bf(t, AVLRIGHTHEAVY); h = rh + 1; } else if (rh == lh - 1) { set_bf(t, AVLLEFTHEAVY); h = lh + 1; } else // can't happen abort(); return t; } static AVLNode* _treeify(int n) { AVLNode* t; if (n == 0) t = 0; else { int b; _max_hold_index = n-1; t = _do_treeify(0, _max_hold_index, b); } delete _hold_nodes; return t; } void AVLSet::_kill(AVLNode* t) { if (t != 0) { if (!lthread(t)) _kill(t->lt); if (!rthread(t)) _kill(t->rt); delete t; } } AVLSet::AVLSet(AVLSet& b) { if ((count = b.count) == 0) { root = 0; } else { _hold_nodes = new AVLNodePtr [count]; AVLNode* t = b.leftmost(); int i = 0; while (t != 0) { _hold_nodes[i++] = new AVLNode(t->item); t = b.succ(t); } root = _treeify(count); } } int AVLSet::operator == (AVLSet& y) { if (count != y.count) return 0; else { AVLNode* t = leftmost(); AVLNode* u = y.leftmost(); for (;;) { if (t == 0) return 1; else if (!(EQ(t->item, u->item))) return 0; else { t = succ(t); u = y.succ(u); } } } } int AVLSet::operator <= (AVLSet& y) { if (count > y.count) return 0; else { AVLNode* t = leftmost(); AVLNode* u = y.leftmost(); for (;;) { if (t == 0) return 1; else if (u == 0) return 0; int cmp = CMP(t->item, u->item); if (cmp == 0) { t = succ(t); u = y.succ(u); } else if (cmp < 0) return 0; else u = y.succ(u); } } } void AVLSet::operator |=(AVLSet& y) { AVLNode* t = leftmost(); AVLNode* u = y.leftmost(); int rsize = count + y.count; _hold_nodes = new AVLNodePtr [rsize]; int k = 0; for (;;) { if (t == 0) { while (u != 0) { _hold_nodes[k++] = new AVLNode(u->item); u = y.succ(u); } break; } else if (u == 0) { while (t != 0) { _hold_nodes[k++] = t; t = succ(t); } break; } int cmp = CMP(t->item, u->item); if (cmp == 0) { _hold_nodes[k++] = t; t = succ(t); u = y.succ(u); } else if (cmp < 0) { _hold_nodes[k++] = t; t = succ(t); } else { _hold_nodes[k++] = new AVLNode(u->item); u = y.succ(u); } } root = _treeify(k); count = k; } void AVLSet::operator &= (AVLSet& y) { AVLNode* t = leftmost(); AVLNode* u = y.leftmost(); int rsize = (count < y.count)? count : y.count; _hold_nodes = new AVLNodePtr [rsize]; int k = 0; for (;;) { if (t == 0) break; if (u == 0) { while (t != 0) { AVLNode* tmp = succ(t); delete t; t = tmp; } break; } int cmp = CMP(t->item, u->item); if (cmp == 0) { _hold_nodes[k++] = t; t = succ(t); u = y.succ(u); } else if (cmp < 0) { AVLNode* tmp = succ(t); delete t; t = tmp; } else u = y.succ(u); } root = _treeify(k); count = k; } void AVLSet::operator -=(AVLSet& y) { AVLNode* t = leftmost(); AVLNode* u = y.leftmost(); int rsize = count; _hold_nodes = new AVLNodePtr [rsize]; int k = 0; for (;;) { if (t == 0) break; else if (u == 0) { while (t != 0) { _hold_nodes[k++] = t; t = succ(t); } break; } int cmp = CMP(t->item, u->item); if (cmp == 0) { AVLNode* tmp = succ(t); delete t; t = tmp; u = y.succ(u); } else if (cmp < 0) { _hold_nodes[k++] = t; t = succ(t); } else u = y.succ(u); } root = _treeify(k); count = k; } int AVLSet::owns(Pix i) { if (i == 0) return 0; for (AVLNode* t = leftmost(); t != 0; t = succ(t)) if (Pix(t) == i) return 1; return 0; } int AVLSet::OK() { int v = 1; if (root == 0) v = count == 0; else { int n = 1; AVLNode* trail = leftmost(); AVLNode* t = succ(trail); while (t != 0) { ++n; v &= CMP(trail->item, t->item) < 0; trail = t; t = succ(t); } v &= n == count; } if (!v) error("invariant failure"); return v; } ./g++-include/gen/AVec.ccP100644 0 1 17756 5522102332 13620 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include #include ".AVec.h" /* The following brought to you by the department of redundancy department */ AVec& AVec::operator = (AVec& v) { if (len != 0 && len != v.capacity()) error("nonconformant vectors."); if (len == 0) s = new [len = v.capacity()]; if (s != v.vec()) { for (int i = 0; i < len; ++i) s[i] = v.vec()[i]; } return *this; } AVec& AVec::operator = ( f) { for (int i = 0; i < len; ++i) s[i] = f; return *this; } AVec concat(AVec & a, AVec & b) { int newl = a.capacity() + b.capacity(); * news = new [newl]; * p = news; * top = &(a.vec()[a.capacity()]); * t = a.vec(); while (t < top) *p++ = *t++; top = &(b.vec()[b.capacity()]); t = b.vec(); while (t < top) *p++ = *t++; return AVec(newl, news); } AVec combine(Combiner f, AVec& a, AVec& b) { int newl = (a.capacity() < b.capacity())? a.capacity() : b.capacity(); * news = new [newl]; * p = news; * top = &(a.vec()[newl]); * t = a.vec(); * u = b.vec(); while (t < top) *p++ = (*f)(*t++, *u++); return AVec(newl, news); } AVec reverse(AVec& a) { * news = new [a.capacity()]; if (a.capacity() != 0) { * lo = news; * hi = &(news[a.capacity() - 1]); while (lo < hi) { tmp = *lo; *lo++ = *hi; *hi-- = tmp; } } return AVec(a.capacity(), news); } AVec map(Mapper f, AVec& a) { * news = new [a.capacity()]; * p = news; * top = &(a.vec()[a.capacity()]); * t = a.vec(); while(t < top) *p++ = (*f)(*t++); return AVec(a.capacity(), news); } AVec AVec::at(int from, int n) { int to; if (n < 0) { n = len - from; to = len - 1; } else to = from + n - 1; if ((unsigned)from > (unsigned)to) range_error(); * news = new [n]; * p = news; * t = &(s[from]); * top = &(s[to]); while (t <= top) *p++ = *t++; return AVec(n, news); } AVec merge(AVec & a, AVec & b, Comparator f) { int newl = a.capacity() + b.capacity(); * news = new [newl]; * p = news; * topa = &(a.vec()[a.capacity()]); * as = a.vec(); * topb = &(b.vec()[b.capacity()]); * bs = b.vec(); for (;;) { if (as >= topa) { while (bs < topb) *p++ = *bs++; break; } else if (bs >= topb) { while (as < topa) *p++ = *as++; break; } else if ((*f)(*as, *bs) <= 0) *p++ = *as++; else *p++ = *bs++; } return AVec(newl, news); } AVec operator + (AVec& a, AVec& b) { a.check_len(b.capacity()); * news = new [a.capacity()]; * p = news; * top = &(a.vec()[a.capacity()]); * t = a.vec(); * u = b.vec(); while (t < top) *p++ = *t++ + *u++; return AVec(a.capacity(), news); } AVec operator - (AVec& a, AVec& b) { a.check_len(b.capacity()); * news = new [a.capacity()]; * p = news; * top = &(a.vec()[a.capacity()]); * t = a.vec(); * u = b.vec(); while (t < top) *p++ = *t++ - *u++; return AVec(a.capacity(), news); } AVec product (AVec& a, AVec& b) { a.check_len(b.capacity()); * news = new [a.capacity()]; * p = news; * top = &(a.vec()[a.capacity()]); * t = a.vec(); * u = b.vec(); while (t < top) *p++ = *t++ * *u++; return AVec(a.capacity(), news); } AVec quotient(AVec& a, AVec& b) { a.check_len(b.capacity()); * news = new [a.capacity()]; * p = news; * top = &(a.vec()[a.capacity()]); * t = a.vec(); * u = b.vec(); while (t < top) *p++ = *t++ / *u++; return AVec(a.capacity(), news); } AVec operator + (AVec& a, b) { * news = new [a.capacity()]; * p = news; * top = &(a.vec()[a.capacity()]); * t = a.vec(); while (t < top) *p++ = *t++ + b; return AVec(a.capacity(), news); } AVec operator - (AVec& a, b) { * news = new [a.capacity()]; * p = news; * top = &(a.vec()[a.capacity()]); * t = a.vec(); while (t < top) *p++ = *t++ - b; return AVec(a.capacity(), news); } AVec operator * (AVec& a, b) { * news = new [a.capacity()]; * p = news; * top = &(a.vec()[a.capacity()]); * t = a.vec(); while (t < top) *p++ = *t++ * b; return AVec(a.capacity(), news); } AVec operator / (AVec& a, b) { * news = new [a.capacity()]; * p = news; * top = &(a.vec()[a.capacity()]); * t = a.vec(); while (t < top) *p++ = *t++ / b; return AVec(a.capacity(), news); } AVec AVec::operator - () { * news = new [len]; * p = news; * top = &(s[len]); * t = s; while (t < top) *p++ = -(*t++); return AVec(len, news); } AVec& AVec::operator += (AVec& b) { check_len(b.capacity()); * u = b.vec(); * top = &(s[len]); * t = s; while (t < top) *t++ += *u++; return *this; } AVec& AVec::operator -= (AVec& b) { check_len(b.capacity()); * u = b.vec(); * top = &(s[len]); * t = s; while (t < top) *t++ -= *u++; return *this; } AVec& AVec::product(AVec& b) { check_len(b.capacity()); * u = b.vec(); * top = &(s[len]); * t = s; while (t < top) *t++ *= *u++; return *this; } AVec& AVec::quotient(AVec& b) { check_len(b.capacity()); * u = b.vec(); * top = &(s[len]); * t = s; while (t < top) *t++ /= *u++; return *this; } AVec& AVec::operator += ( b) { * top = &(s[len]); * t = s; while (t < top) *t++ += b; return *this; } AVec& AVec::operator -= ( b) { * top = &(s[len]); * t = s; while (t < top) *t++ -= b; return *this; } AVec& AVec::operator *= ( b) { * top = &(s[len]); * t = s; while (t < top) *t++ *= b; return *this; } AVec& AVec::operator /= ( b) { * top = &(s[len]); * t = s; while (t < top) *t++ /= b; return *this; } AVec::max() { if (len == 0) return 0; * top = &(s[len]); * t = s; res = *t++; for (; t < top; ++t) if (*t > res) res = *t; return res; } int AVec::max_index() { if (len == 0) return -1; int ind = 0; for (int i = 1; i < len; ++i) if (s[i] > s[ind]) ind = i; return ind; } AVec::min() { if (len == 0) return 0; * top = &(s[len]); * t = s; res = *t++; for (; t < top; ++t) if (*t < res) res = *t; return res; } int AVec::min_index() { if (len == 0) return -1; int ind = 0; for (int i = 1; i < len; ++i) if (s[i] < s[ind]) ind = i; return ind; } AVec::sum() { res = 0; * top = &(s[len]); * t = s; while (t < top) res += *t++; return res; } AVec::sumsq() { res = 0; * top = &(s[len]); * t = s; for (; t < top; ++t) res += *t * *t; return res; } operator * (AVec& a, AVec& b) { a.check_len(b.capacity()); * top = &(a.vec()[a.capacity()]); * t = a.vec(); * u = b.vec(); res = 0; while (t < top) res += *t++ * *u++; return res; } ./g++-include/gen/BSTSet.ccP100644 0 1 16127 5522102333 14076 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include ".BSTSet.h" /* traversal primitives */ BSTNode* BSTSet::leftmost() { BSTNode* t = root; if (t != 0) while (t->lt != 0) t = t->lt; return t; } BSTNode* BSTSet::rightmost() { BSTNode* t = root; if (t != 0) while (t->rt != 0) t = t->rt; return t; } BSTNode* BSTSet::succ(BSTNode* t) { if (t == 0) return 0; if (t->rt != 0) { t = t->rt; while (t->lt != 0) t = t->lt; return t; } else { for (;;) { if (t->par == 0 || t == t->par->lt) return t->par; else t = t->par; } } } BSTNode* BSTSet::pred(BSTNode* t) { if (t == 0) return 0; else if (t->lt != 0) { t = t->lt; while (t->rt != 0) t = t->rt; return t; } else { for (;;) { if (t->par == 0 || t == t->par->rt) return t->par; else t = t->par; } } } Pix BSTSet::seek( key) { BSTNode* t = root; for (;;) { if (t == 0) return 0; int comp = CMP(key, t->item); if (comp == 0) return Pix(t); else if (comp < 0) t = t->lt; else t = t->rt; } } Pix BSTSet::add( item) { if (root == 0) { ++count; root = new BSTNode(item); return Pix(root); } BSTNode* t = root; BSTNode* p = root; int comp; for (;;) { if (t == 0) { ++count; t = new BSTNode(item); if (comp > 0) p->lt = t; else p->rt = t; t->par = p; return Pix(t); } p = t; comp = CMP(t->item, item); if (comp == 0) return Pix(t); else if (comp > 0) t = t->lt; else t = t->rt; } } void BSTSet::del( key) { BSTNode* t = root; BSTNode* p = root; int comp; for (;;) { if (t == 0) return; comp = CMP(key, t->item); if (comp == 0) { --count; BSTNode* repl; if (t->lt == 0) repl = t->rt; else if (t->rt == 0) repl = t->lt; else { BSTNode* prepl = t; repl = t->lt; while (repl->rt != 0) { prepl = repl; repl = repl->rt; } if (prepl != t) { prepl->rt = repl->lt; if (prepl->rt != 0) prepl->rt->par = prepl; repl->lt = t->lt; if (repl->lt != 0) repl->lt->par = repl; } repl->rt = t->rt; if (repl->rt != 0) repl->rt->par = repl; } if (t == root) { root = repl; if (repl != 0) repl->par = 0; } else { if (t == p->lt) p->lt = repl; else p->rt = repl; if (repl != 0) repl->par = p; } delete t; return; } p = t; if (comp < 0) t = t->lt; else t = t->rt; } } void BSTSet::_kill(BSTNode* t) { if (t != 0) { _kill(t->lt); _kill(t->rt); delete t; } } BSTNode* BSTSet::_copy(BSTNode* t) { if (t == 0) return 0; else { BSTNode* u = new BSTNode(t->item, _copy(t->lt), _copy(t->rt)); if (u->lt != 0) u->lt->par = u; if (u->rt != 0) u->rt->par = u; return u; } } int BSTSet::operator == (BSTSet& y) { if (count != y.count) return 0; else { BSTNode* t = leftmost(); BSTNode* u = y.leftmost(); for (;;) { if (t == 0) return 1; else if (!EQ(t->item, u->item)) return 0; else { t = succ(t); u = y.succ(u); } } } } int BSTSet::operator <= (BSTSet& y) { if (count > y.count) return 0; else { BSTNode* t = leftmost(); BSTNode* u = y.leftmost(); for (;;) { if (t == 0) return 1; else if (u == 0) return 0; int cmp = CMP(t->item, u->item); if (cmp == 0) { t = succ(t); u = y.succ(u); } else if (cmp < 0) return 0; else u = y.succ(u); } } } // linear-time, zero space overhead binary tree rebalancing from // Stout & Warren, ``Tree rebalancing in linear space and time'' // CACM, Sept, 1986, p902. void BSTSet::balance() { if (count <= 2) return; // don't bother -- // also we assume non-null root, below // make re-attaching the root easy via trickery struct _fake_node { _fake_node *lt, *rt, *par; } fake_root; fake_root.rt = (_fake_node*)root; fake_root.par = 0; BSTNode* pseudo_root = (BSTNode*)&fake_root; // phase 1: tree-to-vine BSTNode* vine_tail = pseudo_root; BSTNode* remainder = root; while (remainder != 0) { if (remainder->lt == 0) { vine_tail = remainder; remainder = remainder->rt; } else { BSTNode* tmp = remainder->lt; remainder->lt = tmp->rt; if (remainder->lt != 0) remainder->lt->par = remainder; tmp->rt = remainder; remainder->par = tmp; vine_tail->rt = remainder = tmp; } } // phase 2: vine-to-tree // Uses the slightly simpler version adapted from // Day ``Balancing a binary tree'' Computer Journal, Nov. 1976, // since it's not generally important whether the `stray' leaves are // on the left or on the right. unsigned int spines = count - 1; while (spines > 1) { int compressions = spines >> 1; // compress every other node spines -= compressions + 1; // halve for next time BSTNode* scanner = pseudo_root; while (compressions-- > 0) { BSTNode* child = scanner->rt; BSTNode* grandchild = child->rt; scanner->rt = grandchild; grandchild->par = scanner; child->rt = grandchild->lt; if (child->rt != 0) child->rt->par = child; grandchild->lt = child; child->par = grandchild; scanner = grandchild; } } root = pseudo_root->rt; root->par = 0; } int BSTSet::OK() { int v = 1; if (root == 0) v = count == 0; else { int n = 1; BSTNode* trail = leftmost(); BSTNode* t = succ(trail); while (t != 0) { ++n; v &= CMP(trail->item, t->item) < 0; trail = t; t = succ(t); } v &= n == count; } if (!v) error("invariant failure"); return v; } ./g++-include/gen/Bag.ccP100644 0 1 3216 5522102334 13437 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include ".Bag.h" // error handling void Bag::error(const char* msg) { (*lib_error_handler)("Bag", msg); } Pix Bag::seek( item, Pix i) { if (i == 0) i = first(); else next(i); for (;i != 0 && (!(EQ((*this)(i), item))); next(i)); return i; } int Bag::owns(Pix p) { if (p == 0) return 0; for (Pix i = first(); i != 0; next(i)) if (i == p) return 1; return 0; } void Bag::remove( item) { int i = nof(item); while (i-- > 0) del(item); } int Bag::nof( item) { int n = 0; for (Pix p = first(); p; next(p)) if (EQ((*this)(p), item)) ++n; return n; } void Bag::clear() { Pix i = first(); while (i != 0) { del((*this)(i)); i = first(); } } ./g++-include/gen/CHBag.ccP100644 0 1 10401 5522102335 13665 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".CHBag.h" // The nodes are linked together serially via a version // of a trick used in some vtables: odd pointers are // actually links to the next table entry. // Not terrible, but not wonderful either static inline int goodCHptr(CHNode* t) { return ((((unsigned)t) & 1) == 0); } static inline CHNode* index_to_CHptr(int i) { return (CHNode*)((i << 1) + 1); } static inline int CHptr_to_index(CHNode* t) { return ( ((unsigned) t) >> 1); } CHBag::CHBag(unsigned int sz) { tab = (CHNode**)(new CHNodePtr[size = sz]); for (unsigned int i = 0; i < size; ++i) tab[i] = index_to_CHptr(i+1); count = 0; } CHBag::CHBag(CHBag& a) { tab = (CHNode**)(new CHNodePtr[size = a.size]); for (unsigned int i = 0; i < size; ++i) tab[i] = index_to_CHptr(i+1); count = 0; for (Pix p = a.first(); p; a.next(p)) add(a(p)); } Pix CHBag::seek( key, Pix i) { CHNode* p = (CHNode*)i; if (p == 0 || !EQ(p->hd, key)) { unsigned int h = HASH(key) % size; for (CHNode* t = tab[h]; goodCHptr(t); t = t->tl) if (EQ(key, t->hd)) return Pix(t); } else { for (p = p->tl; goodCHptr(p); p = p->tl) if (EQ(p->hd, key)) return Pix(p); } return 0; } int CHBag::nof( key) { int n = 0; unsigned int h = HASH(key) % size; for (CHNode* t = tab[h]; goodCHptr(t); t = t->tl) if (EQ(key, t->hd)) ++n; return n; } Pix CHBag::add( item) { unsigned int h = HASH(item) % size; CHNode* t = new CHNode(item); t->tl = tab[h]; tab[h] = t; ++count; return Pix(t); } void CHBag::del( key) { unsigned int h = HASH(key) % size; CHNode* t = tab[h]; CHNode* trail = t; while (goodCHptr(t)) { if (EQ(key, t->hd)) { if (trail == t) tab[h] = t->tl; else trail->tl = t->tl; delete t; --count; return; } trail = t; t = t->tl; } } void CHBag::remove( key) { unsigned int h = HASH(key) % size; CHNode* t = tab[h]; CHNode* trail = t; while (goodCHptr(t)) { if (EQ(key, t->hd)) { --count; if (trail == t) { tab[h] = t->tl; delete t; t = trail = tab[h]; } else { trail->tl = t->tl; delete t; t = trail->tl; } } else { trail = t; t = t->tl; } } } void CHBag::clear() { for (unsigned int i = 0; i < size; ++i) { CHNode* p = tab[i]; tab[i] = index_to_CHptr(i+1); while (goodCHptr(p)) { CHNode* nxt = p->tl; delete(p); p = nxt; } } count = 0; } Pix CHBag::first() { for (unsigned int i = 0; i < size; ++i) if (goodCHptr(tab[i])) return Pix(tab[i]); return 0; } void CHBag::next(Pix& p) { if (p == 0) return; CHNode* t = ((CHNode*)p)->tl; if (goodCHptr(t)) p = Pix(t); else { for (unsigned int i = CHptr_to_index(t); i < size; ++i) { if (goodCHptr(tab[i])) { p = Pix(tab[i]); return; } } p = 0; } } int CHBag::OK() { int v = tab != 0; int n = 0; for (unsigned int i = 0; i < size; ++i) { for (CHNode* p = tab[i]; goodCHptr(p); p = p->tl) ++n; v &= CHptr_to_index(p) == i + 1; } v &= count == n; if (!v) error("invariant failure"); return v; } ./g++-include/gen/CHMap.ccP100644 0 1 7240 5522102335 13700 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include "..CHMap.h" // The nodes are linked together serially via a version // of a trick used in some vtables: odd pointers are // actually links to the next table entry. // Not terrible, but not wonderful either static inline int goodCHptr(CHNode* t) { return ((((unsigned)t) & 1) == 0); } static inline CHNode* index_to_CHptr(int i) { return (CHNode*)((i << 1) + 1); } static inline int CHptr_to_index(CHNode* t) { return ( ((unsigned) t) >> 1); } CHMap::CHMap( dflt, unsigned int sz) :Map(dflt) { tab = (CHNode**)(new CHNodePtr[size = sz]); for (unsigned int i = 0; i < size; ++i) tab[i] = index_to_CHptr(i+1); count = 0; } CHMap::CHMap(CHMap& a) :Map(a.def) { tab = (CHNode**)(new CHNodePtr[size = a.size]); for (unsigned int i = 0; i < size; ++i) tab[i] = index_to_CHptr(i+1); count = 0; for (Pix p = a.first(); p; a.next(p)) (*this)[a.key(p)] = a.contents(p); } Pix CHMap::seek( key) { unsigned int h = HASH(key) % size; for (CHNode* t = tab[h]; goodCHptr(t); t = t->tl) if (EQ(key, t->hd)) return Pix(t); return 0; } & CHMap::operator []( item) { unsigned int h = HASH(item) % size; for (CHNode* t = tab[h]; goodCHptr(t); t = t->tl) if (EQ(item, t->hd)) return t->cont; t = new CHNode(item, def, tab[h]); tab[h] = t; ++count; return t->cont; } void CHMap::del( key) { unsigned int h = HASH(key) % size; CHNode* t = tab[h]; CHNode* trail = t; while (goodCHptr(t)) { if (EQ(key, t->hd)) { if (trail == t) tab[h] = t->tl; else trail->tl = t->tl; delete t; --count; return; } trail = t; t = t->tl; } } void CHMap::clear() { for (unsigned int i = 0; i < size; ++i) { CHNode* p = tab[i]; tab[i] = index_to_CHptr(i+1); while (goodCHptr(p)) { CHNode* nxt = p->tl; delete(p); p = nxt; } } count = 0; } Pix CHMap::first() { for (unsigned int i = 0; i < size; ++i) if (goodCHptr(tab[i])) return Pix(tab[i]); return 0; } void CHMap::next(Pix& p) { CHNode* t = ((CHNode*)p)->tl; if (goodCHptr(t)) p = Pix(t); else { for (unsigned int i = CHptr_to_index(t); i < size; ++i) { if (goodCHptr(tab[i])) { p = Pix(tab[i]); return; } } p = 0; } } int CHMap::OK() { int v = tab != 0; int n = 0; for (unsigned int i = 0; i < size; ++i) { for (CHNode* p = tab[i]; goodCHptr(p); p = p->tl) ++n; v &= CHptr_to_index(p) == i + 1; } v &= count == n; if (!v) error("invariant failure"); return v; } ./g++-include/gen/CHNode.ccP100644 0 1 1606 5522102336 14051 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1992 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".CHNode.h" ./g++-include/gen/CHSet.ccP100644 0 1 13725 5522102337 13745 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".CHSet.h" // A CHSet is implemented as an array (tab) of buckets, each of which // contains a pointer to a list of CHNodes. Each node contains a // pointer to the next node in the list, and a pointer to the . // The end of the list is marked by a next node pointer which is odd // when considered as an integer (least significant bit = 1). The // assumption is that CHNodes will all begin on even addresses. If // the odd pointer is right-shifted by one bit, it becomes the index // within the tab array of the next bucket (that is, bucket i has // next bucket pointer 2*(i+1)+1). // The bucket pointers are initialized by the constructor and // used to support the next(Pix&) method. // This implementation is not portable to machines with different // pointer and integer sizes, or on which CHNodes might be aligned on // odd byte boundaries, but allows the same pointer to be used for // chaining within a bucket and to the next bucket. static inline int goodCHptr(CHNode* t) { return ((((unsigned)t) & 1) == 0); } static inline CHNode* index_to_CHptr(int i) { return (CHNode*)((i << 1) + 1); } static inline int CHptr_to_index(CHNode* t) { return ( ((unsigned) t) >> 1); } CHSet::CHSet(unsigned int sz) { tab = (CHNode**)(new CHNodePtr[size = sz]); for (unsigned int i = 0; i < size; ++i) tab[i] = index_to_CHptr(i+1); count = 0; } CHSet::CHSet(CHSet& a) { tab = (CHNode**)(new CHNodePtr[size = a.size]); for (unsigned int i = 0; i < size; ++i) tab[i] = index_to_CHptr(i+1); count = 0; for (Pix p = a.first(); p; a.next(p)) add(a(p)); } Pix CHSet::seek( key) { unsigned int h = HASH(key) % size; for (CHNode* t = tab[h]; goodCHptr(t); t = t->tl) if (EQ(key, t->hd)) return Pix(t); return 0; } Pix CHSet::add( item) { unsigned int h = HASH(item) % size; for (CHNode* t = tab[h]; goodCHptr(t); t = t->tl) if (EQ(item, t->hd)) return Pix(t); ++count; t = new CHNode(item, tab[h]); tab[h] = t; return Pix(t); } void CHSet::del( key) { unsigned int h = HASH(key) % size; CHNode* t = tab[h]; CHNode* trail = t; while (goodCHptr(t)) { if (EQ(key, t->hd)) { if (trail == t) tab[h] = t->tl; else trail->tl = t->tl; delete t; --count; return; } trail = t; t = t->tl; } } void CHSet::clear() { for (unsigned int i = 0; i < size; ++i) { CHNode* p = tab[i]; tab[i] = index_to_CHptr(i+1); while (goodCHptr(p)) { CHNode* nxt = p->tl; delete(p); p = nxt; } } count = 0; } Pix CHSet::first() { for (unsigned int i = 0; i < size; ++i) if (goodCHptr(tab[i])) return Pix(tab[i]); return 0; } void CHSet::next(Pix& p) { if (p == 0) return; CHNode* t = ((CHNode*)p)->tl; if (goodCHptr(t)) p = Pix(t); else { for (unsigned int i = CHptr_to_index(t); i < size; ++i) { if (goodCHptr(tab[i])) { p = Pix(tab[i]); return; } } p = 0; } } int CHSet::operator == (CHSet& b) { if (count != b.count) return 0; else { CHNode* p; for (unsigned int i = 0; i < size; ++i) for (p = tab[i]; goodCHptr(p); p = p->tl) if (b.seek(p->hd) == 0) return 0; for (i = 0; i < b.size; ++i) for (p = b.tab[i]; goodCHptr(p); p = p->tl) if (seek(p->hd) == 0) return 0; return 1; } } int CHSet::operator <= (CHSet& b) { if (count > b.count) return 0; else { for (unsigned int i = 0; i < size; ++i) for (CHNode* p = tab[i]; goodCHptr(p); p = p->tl) if (b.seek(p->hd) == 0) return 0; return 1; } } void CHSet::operator |= (CHSet& b) { if (&b == this || b.count == 0) return; for (unsigned int i = 0; i < b.size; ++i) for (CHNode* p = b.tab[i]; goodCHptr(p); p = p->tl) add(p->hd); } void CHSet::operator &= (CHSet& b) { for (unsigned int i = 0; i < size; ++i) { CHNode* t = tab[i]; CHNode* trail = t; while (goodCHptr(t)) { CHNode* nxt = t->tl; if (b.seek(t->hd) == 0) { if (trail == tab[i]) trail = tab[i] = nxt; else trail->tl = nxt; delete t; --count; } else trail = t; t = nxt; } } } void CHSet::operator -= (CHSet& b) { for (unsigned int i = 0; i < size; ++i) { CHNode* t = tab[i]; CHNode* trail = t; while (goodCHptr(t)) { CHNode* nxt = t->tl; if (b.seek(t->hd) != 0) { if (trail == tab[i]) trail = tab[i] = nxt; else trail->tl = nxt; delete t; --count; } else trail = t; t = nxt; } } } int CHSet::OK() { int v = tab != 0; int n = 0; for (unsigned int i = 0; i < size; ++i) { for (CHNode* p = tab[i]; goodCHptr(p); p = p->tl) ++n; v &= CHptr_to_index(p) == i + 1; } v &= count == n; if (!v) error("invariant failure"); return v; } ./g++-include/gen/DLDeque.ccP100644 0 1 107 5522102340 14202 0ustar rootdaemon#ifdef __GNUG__ #pragma implementation #endif #include ".DLDeque.h" ./g++-include/gen/DLList.ccP100644 0 1 13177 5522102341 14126 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- // WARNING: This file is obsolete. Use ../DLList.cc, if you can. /* Copyright (C) 1988 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include #include #include ".DLList.h" // error handling void DLList::error(const char* msg) { (*lib_error_handler)("DLList", msg); } int DLList::length() { int l = 0; DLListNode* t = h; if (t != 0) do { ++l; t = t->fd; } while (t != h); return l; } DLList::DLList(const DLList& a) { if (a.h == 0) h = 0; else { DLListNode* p = a.h; DLListNode* t = new DLListNode(p->hd); h = t; p = p->fd; while (p != a.h) { DLListNode* n = new DLListNode(p->hd); t->fd = n; n->bk = t; t = n; p = p->fd; } t->fd = h; h->bk = t; return; } } DLList& DLList::operator = (const DLList& a) { if (h != a.h) { clear(); if (a.h != 0) { DLListNode* p = a.h; DLListNode* t = new DLListNode(p->hd); h = t; p = p->fd; while (p != a.h) { DLListNode* n = new DLListNode(p->hd); t->fd = n; n->bk = t; t = n; p = p->fd; } t->fd = h; h->bk = t; } } return *this; } void DLList::clear() { if (h == 0) return; DLListNode* p = h->fd; h->fd = 0; h = 0; while (p != 0) { DLListNode* nxt = p->fd; delete(p); p = nxt; } } Pix DLList::prepend( item) { DLListNode* t = new DLListNode(item); if (h == 0) t->fd = t->bk = h = t; else { t->fd = h; t->bk = h->bk; h->bk->fd = t; h->bk = t; h = t; } return Pix(t); } Pix DLList::append( item) { DLListNode* t = new DLListNode(item); if (h == 0) t->fd = t->bk = h = t; else { t->bk = h->bk; t->bk->fd = t; t->fd = h; h->bk = t; } return Pix(t); } Pix DLList::ins_after(Pix p, item) { if (p == 0) return prepend(item); DLListNode* u = (DLListNode*) p; DLListNode* t = new DLListNode(item, u, u->fd); u->fd->bk = t; u->fd = t; return Pix(t); } Pix DLList::ins_before(Pix p, item) { if (p == 0) error("null Pix"); DLListNode* u = (DLListNode*) p; DLListNode* t = new DLListNode(item, u->bk, u); u->bk->fd = t; u->bk = t; if (u == h) h = t; return Pix(t); } void DLList::join(DLList& b) { DLListNode* t = b.h; b.h = 0; if (h == 0) h = t; else if (t != 0) { DLListNode* l = t->bk; h->bk->fd = t; t->bk = h->bk; h->bk = l; l->fd = h; } } int DLList::owns(Pix p) { DLListNode* t = h; if (t != 0 && p != 0) { do { if (Pix(t) == p) return 1; t = t->fd; } while (t != h); } return 0; } void DLList::del(Pix& p, int dir) { if (p == 0) error("null Pix"); DLListNode* t = (DLListNode*) p; if (t->fd == t) { h = 0; p = 0; } else { if (dir < 0) { if (t == h) p = 0; else p = Pix(t->bk); } else { if (t == h->bk) p = 0; else p = Pix(t->fd); } t->bk->fd = t->fd; t->fd->bk = t->bk; if (t == h) h = t->fd; } delete t; } void DLList::del_after(Pix& p) { if (p == 0) { del_front(); return; } DLListNode* b = (DLListNode*) p; DLListNode* t = b->fd; if (b == t) { h = 0; p = 0; } else { t->bk->fd = t->fd; t->fd->bk = t->bk; if (t == h) h = t->fd; } delete t; } DLList::remove_front() { if (h == 0) error("remove_front of empty list"); DLListNode* t = h; res = t->hd; if (h->fd == h) h = 0; else { h->fd->bk = h->bk; h->bk->fd = h->fd; h = h->fd; } delete t; return res; } void DLList::del_front() { if (h == 0) error("del_front of empty list"); DLListNode* t = h; if (h->fd == h) h = 0; else { h->fd->bk = h->bk; h->bk->fd = h->fd; h = h->fd; } delete t; } DLList::remove_rear() { if (h == 0) error("remove_rear of empty list"); DLListNode* t = h->bk; res = t->hd; if (h->fd == h) h = 0; else { t->fd->bk = t->bk; t->bk->fd = t->fd; } delete t; return res; } void DLList::del_rear() { if (h == 0) error("del_rear of empty list"); DLListNode* t = h->bk; if (h->fd == h) h = 0; else { t->fd->bk = t->bk; t->bk->fd = t->fd; } delete t; } int DLList::OK() { int v = 1; if (h != 0) { DLListNode* t = h; long count = LONG_MAX; // Lots of chances to find h! do { count--; v &= t->bk->fd == t; v &= t->fd->bk == t; t = t->fd; } while (v && count > 0 && t != h); v &= count > 0; } if (!v) error("invariant failure"); return v; } ./g++-include/gen/Deque.ccP100644 0 1 260 5522102342 13764 0ustar rootdaemon#ifdef __GNUG__ #pragma implementation #endif #include ".Deque.h" Deque::~Deque() {} void Deque::error(const char* msg) { (*lib_error_handler)("Deque", msg); } ./g++-include/gen/FPQueue.ccP100644 0 1 107 5522102343 14234 0ustar rootdaemon#ifdef __GNUG__ #pragma implementation #endif #include ".FPQueue.h" ./g++-include/gen/FPStack.ccP100644 0 1 107 5522102343 14215 0ustar rootdaemon#ifdef __GNUG__ #pragma implementation #endif #include ".FPStack.h" ./g++-include/gen/FPlex.ccP100644 0 1 7614 5522102344 13773 0ustar rootdaemon// 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".FPlex.h" FPlex:: FPlex() { lo = fnc = 0; csize = DEFAULT_INITIAL_CAPACITY; * data = new [csize]; hd = new IChunk(data, lo, lo, fnc, csize); } FPlex:: FPlex(int maxsize) { if (maxsize == 0) error("invalid constructor specification"); lo = fnc = 0; if (maxsize > 0) { csize = maxsize; * data = new [csize]; hd = new IChunk(data, lo, lo, fnc, csize); } else { csize = -maxsize; * data = new [csize]; hd = new IChunk(data, maxsize, lo, fnc, fnc); } } FPlex:: FPlex(int l, int maxsize) { if (maxsize == 0) error("invalid constructor specification"); lo = fnc = l; if (maxsize > 0) { csize = maxsize; * data = new [csize]; hd = new IChunk(data, lo, lo, fnc, csize+lo); } else { csize = -maxsize; * data = new [csize]; hd = new IChunk(data, maxsize+lo, lo, fnc, fnc); } } FPlex:: FPlex(int l, int hi, const initval, int maxsize) { lo = l; fnc = hi + 1; if (maxsize >= 0) { csize = maxsize; if (csize < fnc - lo) csize = fnc - lo; * data = new [csize]; hd = new IChunk(data, lo, lo, fnc, csize); } else { csize = -maxsize; if (csize < fnc - lo) csize = fnc - lo; * data = new [csize]; hd = new IChunk(data, -csize, lo, fnc, fnc); } fill(initval); } FPlex::FPlex(const FPlex& a) { lo = a.lo; fnc = a.fnc; csize = fnc - lo; if (csize < a.csize) csize = a.csize; * data = new [csize]; hd = new IChunk(data, lo, lo, fnc, lo+csize); for (int i = a.low(); i < a.fence(); a.next(i)) (*this)[i] = a[i]; } void FPlex::operator= (const FPlex& a) { if (&a != this) { del_chunk(hd); lo = a.lo; fnc = a.fnc; csize = fnc - lo; if (csize < a.csize) csize = a.csize; * data = new [csize]; hd = new IChunk(data, lo, lo, fnc, lo+csize); for (int i = a.low(); i < a.fence(); a.next(i)) (*this)[i] = a[i]; } } void FPlex::reverse() { tmp; int l = lo; int h = fnc - 1; while (l < h) { tmp = (*this)[l]; (*this)[l] = (*this)[h]; (*this)[h] = tmp; next(l); prev(h); } } void FPlex::fill(const x) { for (int i = lo; i < fnc; ++i) (*this)[i] = x; } void FPlex::fill(const x, int lo, int hi) { for (int i = lo; i <= hi; ++i) (*this)[i] = x; } void FPlex::clear() { if (fnc != lo) { hd->clear(lo); fnc = lo; } } int FPlex::OK () const { int v = hd != 0; // hd exists v &= hd->IChunk::OK(); // and is OK v &= fnc - lo <= hd->size(); // and has enough space v &= lo <= fnc; // plex indices consistent v &= lo == hd->low_index(); // and match those v &= fnc == hd->fence_index(); // of chunk v &= one_chunk(); // and only one chunk if (!v) error("invariant failure"); return v; } ./g++-include/gen/List.ccP100644 0 1 42125 5522102345 13705 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include ".List.h" ListNode NilListNode; class init_NilListNode { public: init_NilListNode() { NilListNode.tl = &NilListNode; NilListNode.ref = -1; } }; static init_NilListNode NilListNode_initializer; List& List::operator = (List& a) { reference(a.P); dereference(P); P = a.P; return *this; } List::pop() { res = P->hd; ListNode* tail = P->tl; reference(tail); dereference(P); P = tail; return res; } void List::set_tail(List& a) { reference(a.P); dereference(P->tl); P->tl = a.P; } List List::nth(int n) { for (ListNode* p = P; n-- > 0; p = p->tl); reference(p); return List(p); } List List::last() { ListNode* p = P; if (p != &NilListNode) while (p->tl != &NilListNode) p = p->tl; reference(p); return List(p); } void List::append(List& l) { ListNode* p = P; ListNode* a = l.P; reference(a); if (p != &NilListNode) { while (p->tl != &NilListNode) p = p->tl; p->tl = a; } else P = a; } int List::length() { int l = 0; for (ListNode* p = P; p != &NilListNode; p = p->tl) ++l; return l; } & List::operator [] (int n) { for (ListNode* p = P; n-- > 0; p = p->tl); return (p->hd); } int operator == (List& x, List& y) { ListNode* a = x.P; ListNode* b = y.P; for (;;) { if (a == &NilListNode) return b == &NilListNode; else if (b == &NilListNode) return 0; else if (EQ(a->hd, b->hd)) { a = a->tl; b = b->tl; } else return 0; } } void List::apply(Procedure f) { for(ListNode* p = P; p != &NilListNode; p = p->tl) (*f)((p->hd)); } void List::subst( old, repl) { for(ListNode* p = P; p != &NilListNode; p = p->tl) if (EQ(p->hd, old)) p->hd = repl; } List::reduce(Combiner f, base) { r = base; for(ListNode* p = P; p != &NilListNode; p = p->tl) r = (*f)(r, (p->hd)); return r; } int List::position( targ) { int l = 0; ListNode* p = P; for (;;) { if (p == &NilListNode) return -1; else if (EQ(p->hd, targ)) return l; else { ++l; p = p->tl; } } } int List::contains( targ) { ListNode* p = P; for (;;) { if (p == &NilListNode) return 0; else if (EQ(p->hd, targ)) return 1; else p = p->tl; } } List List::find( targ) { ListNode* p = P; while (p != &NilListNode && !EQ(p->hd, targ)) p=p->tl; reference(p); return List(p); } Pix List::seek( targ) { ListNode* p = P; for (;;) { if (p == &NilListNode) return 0; else if (EQ(p->hd, targ)) return Pix(p); else p = p->tl; } } int List::owns(Pix i) { ListNode* p = P; for (;;) { if (p == &NilListNode) return 0; else if (Pix(p) == i) return 1; else p = p->tl; } } List List::find(List& target) { ListNode* targ = target.P; if (targ == &NilListNode) return List(targ); ListNode* p = P; while (p != &NilListNode) { if (EQ(p->hd, targ->hd)) { ListNode* a = p->tl; ListNode* t = targ->tl; for(;;) { if (t == &NilListNode) { reference(p); return List(p); } else if (a == &NilListNode || !EQ(a->hd, t->hd)) break; else { a = a->tl; t = t->tl; } } } p = p->tl; } return List(&NilListNode); } int List::contains(List& target) { ListNode* targ = target.P; if (targ == &NilListNode) return 0; ListNode* p = P; while (p != &NilListNode) { if (EQ(p->hd, targ->hd)) { ListNode* a = p->tl; ListNode* t = targ->tl; for(;;) { if (t == &NilListNode) return 1; else if (a == &NilListNode || !EQ(a->hd, t->hd)) break; else { a = a->tl; t = t->tl; } } } p = p->tl; } return 0; } void List::del( targ) { ListNode* h = P; for (;;) { if (h == &NilListNode) { P = h; return; } else if (EQ(h->hd, targ)) { ListNode* nxt = h->tl; reference(nxt); dereference(h); h = nxt; } else break; } ListNode* trail = h; ListNode* p = h->tl; while (p != &NilListNode) { if (EQ(p->hd, targ)) { ListNode* nxt = p->tl; reference(nxt); dereference(p); trail->tl = nxt; p = nxt; } else { trail = p; p = p->tl; } } P = h; } void List::del(Predicate f) { ListNode* h = P; for (;;) { if (h == &NilListNode) { P = h; return; } else if ((*f)(h->hd)) { ListNode* nxt = h->tl; reference(nxt); dereference(h); h = nxt; } else break; } ListNode* trail = h; ListNode* p = h->tl; while (p != &NilListNode) { if ((*f)(p->hd)) { ListNode* nxt = p->tl; reference(nxt); dereference(p); trail->tl = nxt; p = nxt; } else { trail = p; p = p->tl; } } P = h; } void List::select(Predicate f) { ListNode* h = P; for (;;) { if (h == &NilListNode) { P = h; return; } else if (!(*f)(h->hd)) { ListNode* nxt = h->tl; reference(nxt); dereference(h); h = nxt; } else break; } ListNode* trail = h; ListNode* p = h->tl; while (p != &NilListNode) { if (!(*f)(p->hd)) { ListNode* nxt = p->tl; reference(nxt); dereference(p); trail->tl = nxt; p = nxt; } else { trail = p; p = p->tl; } } P = h; } void List::reverse() { ListNode* l = &NilListNode; ListNode* p = P; while (p != &NilListNode) { ListNode* nxt = p->tl; p->tl = l; l = p; p = nxt; } P = l; } List copy(List& x) { ListNode* a = x.P; if (a == &NilListNode) return List(a); else { ListNode* h = newListNode(a->hd); ListNode* trail = h; for(a = a->tl; a != &NilListNode; a = a->tl) { ListNode* n = newListNode(a->hd); trail->tl = n; trail = n; } trail->tl = &NilListNode; return List(h); } } List subst( old, repl, List& x) { ListNode* a = x.P; if (a == &NilListNode) return List(a); else { ListNode* h = new ListNode; h->ref = 1; if (EQ(a->hd, old)) h->hd = repl; else h->hd = a->hd; ListNode* trail = h; for(a = a->tl; a != &NilListNode; a = a->tl) { ListNode* n = new ListNode; n->ref = 1; if (EQ(a->hd, old)) n->hd = repl; else n->hd = a->hd; trail->tl = n; trail = n; } trail->tl = &NilListNode; return List(h); } } List combine(Combiner f, List& x, List& y) { ListNode* a = x.P; ListNode* b = y.P; if (a == &NilListNode || b == &NilListNode) return List(&NilListNode); else { ListNode* h = newListNode((*f)(a->hd, b->hd)); ListNode* trail = h; a = a->tl; b = b->tl; while (a != &NilListNode && b != &NilListNode) { ListNode* n = newListNode((*f)(a->hd, b->hd)); trail->tl = n; trail = n; a = a->tl; b = b->tl; } trail->tl = &NilListNode; return List(h); } } List reverse(List& x) { ListNode* a = x.P; if (a == &NilListNode) return List(a); else { ListNode* l = newListNode(a->hd); l->tl = &NilListNode; for(a = a->tl; a != &NilListNode; a = a->tl) { ListNode* n = newListNode(a->hd); n->tl = l; l = n; } return List(l); } } List append(List& x, List& y) { ListNode* a = x.P; ListNode* b = y.P; reference(b); if (a != &NilListNode) { ListNode* h = newListNode(a->hd); ListNode* trail = h; for(a = a->tl; a != &NilListNode; a = a->tl) { ListNode* n = newListNode(a->hd); trail->tl = n; trail = n; } trail->tl = b; return List(h); } else return List(b); } void List::prepend(List& y) { ListNode* b = y.P; if (b != &NilListNode) { ListNode* h = newListNode(b->hd); ListNode* trail = h; for(b = b->tl; b != &NilListNode; b = b->tl) { ListNode* n = newListNode(b->hd); trail->tl = n; trail = n; } trail->tl = P; P = h; } } List concat(List& x, List& y) { ListNode* a = x.P; ListNode* b = y.P; if (a != &NilListNode) { ListNode* h = newListNode(a->hd); ListNode* trail = h; for(a = a->tl; a != &NilListNode; a = a->tl) { ListNode* n = newListNode(a->hd); trail->tl = n; trail = n; }; for(;b != &NilListNode; b = b->tl) { ListNode* n = newListNode(b->hd); trail->tl = n; trail = n; } trail->tl = &NilListNode; return List(h); } else if (b != &NilListNode) { ListNode* h = newListNode(b->hd); ListNode* trail = h; for(b = b->tl; b != &NilListNode; b = b->tl) { ListNode* n = newListNode(b->hd); trail->tl = n; trail = n; } trail->tl = &NilListNode; return List(h); } else return List(&NilListNode); } List select(Predicate f, List& x) { ListNode* a = x.P; ListNode* h = &NilListNode; while (a != &NilListNode) { if ((*f)(a->hd)) { h = newListNode(a->hd); ListNode* trail = h; for(a = a->tl; a != &NilListNode; a = a->tl) { if ((*f)(a->hd)) { ListNode* n = newListNode(a->hd); trail->tl = n; trail = n; } } trail->tl = &NilListNode; break; } else a = a->tl; } return List(h); } List remove(Predicate f, List& x) { ListNode* a = x.P; ListNode* h = &NilListNode; while (a != &NilListNode) { if (!(*f)(a->hd)) { h = newListNode(a->hd); ListNode* trail = h; for(a = a->tl; a != &NilListNode; a = a->tl) { if (!(*f)(a->hd)) { ListNode* n = newListNode(a->hd); trail->tl = n; trail = n; } } trail->tl = &NilListNode; break; } else a = a->tl; } return List(h); } List remove( targ, List& x) { ListNode* a = x.P; ListNode* h = &NilListNode; while (a != &NilListNode) { if (!(EQ(a->hd, targ))) { h = newListNode(a->hd); ListNode* trail = h; for(a = a->tl; a != &NilListNode; a = a->tl) { if (!EQ(a->hd, targ)) { ListNode* n = newListNode(a->hd); trail->tl = n; trail = n; } } trail->tl = &NilListNode; break; } else a = a->tl; } return List(h); } List map(Mapper f, List& x) { ListNode* a = x.P; ListNode* h = &NilListNode; if (a != &NilListNode) { h = newListNode((*f)(a->hd)); ListNode* trail = h; for(a = a->tl; a != &NilListNode; a = a->tl) { ListNode* n = newListNode((*f)(a->hd)); trail->tl = n; trail = n; } trail->tl = &NilListNode; } return List(h); } List merge(List& x, List& y, Comparator f) { ListNode* a = x.P; ListNode* b = y.P; if (a == &NilListNode) { if (b == &NilListNode) return List(&NilListNode); else return copy(y); } else if (b == &NilListNode) return copy(x); ListNode* h = new ListNode; h->ref = 1; if ((*f)(a->hd, b->hd) <= 0) { h->hd = a->hd; a = a->tl; } else { h->hd = b->hd; b = b->tl; } ListNode* r = h; for(;;) { if (a == &NilListNode) { while (b != &NilListNode) { ListNode* n = new ListNode; n->ref = 1; n->hd = b->hd; r->tl = n; r = n; b = b->tl; } r->tl = &NilListNode; return List(h); } else if (b == &NilListNode) { while (a != &NilListNode) { ListNode* n = new ListNode; n->ref = 1; n->hd = a->hd; r->tl = n; r = n; a = a->tl; } r->tl = &NilListNode; return List(h); } else if ((*f)(a->hd, b->hd) <= 0) { ListNode* n = new ListNode; n->ref = 1; n->hd = a->hd; r->tl = n; r = n; a = a->tl; } else { ListNode* n = new ListNode; n->ref = 1; n->hd = b->hd; r->tl = n; r = n; b = b->tl; } } } void List::sort(Comparator f) { // strategy: place runs in queue, merge runs until done // This is often very fast if (P == &NilListNode || P->tl == &NilListNode) return; int qlen = 250; // guess a good queue size, realloc if necessary ListNode** queue = (ListNode**)malloc(qlen * sizeof(ListNode*)); ListNode* h = P; ListNode* a = h; ListNode* b = a->tl; int qin = 0; while (b != &NilListNode) { if ((*f)(a->hd, b->hd) > 0) { if (h == a) // minor optimization: ensure runlen >= 2 { h = b; a->tl = b->tl; b->tl = a; b = a->tl; } else { if (qin >= qlen) { qlen *= 2; queue = (ListNode**)realloc(queue, qlen * sizeof(ListNode*)); } queue[qin++] = h; a->tl = &NilListNode; h = a = b; b = b->tl; } } else { a = b; b = b->tl; } } int count = qin; queue[qin] = h; if (++qin >= qlen) qin = 0; int qout = 0; while (count-- > 0) { a = queue[qout]; if (++qout >= qlen) qout = 0; b = queue[qout]; if (++qout >= qlen) qout = 0; if ((*f)(a->hd, b->hd) <= 0) { h = a; a = a->tl; } else { h = b; b = b->tl; } queue[qin] = h; if (++qin >= qlen) qin = 0; for (;;) { if (a == &NilListNode) { h->tl = b; break; } else if (b == &NilListNode) { h->tl = a; break; } else if ((*f)(a->hd, b->hd) <= 0) { h->tl = a; h = a; a = a->tl; } else { h->tl = b; h = b; b = b->tl; } } } P = queue[qout]; free(queue); } int List::list_length() { ListNode* fast = P; if (fast == &NilListNode) return 0; ListNode* slow = fast->tl; if (slow == &NilListNode) return 1; fast = slow->tl; int n = 2; for (;;) { if (fast == &NilListNode) return n; else if (fast->tl == &NilListNode) return n+1; else if (fast == slow) return -1; else { n += 2; fast = fast->tl->tl; slow = slow->tl; } } } void List::error(const char* msg) { (*lib_error_handler)("List", msg); } int List::OK() { int v = P != 0; // have a node // check that all nodes OK, even if circular: ListNode* fast = P; if (fast != &NilListNode) { v &= fast->ref != 0; ListNode* slow = fast->tl; v &= slow->ref != 0; if (v && slow != &NilListNode) { fast = slow->tl; v &= fast->ref != 0; while (v) { if (fast == &NilListNode) break; else if (fast->tl == &NilListNode) break; else if (fast == slow) break; else { v &= fast->ref != 0 && slow->ref != 0; fast = fast->tl->tl; slow = slow->tl; } } } } if (!v) error ("invariant failure"); return v; } ./g++-include/gen/MPlex.ccP100644 0 1 40772 5522102346 14026 0ustar rootdaemon// 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".MPlex.h" // MChunk support MChunk::MChunk(* d, int baseidx, int lowidx, int fenceidx, int topidx) : IChunk(d, baseidx, lowidx, fenceidx, topidx) { unused = fence - low; unsigned msize = (top - base)/_MAP_BITS + 1; map = (unsigned long *) (new long[msize]); memset((void*)map, 0, msize * sizeof(long)); } void MChunk:: shrink_high () { if (fence <= low) empty_error(); --fence; if (!valid(fence)) --unused; else free(fence); reset_high(); } void MChunk:: shrink_low () { if (fence <= low) empty_error(); if (!valid(low)) --unused; else free(low); ++low; reset_low(); } void MChunk::clear(int lo) { int s = top - base; low = base = fence = lo; top = base + s; unused = 0; memset((void*)map, 0, ((top - base)/_MAP_BITS + 1) * sizeof(long)); } void MChunk::cleardown(int hi) { int s = top - base; low = top = fence = hi; base = top - s; unused = 0; memset((void*)map, 0, ((top - base)/_MAP_BITS + 1) * sizeof(long)); } int MChunk::del(int idx) { if (idx < low || idx >= fence) index_error(); int v = valid(idx); if (v) { free(idx); ++unused; } return v; } int MChunk::undel(int idx) { if (idx < low || idx >= fence) index_error(); int v = valid(idx); if (!v) { mark(idx); --unused; } return v; } int MChunk::unused_index() const { if (unused_indices() == 0) index_error(); int slot; if (low == base) // can traverse 32 slots at a time { int blk = 0; while (map[blk] == ~0L) ++blk; slot = blk * _MAP_BITS + base; } else slot = low; while(valid(slot)) ++slot; return slot; } int MChunk::first_index() const { if (empty()) return fence; int slot; if (low == base) { int blk = 0; while (map[blk] == 0) ++blk; slot = blk * _MAP_BITS + base; } else slot = low; while(!valid(slot)) ++slot; return slot; } int MChunk::last_index() const { if (empty()) return low - 1; int slot; if (top == fence) { int blk = (top - base) / _MAP_BITS; while (map[blk] == 0) --blk; slot = blk * _MAP_BITS + base + _MAP_BITS - 1; } else slot = fence - 1; while(!valid(slot)) --slot; return slot; } int MChunk:: OK() const { int v = data != 0; // have some data v &= map != 0; // and a map v &= base <= low; // ok, index-wise v &= low <= fence; v &= fence <= top; v &= ((MChunk*)(nxt->prev())) == this; // and links are OK v &= ((MChunk*)(prv->next())) == this; int bitcount = 0; // and unused count correct for (int i = low; i < fence; ++i) if (!valid(i)) ++bitcount; v &= unused == bitcount; if (!v) error("invariant failure"); return(v); } * MChunk::succ(* p) const { int i = ((int) p - (int) data) / sizeof() + base + 1; if (p == 0 || i < low) return 0; while (i < fence && !valid(i)) ++i; if (i >= fence) return 0; return pointer_to(i); } * MChunk::pred(* p) const { int i = ((int) p - (int) data) / sizeof() + base - 1; if (p == 0 || i >= fence) return 0; while (i >= low && !valid(i)) --i; if (i < low) return 0; return pointer_to(i); } * MChunk::first_pointer() const { if (empty()) return 0; int slot; if (low == base) { int blk = 0; while (map[blk] == 0) ++blk; slot = blk * _MAP_BITS + base; } else slot = low; while(!valid(slot)) ++slot; return pointer_to(slot); } * MChunk::last_pointer() const { if (empty()) return 0; int slot; if (top == fence) { int blk = (top - base) / _MAP_BITS; while (map[blk] == 0) --blk; slot = blk * _MAP_BITS + base + _MAP_BITS - 1; } else slot = fence - 1; while(!valid(slot)) --slot; return pointer_to(slot); } MPlex:: MPlex() { unused = 0; lo = fnc = 0; csize = DEFAULT_INITIAL_CAPACITY; * data = new [csize]; hd = ch = new MChunk(data, lo, lo, fnc, lo+csize); } MPlex:: MPlex(int chunksize) { if (chunksize == 0) error("invalid constructor specification"); unused = 0; lo = fnc = 0; if (chunksize > 0) { csize = chunksize; * data = new [csize]; hd = ch = new MChunk(data, lo, lo, fnc, csize); } else { csize = -chunksize; * data = new [csize]; hd = ch = new MChunk(data, chunksize, lo, fnc, fnc); } } MPlex:: MPlex(int l, int chunksize) { if (chunksize == 0) error("invalid constructor specification"); unused = 0; lo = fnc = l; if (chunksize > 0) { csize = chunksize; * data = new [csize]; hd = ch = new MChunk(data, lo, lo, fnc, csize+lo); } else { csize = -chunksize; * data = new [csize]; hd = ch = new MChunk(data, chunksize+lo, lo, fnc, fnc); } } void MPlex::make_initial_chunks(int up) { int need = fnc - lo; hd = 0; if (up) { int l = lo; do { int sz; if (need >= csize) sz = csize; else sz = need; * data = new [csize]; MChunk* h = new MChunk(data, l, l, l+sz, l+csize); if (hd != 0) h->link_to_next(hd); else hd = h; l += sz; need -= sz; } while (need > 0); } else { int hi = fnc; do { int sz; if (need >= csize) sz = csize; else sz = need; * data = new [csize]; MChunk* h = new MChunk(data, hi-csize, hi-sz, hi, hi); if (hd != 0) h->link_to_next(hd); hd = h; hi -= sz; need -= sz; } while (need > 0); } ch = (MChunk*) hd; } MPlex:: MPlex(int l, int hi, const initval, int chunksize) { lo = l; fnc = hi + 1; if (chunksize == 0) { csize = fnc - l; make_initial_chunks(1); } else if (chunksize < 0) { csize = -chunksize; make_initial_chunks(0); } else { csize = chunksize; make_initial_chunks(1); } unused = fnc - lo; for (int i=lo; iMPlex::MPlex(const MPlex& a) { lo = a.lo; fnc = a.fnc; csize = a.csize; unused = fnc - lo; hd = 0; const IChunk* p = a.hd; do { * data = new [p->size()]; MChunk* h = new MChunk(data, p->base_index(), p->low_index(), p->fence_index(), p->top_index()); if (hd != 0) h->link_to_next(hd); else hd = h; p = p->next(); } while (p != a.hd); ch = (MChunk*) hd; for (int i = a.low(); i < a.fence(); a.next(i)) { undel_index(i); (*this)[i] = a[i]; } } void MPlex::operator= (const MPlex& a) { if (&a != this) { invalidate(); lo = a.lo; fnc = a.fnc; csize = a.csize; unused = fnc - lo; hd = 0; const IChunk* p = a.hd; do { * data = new [p->size()]; MChunk* h = new MChunk(data, p->base_index(), p->low_index(), p->fence_index(), p->top_index()); if (hd != 0) h->link_to_next(hd); else hd = h; p = p->next(); } while (p != a.hd); ch = (MChunk*) hd; for (int i = a.low(); i < a.fence(); a.next(i)) { undel_index(i); (*this)[i] = a[i]; } } } int MPlex::valid(int idx) const { const MChunk* tail = (MChunk*)tl(); const MChunk* t = ch; while (idx >= t->fence_index()) { if (t == tail) return 0; t = ((MChunk*)(t->next())); } while (idx < t->low_index()) { if (t == (MChunk*)(hd)) return 0; t = ((MChunk*)(t->prev())); } set_cache(t); return t->MChunk::valid_index(idx); } void MPlex::cache(int idx) const { const MChunk* tail = (MChunk*)tl(); const MChunk* t = ch; while (idx >= t->fence_index()) { if (t == tail) index_error(); t = ((MChunk*)(t->next())); } while (idx < t->low_index()) { if (t == (MChunk*)hd) index_error(); t = ((MChunk*)(t->prev())); } if (!t->MChunk::valid_index(idx)) index_error(); set_cache(t); } void MPlex::cache(const * p) const { const MChunk* old = ch; const MChunk* t = ch; while (!t->actual_pointer(p)) { t = ((MChunk*)(t->next())); if (t == old) index_error(); } if (!t->MChunk::valid_pointer(p)) index_error(); set_cache(t); } int MPlex::owns(Pix px) const { * p = (*)px; const MChunk* old = ch; const MChunk* t = ch; while (!t->actual_pointer(p)) { t = ((MChunk*)(t->next())); if (t == old) return 0; } set_cache(t); return t->MChunk::valid_pointer(p); } int MPlex::add_high(const elem) { MChunk* t = ((MChunk*) tl()); if (!t->can_grow_high()) { * data = new [csize]; t = (new MChunk(data, fnc,fnc,fnc,fnc+csize)); t->link_to_prev(tl()); } *((t->MChunk::grow_high())) = elem; set_cache(t); return fnc++; } int MPlex::add_low (const elem) { MChunk* t = ((MChunk*) hd); if (!t->can_grow_low()) { * data = new [csize]; hd = new MChunk(data, lo-csize, lo, lo, lo); hd->link_to_next(t); t = ((MChunk*) hd); } *((t->MChunk::grow_low())) = elem; set_cache(t); return --lo; } void MPlex::adjust_bounds() { MChunk* t = ((MChunk*) tl()); // clean up tail t->reset_high(); while (t->MChunk::empty() && !one_chunk()) { MChunk* pred = (MChunk*)(t->prev()); del_chunk(t); pred->reset_high(); t = (pred); } if (one_chunk()) t->reset_high(); int oldfnc = fnc; fnc = t->fence_index(); unused -= oldfnc - fnc; // and head.. t = ((MChunk*) hd); t->reset_low(); while (t->MChunk::empty() && !one_chunk()) { hd = (MChunk*)(t->next()); del_chunk(t); t = ((MChunk*) hd); t->reset_low(); } int oldlo = lo; lo = t->low_index(); unused -= lo - oldlo; set_cache(t); } int MPlex::del_high () { if (empty()) empty_error(); MChunk* t = ((MChunk*) tl()); while (t->MChunk::empty() && !one_chunk()) // possible stragglers { MChunk* pred = (MChunk*)(t->prev()); del_chunk(t); pred->reset_high(); t = (pred); } t->MChunk::shrink_high(); while (t->MChunk::empty() && !one_chunk()) { MChunk* pred = (MChunk*)(t->prev()); del_chunk(t); pred->reset_high(); t = (pred); } int oldfnc = fnc; fnc = t->fence_index(); unused -= oldfnc - fnc - 1; set_cache(t); return fnc - 1; } int MPlex::del_low () { if (empty()) empty_error(); MChunk* t = ((MChunk*) hd); while (t->MChunk::empty() && !one_chunk()) { hd = (MChunk*)(t->next()); del_chunk(t); t = ((MChunk*) hd); t->reset_low(); } t->MChunk::shrink_low(); while (t->MChunk::empty() && !one_chunk()) { hd = (MChunk*)(t->next()); del_chunk(t); t = ((MChunk*) hd); t->reset_low(); } int oldlo = lo; lo = t->low_index(); unused -= lo - oldlo - 1; set_cache(t); return lo; } int MPlex::add(const elem) { if (unused == 0) return add_high(elem); for(MChunk* t = ch; t->unused_indices() == 0; t = (MChunk*)(t->prev())) ; int i = t->unused_index(); set_cache(t); undel_index(i); (*this)[i] = elem; return i; } int MPlex::unused_index() const { if (unused == 0) index_error(); for(MChunk* t = ch; t->unused_indices() == 0; t = (MChunk*)(t->prev())) ; set_cache(t); return t->unused_index(); } Pix MPlex::unused_Pix() const { if (unused == 0) return 0; for(MChunk* t = ch; t->unused_indices() == 0; t = (MChunk*)(t->prev())) ; set_cache(t); return t->pointer_to(t->unused_index()); } int MPlex::del_index(int idx) { if (idx < lo || idx >= fnc) index_error(); if (MPlex::valid(idx)) { ++unused; ch->MChunk::del(idx); return 1; } else return 0; } int MPlex::dopred(int idx) const { if (idx >= fnc) idx = fnc; if (idx <= lo) return lo - 1; const MChunk* t = ch; while (idx > t->fence_index()) { t = ((MChunk*)(t->next())); } while (idx <= t->low_index()) { t = ((MChunk*)(t->prev())); } int i = t->MChunk::pred(idx); while (i < t->low_index() && i >= lo) { t = ((MChunk*)(t->prev())); i = t->MChunk::last_index(); } set_cache(t); return i; } int MPlex::dosucc(int idx) const { if (idx < lo) idx = lo; if (idx >= fnc - 1) return fnc; const MChunk* t = ch; while (idx >= t->fence_index()) { t = ((MChunk*)(t->next())); } while (idx < t->low_index()) { t = ((MChunk*)(t->prev())); } int i = t->MChunk::succ(idx); while (i >= t->fence_index() && i < fnc) { t = (MChunk*)(t->next()); i = t->MChunk::first_index(); } set_cache(t); return i; } void MPlex::prev(Pix& i) const { if (i == 0) return; * p = (*) i; const MChunk* old = ch; const MChunk* t = ch; while (!t->actual_pointer(p)) { t = ((MChunk*)(t->prev())); if (t == old) { i = 0; return; } } * q = t->MChunk::pred(p); while (q == 0 && t != (MChunk*)hd) { t = ((MChunk*)(t->prev())); q = t->MChunk::last_pointer(); } i = Pix(q); set_cache(t); return; } void MPlex::next(Pix& i) const { if (i == 0) return; * p = (*) i; const MChunk* tail = (MChunk*)(tl()); const MChunk* old = ch; const MChunk* t = ch; while (!t->actual_pointer(p)) { t = ((MChunk*)(t->next())); if (t == old) { i = 0; return; } } * q = t->MChunk::succ(p); while (q == 0 && t != tail) { t = ((MChunk*)(t->next())); q = t->MChunk::first_pointer(); } i = Pix(q); set_cache(t); return; } void MPlex::undel_index(int idx) { if (idx < lo || idx >= fnc) index_error(); MChunk* t = ch; while (idx >= t->fence_index()) { t = ((MChunk*)(t->next())); } while (idx < t->low_index()) { t = ((MChunk*)(t->prev())); } int was_present = t->MChunk::undel(idx); if (!was_present) { --unused; } set_cache(t); return; } void MPlex::clear() { if (fnc != lo) { MChunk* t = ((MChunk*)tl()); while (t != hd) { MChunk* prv = (MChunk*)(t->prev()); del_chunk(t); t = prv; } t->MChunk::clear(lo); set_cache(t); fnc = lo; unused = 0; } } int MPlex::OK () const { int v = hd != 0; // at least one chunk int found_ch = 0; // to make sure ch is in list; int count = 0; // to count unused slots const MChunk* t = (MChunk*)(hd); int gap = t->low_index() - lo; v &= gap == 0; // hd lo not less than lo. count += gap; for (;;) { if (t == ch) ++found_ch; v &= t->MChunk::OK(); // each chunk is OK count += t->unused_indices(); if (t == (MChunk*)(tl())) break; else // and has indices less than succ { gap = t->next()->base_index() - t->top_index(); v &= gap == 0; count += gap; if (t != (MChunk*)hd) // internal chunks can't grow v &= !t->can_grow_low() && !t->can_grow_high(); t = (const MChunk*)(t->next()); } } gap = fnc - t->fence_index(); v &= gap == 0; count += gap; v &= count == unused; // chunk counts agree with plex v &= found_ch == 1; if (!v) error("invariant failure"); return v; } ./g++-include/gen/Map.ccP100644 0 1 2703 5522102347 13467 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include "..Map.h" Pix Map::seek( item) { for (Pix i = first(); i != 0 && !(EQ(key(i), item)); next(i)); return i; } int Map::owns(Pix idx) { if (idx == 0) return 0; for (Pix i = first(); i; next(i)) if (i == idx) return 1; return 0; } void Map::clear() { Pix i = first(); while (i != 0) { del(key(i)); i = first(); } } int Map::contains ( item) { return seek(item) != 0; } void Map::error(const char* msg) { (*lib_error_handler)("Map", msg); } ./g++-include/gen/OSLBag.ccP100644 0 1 6717 5522102350 14024 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".OSLBag.h" Pix OSLBag::seek( item, Pix i) { if (i == 0) i = p.first(); else next(i); for (; i != 0; p.next(i)) { int cmp = CMP(item, p(i)); if (cmp == 0) return i; else if (cmp < 0) return 0; } return 0; } int OSLBag::nof( item) { int n = 0; for (Pix i = p.first(); i != 0; p.next(i)) { int cmp = CMP(item, p(i)); if (cmp == 0) ++n; else if (cmp < 0) break; } return n; } Pix OSLBag::add( item) { Pix i = p.first(); if (i == 0) { ++count; return p.prepend(item); } int cmp = CMP(item, p(i)); if (cmp <= 0) { ++count; return p.prepend(item); } else { Pix trail = i; p.next(i); for (;;) { if (i == 0) { ++count; return p.append(item); } cmp = CMP(item, p(i)); if (cmp <= 0) { ++count; return p.ins_after(trail, item); } else { trail = i; p.next(i); } } } } void OSLBag::del( item) { Pix i = p.first(); if (i == 0) return; int cmp = CMP(item, p(i)); if (cmp < 0) return; else if (cmp == 0) { --count; p.del_front(); } else { Pix trail = i; p.next(i); while (i != 0) { cmp = CMP(item, p(i)); if (cmp < 0) return; else if (cmp == 0) { --count; p.del_after(trail); return; } else { trail = i; p.next(i); } } } } void OSLBag::remove( item) { Pix i = p.first(); if (i == 0) return; int cmp = CMP(item, p(i)); if (cmp < 0) return; else if (cmp == 0) { do { --count; p.del_front(); i = p.first(); } while (i != 0 && EQ(item, p(i))); } else { Pix trail = i; p.next(i); while (i != 0) { cmp = CMP(item, p(i)); if (cmp < 0) return; else if (cmp == 0) { do { --count; p.del_after(trail); i = trail; next(i); } while (i != 0 && EQ(item, p(i))); return; } else { trail = i; p.next(i); } } } } int OSLBag::OK() { int v = p.OK(); v &= count == p.length(); Pix trail = p.first(); if (trail == 0) v &= count == 0; else { Pix i = trail; next(i); while (i != 0) { v &= CMP(p(trail), p(i)) <= 0; trail = i; next(i); } } if (!v) error("invariant failure"); return v; } ./g++-include/gen/OSLSet.ccP100644 0 1 12725 5522102350 14102 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".OSLSet.h" Pix OSLSet::seek( item) { for (Pix i = p.first(); i != 0; p.next(i)) { int cmp = CMP(item, p(i)); if (cmp == 0) return i; else if (cmp < 0) return 0; } return 0; } Pix OSLSet::add( item) { Pix i = p.first(); if (i == 0) { ++count; return p.prepend(item); } int cmp = CMP(item, p(i)); if (cmp == 0) return i; else if (cmp < 0) { ++count; return p.prepend(item); } else { Pix trail = i; p.next(i); for (;;) { if (i == 0) { ++count; return p.append(item); } cmp = CMP(item, p(i)); if (cmp == 0) return i; else if (cmp < 0) { ++count; return p.ins_after(trail, item); } else { trail = i; p.next(i); } } } } void OSLSet::del( item) { Pix i = p.first(); if (i == 0) return; int cmp = CMP(item, p(i)); if (cmp < 0) return; else if (cmp == 0) { --count; p.del_front(); } else { Pix trail = i; p.next(i); while (i != 0) { cmp = CMP(item, p(i)); if (cmp < 0) return; else if (cmp == 0) { --count; p.del_after(trail); return; } else { trail = i; p.next(i); } } } } int OSLSet::operator <= (OSLSet& b) { if (count > b.count) return 0; Pix i = first(); Pix j = b.first(); for (;;) { if (i == 0) return 1; else if (j == 0) return 0; int cmp = CMP(p(i), b.p(j)); if (cmp == 0) { next(i); b.next(j); } else if (cmp < 0) return 0; else b.next(j); } } int OSLSet::operator == (OSLSet& b) { if (count != b.count) return 0; if (count == 0) return 1; Pix i = p.first(); Pix j = b.p.first(); while (i != 0) { if (!EQ(p(i),b.p(j))) return 0; next(i); b.next(j); } return 1; } void OSLSet::operator |= (OSLSet& b) { if (&b == this || b.count == 0) return; else { Pix j = b.p.first(); Pix i = p.first(); Pix trail = 0; for (;;) { if (j == 0) return; else if (i == 0) { for (; j != 0; b.next(j)) { ++count; p.append(b.p(j)); } return; } int cmp = CMP(p(i), b.p(j)); if (cmp <= 0) { if (cmp == 0) b.next(j); trail = i; next(i); } else { ++count; if (trail == 0) trail = p.prepend(b.p(j)); else trail = p.ins_after(trail, b.p(j)); b.next(j); } } } } void OSLSet::operator -= (OSLSet& b) { if (&b == this) clear(); else if (count != 0 && b.count != 0) { Pix i = p.first(); Pix j = b.p.first(); Pix trail = 0; for (;;) { if (j == 0 || i == 0) return; int cmp = CMP(p(i), b.p(j)); if (cmp == 0) { --count; b.next(j); if (trail == 0) { p.del_front(); i = p.first(); } else { next(i); p.del_after(trail); } } else if (cmp < 0) { trail = i; next(i); } else b.next(j); } } } void OSLSet::operator &= (OSLSet& b) { if (b.count == 0) clear(); else if (&b != this && count != 0) { Pix i = p.first(); Pix j = b.p.first(); Pix trail = 0; for (;;) { if (i == 0) return; else if (j == 0) { if (trail == 0) { p.clear(); count = 0; } else { while (i != 0) { --count; next(i); p.del_after(trail); } } return; } int cmp = CMP(p(i), b.p(j)); if (cmp == 0) { trail = i; next(i); b.next(j); } else if (cmp < 0) { --count; if (trail == 0) { p.del_front(); i = p.first(); } else { next(i); p.del_after(trail); } } else b.next(j); } } } int OSLSet::OK() { int v = p.OK(); v &= count == p.length(); Pix trail = p.first(); if (trail == 0) v &= count == 0; else { Pix i = trail; next(i); while (i != 0) { v &= CMP(p(trail), p(i)) < 0; trail = i; next(i); } } if (!v) error("invariant failure"); return v; } ./g++-include/gen/OXPBag.ccP100644 0 1 11207 5522102351 14044 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".OXPBag.h" Pix OXPBag::seek( item, Pix i) { if (i == 0) { int l = p.low(); int h = p.high(); while (l <= h) { int mid = (l + h) / 2; int cmp = CMP(item, p[mid]); if (cmp == 0) { while (mid > p.low() && EQ(item, p[mid - 1])) --mid; return p.index_to_Pix(mid); } else if (cmp < 0) h = mid - 1; else l = mid + 1; } return 0; } int cmp = CMP(item, p(i)); if (cmp == 0) { next(i); return (EQ(item, p(i)))? i : 0; } else if (cmp < 0) { int ind = p.Pix_to_index(i); int l = ind; int h = p.high(); while (l <= h) { int mid = (l + h) / 2; cmp = CMP(item, p[mid]); if (cmp == 0) { while (mid > ind && EQ(item, p[mid - 1])) --mid; return p.index_to_Pix(mid); } else if (cmp < 0) h = mid - 1; else l = mid + 1; } return 0; } else return 0; } int OXPBag::nof( item) { int l = p.low(); int h = p.high(); while (l <= h) { int mid = (l + h) / 2; int cmp = CMP(item, p[mid]); if (cmp == 0) { l = h = mid; while (l > p.low() && EQ(item, p[l - 1])) --l; while (h < p.high() && EQ(item, p[h + 1])) ++h; return h - l + 1; } else if (cmp < 0) h = mid - 1; else l = mid + 1; } return 0; } Pix OXPBag::add( item) { if (count == 0) { ++count; return p.index_to_Pix(p.add_high(item)); } int l = p.low(); int h = p.high(); while (l <= h) { int mid = (l + h) / 2; int cmp = CMP(item, p[mid]); if (cmp == 0) { l = mid; break; } else if (cmp < 0) h = mid - 1; else l = mid + 1; } // add on whichever side is shortest ++count; if (l == p.fence()) return p.index_to_Pix(p.add_high(item)); else if (l == p.low()) return p.index_to_Pix(p.add_low(item)); else { if (p.high() - l < l - p.low()) { h = p.add_high(p.high_element()); for (int i = h - 1; i > l; --i) p[i] = p[i-1]; } else { --l; h = p.add_low(p.low_element()); for (int i = h + 1; i < l; ++i) p[i] = p[i+1]; } p[l] = item; return p.index_to_Pix(l); } } void OXPBag::del( item) { int l = p.low(); int h = p.high(); while (l <= h) { int mid = (l + h) / 2; int cmp = CMP(item, p[mid]); if (cmp == 0) { --count; if (p.high() - mid < mid - p.low()) { for (int i = mid; i < p.high(); ++i) p[i] = p[i+1]; p.del_high(); } else { for (int i = mid; i > p.low(); --i) p[i] = p[i-1]; p.del_low(); } return; } else if (cmp < 0) h = mid - 1; else l = mid + 1; } } void OXPBag::remove( item) { int l = p.low(); int h = p.high(); while (l <= h) { int mid = (l + h) / 2; int cmp = CMP(item, p[mid]); if (cmp == 0) { l = h = mid; while (l > p.low() && EQ(item, p[l - 1])) --l; while (h < p.high() && EQ(item, p[h + 1])) ++h; int n = h - l + 1; count -= n; if (p.high() - h < l - p.low()) { h = p.high() - n; for (int i = l; i <= h; ++i) p[i] = p[i+n]; while (n-- > 0) p.del_high(); } else { l = p.low() + n; for (int i = h; i >= l; --i) p[i] = p[i-n]; while (n-- > 0) p.del_low(); } return; } else if (cmp < 0) h = mid - 1; else l = mid + 1; } } int OXPBag::OK() { int v = p.OK(); v &= count == p.length(); for (int i = p.low(); i < p.high(); ++i) v &= CMP(p[i], p[i+1]) <= 0; if (!v) error("invariant failure"); return v; } ./g++-include/gen/OXPSet.ccP100644 0 1 13036 5522102352 14111 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".OXPSet.h" Pix OXPSet::seek( item) { int l = p.low(); int h = p.high(); while (l <= h) { int mid = (l + h) / 2; int cmp = CMP(item, p[mid]); if (cmp == 0) return p.index_to_Pix(mid); else if (cmp < 0) h = mid - 1; else l = mid + 1; } return 0; } Pix OXPSet::add( item) { if (count == 0) { ++count; return p.index_to_Pix(p.add_high(item)); } int l = p.low(); int h = p.high(); while (l <= h) { int mid = (l + h) / 2; int cmp = CMP(item, p[mid]); if (cmp == 0) return p.index_to_Pix(mid); else if (cmp < 0) h = mid - 1; else l = mid + 1; } // add on whichever side is shortest ++count; if (l == p.fence()) return p.index_to_Pix(p.add_high(item)); else if (l == p.low()) return p.index_to_Pix(p.add_low(item)); else { if (p.fence() - l < l - p.low()) { h = p.add_high(p.high_element()); for (int i = h - 1; i > l; --i) p[i] = p[i-1]; } else { --l; h = p.add_low(p.low_element()); for (int i = h + 1; i < l; ++i) p[i] = p[i+1]; } p[l] = item; return p.index_to_Pix(l); } } void OXPSet::del( item) { int l = p.low(); int h = p.high(); while (l <= h) { int mid = (l + h) / 2; int cmp = CMP(item, p[mid]); if (cmp == 0) { --count; if (p.high() - mid < mid - p.low()) { for (int i = mid; i < p.high(); ++i) p[i] = p[i+1]; p.del_high(); } else { for (int i = mid; i > p.low(); --i) p[i] = p[i-1]; p.del_low(); } return; } else if (cmp < 0) h = mid - 1; else l = mid + 1; } } int OXPSet::operator <= (OXPSet& b) { if (count > b.count) return 0; int i = p.low(); int j = b.p.low(); for (;;) { if (i >= p.fence()) return 1; else if (j >= b.p.fence()) return 0; int cmp = CMP(p[i], b.p[j]); if (cmp == 0) { ++i; ++j; } else if (cmp < 0) return 0; else ++j; } } int OXPSet::operator == (OXPSet& b) { int n = count; if (n != b.count) return 0; if (n == 0) return 1; int i = p.low(); int j = b.p.low(); while (n-- > 0) if (!EQ(p[i++], b.p[j++])) return 0; return 1; } void OXPSet::operator |= (OXPSet& b) { if (&b == this || b.count == 0) return; else if (b.count <= 2) // small b -- just add for (Pix i = b.first(); i; b.next(i)) add(b(i)); else { // strategy: merge into top of p, simultaneously killing old bottom int oldfence = p.fence(); int i = p.low(); int j = b.p.low(); for (;;) { if (i == oldfence) { while (j < b.p.fence()) p.add_high(b.p[j++]); break; } else if (j == b.p.fence()) { while (i++ < oldfence) { p.add_high(p.low_element()); p.del_low(); } break; } int cmp = CMP(p[i], b.p[j]); if (cmp <= 0) { ++i; if (cmp == 0) ++j; p.add_high(p.low_element()); p.del_low(); } else p.add_high(b.p[j++]); } count = p.length(); } } void OXPSet::operator -= (OXPSet& b) { if (&b == this) clear(); else if (count != 0 && b.count != 0) { int i = p.low(); int k = i; int j = b.p.low(); int oldfence = p.fence(); for (;;) { if (i >= oldfence) break; else if (j >= b.p.fence()) { if (k != i) while (i < oldfence) p[k++] = p[i++]; else k = oldfence; break; } int cmp = CMP(p[i], b.p[j]); if (cmp == 0) { ++i; ++j; } else if (cmp < 0) { if (k != i) p[k] = p[i]; ++i; ++k; } else j++; } while (k++ < oldfence) { --count; p.del_high(); } } } void OXPSet::operator &= (OXPSet& b) { if (b.count == 0) clear(); else if (&b != this && count != 0) { int i = p.low(); int k = i; int j = b.p.low(); int oldfence = p.fence(); for (;;) { if (i >= oldfence || j >= b.p.fence()) break; int cmp = CMP(p[i], b.p[j]); if (cmp == 0) { if (k != i) p[k] = p[i]; ++i; ++k; ++j; } else if (cmp < 0) ++i; else ++j; } while (k++ < oldfence) { --count; p.del_high(); } } } int OXPSet::OK() { int v = p.OK(); v &= count == p.length(); for (int i = p.low(); i < p.high(); ++i) v &= CMP(p[i], p[i+1]) < 0; if (!v) error("invariant failure"); return v; } ./g++-include/gen/PHPQ.ccP100644 0 1 16461 5522102353 13545 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) adapted for libg++ by Doug Lea (dl@rocky.oswego.edu) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include ".PHPQ.h" // // This defines a Pairing Heap structure // // See ``The Pairing Heap: A New Form of Self-Adjusting Heap'' // Fredman, Segdewick et al, // Algorithmica (1986) 1:111-129 // // In particular, this implements the pairing heap using the circular // list. // // PHPQ::PHPQ(int sz) { storage = 0; root = 0; count = 0; size = 0; prealloc(sz); } PHPQ::PHPQ(PHPQ& a) { storage = 0; root = 0; count = 0; size = 0; prealloc(a.size); for (Pix i = a.first(); i != 0; a.next(i)) enq(a(i)); } void PHPQ::prealloc(int newsize) { ++newsize; // leave a spot for freelist if (size != 0) { int news = size; while (news <= newsize) news = (news * 3) / 2; newsize = news; } // see if indices are OK PHPQNode test; test.sibling = 0; test.sibling = ~test.sibling; if ((unsigned long)newsize > (unsigned long)(test.sibling)) error("storage size exceeds index range"); if (storage == 0) { storage = new PHPQNode[size = newsize]; for (int i = 0; i < size; ++i) { storage[i].sibling = i + 1; storage[i].valid = 0; } storage[size-1].sibling = 0; } else { PHPQNode* newstor = new PHPQNode[newsize]; for (int i = 1; i < size; ++i) newstor[i] = storage[i]; delete [] storage; storage = newstor; for (i = size; i < newsize; ++i) { storage[i].sibling = i + 1; storage[i].valid = 0; } storage[newsize-1].sibling = 0; storage[0].sibling = size; size = newsize; } } void PHPQ::clear() { for (int i = 0; i < size; ++i) { storage[i].sibling = i + 1; storage[i].valid = 0; } storage[size-1].sibling = 0; root = 0; count = 0; } Pix PHPQ::enq( item) { ++count; if (storage[0].sibling == 0) prealloc(count); int cell = storage[0].sibling; storage[0].sibling = storage[cell].sibling; storage[cell].sibling = 0; storage[cell].children = 0; storage[cell].item = item; storage[cell].valid = 1; if (root == 0) { root = cell; return Pix(root); } else { int parent; int child; if (LE(storage[root].item, storage[cell].item)) { parent = root; child = cell; } else { parent = cell; child = root; } int popsKid = storage[parent].children; if (popsKid == 0) { storage[parent].children = child; storage[child].sibling = child; } else { int temp = storage[popsKid].sibling; storage[popsKid].sibling = child; storage[child].sibling = temp; storage[parent].children = child; } root = parent; return Pix(cell); } } // // Item removal is the most complicated routine. // // We remove the root (should there be one) and then select a new // root. The siblings of the root are in a circular list. We continue // to pair elements in this list until there is a single element. // This element will be the new root. void PHPQ::del_front() { int valid = 0; do { if (root == 0) return; if (valid = storage[root].valid) --count; storage[root].valid = 0; int child = storage[root].children; storage[root].sibling = storage[0].sibling; storage[0].sibling = root; if (child == 0) { root = 0; return; } else { while(storage[child].sibling != child) { // We have at least two kids, but we may only have // two kids. So, oneChild != child, but it is possible // that twoChild == child. int oneChild = storage[child].sibling; int twoChild = storage[oneChild].sibling; // Remove the two from the sibling list storage[child].sibling = storage[twoChild].sibling; storage[oneChild].sibling = 0; storage[twoChild].sibling = 0; int bestChild; int worstChild; if (LE(storage[oneChild].item, storage[twoChild].item)) { bestChild = oneChild; worstChild = twoChild; } else { bestChild = twoChild; worstChild = oneChild; } int popsKid = storage[bestChild].children; if (popsKid == 0) { storage[bestChild].children = worstChild; storage[worstChild].sibling = worstChild; } else { int temp = storage[popsKid].sibling; storage[popsKid].sibling = worstChild; storage[worstChild].sibling = temp; storage[bestChild].children = worstChild; } if (twoChild == child) { // We have reduced the two to one, so we'll be exiting. child = bestChild; storage[child].sibling = child; } else { // We've removed two siblings, now we need to insert // the better of the two storage[bestChild].sibling = storage[child].sibling; storage[child].sibling = bestChild; child = storage[bestChild].sibling; } } root = child; } } while ( !valid ); } void PHPQ::del(Pix p) { if (p == 0) error("null Pix"); int i = int(p); if (storage[i].valid) { if (i == root) del_front(); else { storage[i].valid = 0; --count; } } } Pix PHPQ::seek( key) { for (int i = 1; i < size; ++i) if (storage[i].valid && EQ(storage[i].item, key)) return Pix(i); return 0; } Pix PHPQ::first() { for (int i = 1; i < size; ++i) if (storage[i].valid) return Pix(i); return 0; } void PHPQ::next(Pix& p) { if (p == 0) return; for (int i = int(p)+1; i < size; ++i) if (storage[i].valid) { p = Pix(i); return; } p = 0; } int PHPQ::OK() { int v = storage != 0; int n = 0; for (int i = 0; i < size; ++i) if (storage[i].valid) ++n; v &= n == count; v &= check_sibling_list(root); int ct = LONG_MAX; n = 0; int f = storage[0].sibling; while (f != 0 && ct-- > 0) { f = storage[f].sibling; ++n; } v &= ct > 0; v &= n <= size - count; if (!v) error("invariant failure"); return v; } int PHPQ::check_sibling_list(int t) { if (t != 0) { int s = t; long ct = LONG_MAX; // Lots of chances to find self! do { if (storage[s].valid && !check_sibling_list(storage[s].children)) return 0; s = storage[s].sibling; } while (ct-- > 0 && s != t && s != 0); if (ct <= 0) return 0; } return 1; } ./g++-include/gen/PQ.ccP100644 0 1 2706 5522102354 13273 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include ".PQ.h" PQ::deq() { x = front(); del_front(); return x; } Pix PQ::seek( item) { for (Pix i = first(); i != 0 && !(EQ((*this)(i), item)); next(i)); return i; } int PQ::owns(Pix idx) { if (idx == 0) return 0; for (Pix i = first(); i; next(i)) if (i == idx) return 1; return 0; } void PQ::clear() { while (count != 0) del_front(); } int PQ::contains ( item) { return seek(item) != 0; } void PQ::error(const char* msg) { (*lib_error_handler)("PQ", msg); } ./g++-include/gen/Plex.ccP100644 0 1 10157 5522102354 13702 0ustar rootdaemon// 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include #include ".Plex.h" // IChunk support void IChunk::error(const char* msg) const { (*lib_error_handler)("IChunk", msg); } void IChunk::index_error() const { error("attempt to use invalid index"); } void IChunk::empty_error() const { error("invalid use of empty chunk"); } void IChunk::full_error() const { error("attempt to extend chunk beyond bounds"); } IChunk:: ~IChunk() {} IChunk::IChunk(* d, int baseidx, int lowidx, int fenceidx, int topidx) { if (d == 0 || baseidx > lowidx || lowidx > fenceidx || fenceidx > topidx) error("inconsistent specification"); data = d; base = baseidx; low = lowidx; fence = fenceidx; top = topidx; nxt = prv = this; } void IChunk:: re_index(int lo) { int delta = lo - low; base += delta; low += delta; fence += delta; top += delta; } void IChunk::clear(int lo) { int s = top - base; low = base = fence = lo; top = base + s; } void IChunk::cleardown(int hi) { int s = top - base; low = top = fence = hi; base = top - s; } int IChunk:: OK() const { int v = data != 0; // have some data v &= base <= low; // ok, index-wise v &= low <= fence; v &= fence <= top; v &= nxt->prv == this; // and links are OK v &= prv->nxt == this; if (!v) error("invariant failure"); return(v); } // error handling void Plex::error(const char* msg) const { (*lib_error_handler)("Plex", msg); } void Plex::index_error() const { error("attempt to access invalid index"); } void Plex::empty_error() const { error("attempted operation on empty plex"); } void Plex::full_error() const { error("attempt to increase size of plex past limit"); } // generic plex ops Plex:: ~Plex() { invalidate(); } void Plex::append (const Plex& a) { for (int i = a.low(); i < a.fence(); a.next(i)) add_high(a[i]); } void Plex::prepend (const Plex& a) { for (int i = a.high(); i > a.ecnef(); a.prev(i)) add_low(a[i]); } void Plex::reverse() { tmp; int l = low(); int h = high(); while (l < h) { tmp = (*this)[l]; (*this)[l] = (*this)[h]; (*this)[h] = tmp; next(l); prev(h); } } void Plex::fill(const x) { for (int i = lo; i < fnc; ++i) (*this)[i] = x; } void Plex::fill(const x, int lo, int hi) { for (int i = lo; i <= hi; ++i) (*this)[i] = x; } void Plex::del_chunk(IChunk* x) { if (x != 0) { x->unlink(); * data = (*)(x->invalidate()); delete [] data; delete x; } } void Plex::invalidate() { IChunk* t = hd; if (t != 0) { IChunk* tail = tl(); while (t != tail) { IChunk* nxt = t->next(); del_chunk(t); t = nxt; } del_chunk(t); hd = 0; } } int Plex::reset_low(int l) { int old = lo; int diff = l - lo; if (diff != 0) { lo += diff; fnc += diff; IChunk* t = hd; do { t->re_index(t->low_index() + diff); t = t->next(); } while (t != hd); } return old; } ./g++-include/gen/Queue.ccP100644 0 1 304 5522102355 14010 0ustar rootdaemon#ifdef __GNUG__ #pragma implementation #endif #include ".Queue.h" Queue::~Queue() {} // error handling void Queue::error(const char* msg) { (*lib_error_handler)("Queue", msg); } ./g++-include/gen/RAVLMap.ccP100644 0 1 34065 5522102356 14202 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include "..RAVLMap.h" /* constants & inlines for maintaining balance & thread status in tree nodes */ #define AVLBALANCEMASK 3 #define AVLBALANCED 0 #define AVLLEFTHEAVY 1 #define AVLRIGHTHEAVY 2 #define LTHREADBIT 4 #define RTHREADBIT 8 static inline int bf(RAVLNode* t) { return t->stat & AVLBALANCEMASK; } static inline void set_bf(RAVLNode* t, int b) { t->stat = (t->stat & ~AVLBALANCEMASK) | (b & AVLBALANCEMASK); } static inline int rthread(RAVLNode* t) { return t->stat & RTHREADBIT; } static inline void set_rthread(RAVLNode* t, int b) { if (b) t->stat |= RTHREADBIT; else t->stat &= ~RTHREADBIT; } static inline int lthread(RAVLNode* t) { return t->stat & LTHREADBIT; } static inline void set_lthread(RAVLNode* t, int b) { if (b) t->stat |= LTHREADBIT; else t->stat &= ~LTHREADBIT; } /* traversal primitives */ RAVLNode* RAVLMap::leftmost() { RAVLNode* t = root; if (t != 0) while (t->lt != 0) t = t->lt; return t; } RAVLNode* RAVLMap::rightmost() { RAVLNode* t = root; if (t != 0) while (t->rt != 0) t = t->rt; return t; } RAVLNode* RAVLMap::succ(RAVLNode* t) { RAVLNode* r = t->rt; if (!rthread(t)) while (!lthread(r)) r = r->lt; return r; } RAVLNode* RAVLMap::pred(RAVLNode* t) { RAVLNode* l = t->lt; if (!lthread(t)) while (!rthread(l)) l = l->rt; return l; } Pix RAVLMap::seek( key) { RAVLNode* t = root; if (t == 0) return 0; for (;;) { int cmp = CMP(key, t->item); if (cmp == 0) return Pix(t); else if (cmp < 0) { if (lthread(t)) return 0; else t = t->lt; } else if (rthread(t)) return 0; else t = t->rt; } } int RAVLMap::rankof( key) { int r; RAVLNode* t = root; if (t == 0) return 0; for (r=t->rank; t != 0; r+=t->rank) { int cmp = CMP(key, t->item); if (cmp == 0) return r; else if (cmp < 0) { if (lthread(t)) return 0; else { r -= t->rank; t = t->lt; } } else if (rthread(t)) return 0; else { t = t->rt; } } return 0; } Pix RAVLMap::ranktoPix(int i) { int r; RAVLNode* t = root; if ((i<1)||(i>count)) return 0; for (r=t->rank; r!=i; r+=t->rank) { if (r>i) { r -= t->rank; t = t->lt; } else t = t->rt; } return Pix(t); } /* The combination of threads and AVL bits make adding & deleting interesting, but very awkward. We use the following statics to avoid passing them around recursively */ static int _need_rebalancing; // to send back balance info from rec. calls static * _target_item; // add/del_item target static RAVLNode* _found_node; // returned added/deleted node static int _already_found; // for deletion subcases static int _rank_changed; // for rank computation void RAVLMap:: _add(RAVLNode*& t) { int cmp = CMP(*_target_item, t->item); if (cmp == 0) { _found_node = t; return; } else if (cmp < 0) { if (lthread(t)) { ++count; _found_node = new RAVLNode(*_target_item, def); set_lthread(_found_node, 1); set_rthread(_found_node, 1); _found_node->lt = t->lt; _found_node->rt = t; t->lt = _found_node; set_lthread(t, 0); _need_rebalancing = 1; _rank_changed = 1; } else _add(t->lt); if (_rank_changed) ++t->rank; if (_need_rebalancing) { switch(bf(t)) { case AVLRIGHTHEAVY: set_bf(t, AVLBALANCED); _need_rebalancing = 0; return; case AVLBALANCED: set_bf(t, AVLLEFTHEAVY); return; case AVLLEFTHEAVY: { RAVLNode* l = t->lt; if (bf(l) == AVLLEFTHEAVY) { t->rank -= l->rank; if (rthread(l)) t->lt = l; else t->lt = l->rt; set_lthread(t, rthread(l)); l->rt = t; set_rthread(l, 0); set_bf(t, AVLBALANCED); set_bf(l, AVLBALANCED); t = l; _need_rebalancing = 0; } else { RAVLNode* r = l->rt; r->rank += l->rank; t->rank -= r->rank; set_rthread(l, lthread(r)); if (lthread(r)) l->rt = r; else l->rt = r->lt; r->lt = l; set_lthread(r, 0); set_lthread(t, rthread(r)); if (rthread(r)) t->lt = r; else t->lt = r->rt; r->rt = t; set_rthread(r, 0); if (bf(r) == AVLLEFTHEAVY) set_bf(t, AVLRIGHTHEAVY); else set_bf(t, AVLBALANCED); if (bf(r) == AVLRIGHTHEAVY) set_bf(l, AVLLEFTHEAVY); else set_bf(l, AVLBALANCED); set_bf(r, AVLBALANCED); t = r; _need_rebalancing = 0; return; } } } } } else { if (rthread(t)) { ++count; _found_node = new RAVLNode(*_target_item, def); set_rthread(t, 0); set_lthread(_found_node, 1); set_rthread(_found_node, 1); _found_node->lt = t; _found_node->rt = t->rt; t->rt = _found_node; _need_rebalancing = 1; _rank_changed = 1; } else _add(t->rt); if (_need_rebalancing) { switch(bf(t)) { case AVLLEFTHEAVY: set_bf(t, AVLBALANCED); _need_rebalancing = 0; return; case AVLBALANCED: set_bf(t, AVLRIGHTHEAVY); return; case AVLRIGHTHEAVY: { RAVLNode* r = t->rt; if (bf(r) == AVLRIGHTHEAVY) { r->rank += t->rank; if (lthread(r)) t->rt = r; else t->rt = r->lt; set_rthread(t, lthread(r)); r->lt = t; set_lthread(r, 0); set_bf(t, AVLBALANCED); set_bf(r, AVLBALANCED); t = r; _need_rebalancing = 0; } else { RAVLNode* l = r->lt; r->rank -= l->rank; l->rank += t->rank; set_lthread(r, rthread(l)); if (rthread(l)) r->lt = l; else r->lt = l->rt; l->rt = r; set_rthread(l, 0); set_rthread(t, lthread(l)); if (lthread(l)) t->rt = l; else t->rt = l->lt; l->lt = t; set_lthread(l, 0); if (bf(l) == AVLRIGHTHEAVY) set_bf(t, AVLLEFTHEAVY); else set_bf(t, AVLBALANCED); if (bf(l) == AVLLEFTHEAVY) set_bf(r, AVLRIGHTHEAVY); else set_bf(r, AVLBALANCED); set_bf(l, AVLBALANCED); t = l; _need_rebalancing = 0; return; } } } } } } & RAVLMap::operator [] ( item) { if (root == 0) { ++count; root = new RAVLNode(item, def); set_rthread(root, 1); set_lthread(root, 1); return root->cont; } else { _target_item = &item; _need_rebalancing = 0; _rank_changed = 0; _add(root); return _found_node->cont; } } void RAVLMap::_del(RAVLNode* par, RAVLNode*& t) { int comp; if (_already_found) { if (rthread(t)) comp = 0; else comp = 1; } else comp = CMP(*_target_item, t->item); if (comp == 0) { if (lthread(t) && rthread(t)) { _found_node = t; if (t == par->lt) { set_lthread(par, 1); par->lt = t->lt; } else { set_rthread(par, 1); par->rt = t->rt; } _need_rebalancing = 1; _rank_changed = 1; return; } else if (lthread(t)) { _found_node = t; RAVLNode* s = succ(t); if (s != 0 && lthread(s)) s->lt = t->lt; t = t->rt; _need_rebalancing = 1; _rank_changed = 1; return; } else if (rthread(t)) { _found_node = t; RAVLNode* p = pred(t); if (p != 0 && rthread(p)) p->rt = t->rt; t = t->lt; _need_rebalancing = 1; _rank_changed = 1; return; } else // replace item & find someone deletable { RAVLNode* p = pred(t); t->item = p->item; t->cont = p->cont; _already_found = 1; comp = -1; // fall through below to left } } if (comp < 0) { if (lthread(t)) return; _del(t, t->lt); if (_rank_changed) --t->rank; if (!_need_rebalancing) return; switch (bf(t)) { case AVLLEFTHEAVY: set_bf(t, AVLBALANCED); return; case AVLBALANCED: set_bf(t, AVLRIGHTHEAVY); _need_rebalancing = 0; return; case AVLRIGHTHEAVY: { RAVLNode* r = t->rt; switch (bf(r)) { case AVLBALANCED: r->rank += t->rank; if (lthread(r)) t->rt = r; else t->rt = r->lt; set_rthread(t, lthread(r)); r->lt = t; set_lthread(r, 0); set_bf(t, AVLRIGHTHEAVY); set_bf(r, AVLLEFTHEAVY); _need_rebalancing = 0; t = r; return; case AVLRIGHTHEAVY: r->rank += t->rank; if (lthread(r)) t->rt = r; else t->rt = r->lt; set_rthread(t, lthread(r)); r->lt = t; set_lthread(r, 0); set_bf(t, AVLBALANCED); set_bf(r, AVLBALANCED); t = r; return; case AVLLEFTHEAVY: { RAVLNode* l = r->lt; r->rank -= l->rank; l->rank += t->rank; set_lthread(r, rthread(l)); if (rthread(l)) r->lt = l; else r->lt = l->rt; l->rt = r; set_rthread(l, 0); set_rthread(t, lthread(l)); if (lthread(l)) t->rt = l; else t->rt = l->lt; l->lt = t; set_lthread(l, 0); if (bf(l) == AVLRIGHTHEAVY) set_bf(t, AVLLEFTHEAVY); else set_bf(t, AVLBALANCED); if (bf(l) == AVLLEFTHEAVY) set_bf(r, AVLRIGHTHEAVY); else set_bf(r, AVLBALANCED); set_bf(l, AVLBALANCED); t = l; return; } } } } } else { if (rthread(t)) return; _del(t, t->rt); if (!_need_rebalancing) return; switch (bf(t)) { case AVLRIGHTHEAVY: set_bf(t, AVLBALANCED); return; case AVLBALANCED: set_bf(t, AVLLEFTHEAVY); _need_rebalancing = 0; return; case AVLLEFTHEAVY: { RAVLNode* l = t->lt; switch (bf(l)) { case AVLBALANCED: t->rank -= l->rank; if (rthread(l)) t->lt = l; else t->lt = l->rt; set_lthread(t, rthread(l)); l->rt = t; set_rthread(l, 0); set_bf(t, AVLLEFTHEAVY); set_bf(l, AVLRIGHTHEAVY); _need_rebalancing = 0; t = l; return; case AVLLEFTHEAVY: t->rank -= l->rank; if (rthread(l)) t->lt = l; else t->lt = l->rt; set_lthread(t, rthread(l)); l->rt = t; set_rthread(l, 0); set_bf(t, AVLBALANCED); set_bf(l, AVLBALANCED); t = l; return; case AVLRIGHTHEAVY: { RAVLNode* r = l->rt; r->rank += l->rank; t->rank -= r->rank; set_rthread(l, lthread(r)); if (lthread(r)) l->rt = r; else l->rt = r->lt; r->lt = l; set_lthread(r, 0); set_lthread(t, rthread(r)); if (rthread(r)) t->lt = r; else t->lt = r->rt; r->rt = t; set_rthread(r, 0); if (bf(r) == AVLLEFTHEAVY) set_bf(t, AVLRIGHTHEAVY); else set_bf(t, AVLBALANCED); if (bf(r) == AVLRIGHTHEAVY) set_bf(l, AVLLEFTHEAVY); else set_bf(l, AVLBALANCED); set_bf(r, AVLBALANCED); t = r; return; } } } } } } void RAVLMap::del( item) { if (root == 0) return; _need_rebalancing = 0; _already_found = 0; _found_node = 0; _rank_changed = 0; _target_item = &item; _del(root, root); if (_found_node) { delete(_found_node); if (--count == 0) root = 0; } } void RAVLMap::_kill(RAVLNode* t) { if (t != 0) { if (!lthread(t)) _kill(t->lt); if (!rthread(t)) _kill(t->rt); delete t; } } RAVLMap::RAVLMap(RAVLMap& b) :Map(b.def) { root = 0; count = 0; for (Pix i = b.first(); i != 0; b.next(i)) (*this)[b.key(i)] = b.contents(i); } int RAVLMap::OK() { int v = 1; if (root == 0) v = count == 0; else { int n = 1; RAVLNode* trail = leftmost(); v &= rankof(trail->item) == n; RAVLNode* t = succ(trail); while (t != 0) { ++n; v &= CMP(trail->item, t->item) < 0; v &= rankof(t->item) == n; trail = t; t = succ(t); } v &= n == count; } if (!v) error("invariant failure"); return v; } ./g++-include/gen/RPlex.ccP100644 0 1 23713 5522102357 14031 0ustar rootdaemon// 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".RPlex.h" typedef IChunk* _IChunk_ptr; RPlex:: RPlex() { lo = fnc = 0; csize = DEFAULT_INITIAL_CAPACITY; * data = new [csize]; set_cache(new IChunk(data, lo, lo, fnc, lo+csize)); hd = ch; maxch = MIN_NCHUNKS; lch = maxch / 2; fch = lch + 1; base = ch->base_index() - lch * csize; chunks = new _IChunk_ptr[maxch]; chunks[lch] = ch; } RPlex:: RPlex(int chunksize) { if (chunksize == 0) error("invalid constructor specification"); lo = fnc = 0; if (chunksize > 0) { csize = chunksize; * data = new [csize]; set_cache(new IChunk(data, lo, lo, fnc, csize+lo)); hd = ch; } else { csize = -chunksize; * data = new [csize]; set_cache(new IChunk(data, chunksize+lo, lo, fnc, fnc)); hd = ch; } maxch = MIN_NCHUNKS; lch = maxch / 2; fch = lch + 1; base = ch->base_index() - lch * csize; chunks = new _IChunk_ptr[maxch]; chunks[lch] = ch; } RPlex:: RPlex(int l, int chunksize) { if (chunksize == 0) error("invalid constructor specification"); lo = fnc = l; if (chunksize > 0) { csize = chunksize; * data = new [csize]; set_cache(new IChunk(data, lo, lo, fnc, lo+csize)); hd = ch; } else { csize = -chunksize; * data = new [csize]; set_cache(new IChunk(data, chunksize+lo, lo, fnc, fnc)); hd = ch; } maxch = MIN_NCHUNKS; lch = maxch / 2; fch = lch + 1; base = ch->base_index() - lch * csize; chunks = new _IChunk_ptr[maxch]; chunks[lch] = ch; } void RPlex::make_initial_chunks(int up) { int count = 0; int need = fnc - lo; hd = 0; if (up) { int l = lo; do { ++count; int sz; if (need >= csize) sz = csize; else sz = need; * data = new [csize]; IChunk* h = new IChunk(data, l, l, l+sz, l+csize); if (hd != 0) h->link_to_next(hd); else hd = h; l += sz; need -= sz; } while (need > 0); } else { int hi = fnc; do { ++count; int sz; if (need >= csize) sz = csize; else sz = need; * data = new [csize]; IChunk* h = new IChunk(data, hi-csize, hi-sz, hi, hi); if (hd != 0) h->link_to_next(hd); hd = h; hi -= sz; need -= sz; } while (need > 0); } set_cache((IChunk*)hd); maxch = MIN_NCHUNKS; if (maxch < count * 2) maxch = count * 2; chunks = new _IChunk_ptr[maxch]; lch = maxch / 3; fch = lch + count; base = ch->base_index() - csize * lch; int k = lch; do { chunks[k++] = ch; set_cache(ch->next()); } while (ch != hd); } RPlex:: RPlex(int l, int hi, const initval, int chunksize) { lo = l; fnc = hi + 1; if (chunksize == 0) { csize = fnc - l; make_initial_chunks(1); } else if (chunksize < 0) { csize = -chunksize; make_initial_chunks(0); } else { csize = chunksize; make_initial_chunks(1); } fill(initval); } RPlex::RPlex(const RPlex& a) { lo = a.lo; fnc = a.fnc; csize = a.csize; make_initial_chunks(); for (int i = a.low(); i < a.fence(); a.next(i)) (*this)[i] = a[i]; } void RPlex::operator= (const RPlex& a) { if (&a != this) { invalidate(); lo = a.lo; fnc = a.fnc; csize = a.csize; make_initial_chunks(); for (int i = a.low(); i < a.fence(); a.next(i)) (*this)[i] = a[i]; } } void RPlex::cache(const * p) const { const IChunk* old = ch; const IChunk* t = ch; while (!t->actual_pointer(p)) { t = (t->next()); if (t == old) index_error(); } set_cache(t); } int RPlex::owns(Pix px) const { * p = (*)px; const IChunk* old = ch; const IChunk* t = ch; while (!t->actual_pointer(p)) { t = (t->next()); if (t == old) return 0; } set_cache(t); return 1; } * RPlex::dosucc(const * p) const { if (p == 0) return 0; const IChunk* old = ch; const IChunk* t = ch; while (!t->actual_pointer(p)) { t = (t->next()); if (t == old) return 0; } int i = t->index_of(p) + 1; if (i >= fnc) return 0; if (i >= t->fence_index()) t = (t->next()); set_cache(t); return t->pointer_to(i); } * RPlex::dopred(const * p) const { if (p == 0) return 0; const IChunk* old = ch; const IChunk* t = ch; while (!t->actual_pointer(p)) { t = (t->prev()); if (t == old) return 0; } int i = t->index_of(p) - 1; if (i < lo) return 0; if (i < t->low_index()) t = (t->prev()); set_cache(t); return (t->pointer_to(i)); } int RPlex::add_high(const elem) { IChunk* t = tl(); if (!t->can_grow_high()) { if (t->IChunk::empty() && one_chunk()) { t->clear(fnc); base = t->base_index() - lch * csize; } else { * data = new [csize]; t = (new IChunk(data, fnc, fnc, fnc,fnc+csize)); t->link_to_prev(tl()); if (fch == maxch) { maxch *= 2; IChunk** newch = new _IChunk_ptr [maxch]; memcpy(newch, chunks, fch * sizeof(_IChunk_ptr)); delete chunks; chunks = newch; } chunks[fch++] = t; } } *((t->IChunk::grow_high())) = elem; set_cache(t); return fnc++; } int RPlex::del_high () { if (empty()) empty_error(); IChunk* t = tl(); if (t->IChunk::empty()) // kill straggler first { IChunk* pred = t->prev(); del_chunk(t); t = (pred); --fch; } t->IChunk::shrink_high(); if (t->IChunk::empty() && !one_chunk()) { IChunk* pred = t->prev(); del_chunk(t); t = (pred); --fch; } set_cache(t); return --fnc - 1; } int RPlex::add_low (const elem) { IChunk* t = hd; if (!t->can_grow_low()) { if (t->IChunk::empty() && one_chunk()) { t->cleardown(lo); base = t->base_index() - lch * csize; } else { * data = new [csize]; hd = new IChunk(data, lo-csize, lo, lo, lo); hd->link_to_next(t); t = ( hd); if (lch == 0) { lch = maxch; fch += maxch; maxch *= 2; IChunk** newch = new _IChunk_ptr [maxch]; memcpy(&(newch[lch]), chunks, lch * sizeof(_IChunk_ptr)); delete chunks; chunks = newch; base = t->base_index() - (lch - 1) * csize; } chunks[--lch] = t; } } *((t->IChunk::grow_low())) = elem; set_cache(t); return --lo; } int RPlex::del_low () { if (empty()) empty_error(); IChunk* t = hd; if (t->IChunk::empty()) { hd = t->next(); del_chunk(t); t = hd; ++lch; } t->IChunk::shrink_low(); if (t->IChunk::empty() && !one_chunk()) { hd = t->next(); del_chunk(t); t = hd; ++lch; } set_cache(t); return ++lo; } void RPlex::reverse() { tmp; int l = lo; int h = fnc - 1; IChunk* loch = hd; IChunk* hich = tl(); while (l < h) { * lptr = loch->pointer_to(l); * hptr = hich->pointer_to(h); tmp = *lptr; *lptr = *hptr; *hptr = tmp; if (++l >= loch->fence_index()) loch = loch->next(); if (--h < hich->low_index()) hich = hich->prev(); } } void RPlex::fill(const x) { for (int i = lo; i < fnc; ++i) (*this)[i] = x; } void RPlex::fill(const x, int lo, int hi) { for (int i = lo; i <= hi; ++i) (*this)[i] = x; } void RPlex::clear() { for (int i = lch + 1; i < fch; ++i) del_chunk(chunks[i]); fch = lch + 1; set_cache(chunks[lch]); ch->IChunk::clear(lo); fnc = lo; } int RPlex::reset_low(int l) { int old = lo; int diff = l - lo; if (diff != 0) { lo += diff; fnc += diff; IChunk* t = hd; do { t->re_index(t->low_index() + diff); t = t->next(); } while (t != hd); } base = hd->base_index() - lch * csize; return old; } int RPlex::OK () const { int v = hd != 0 && ch != 0; // at least one chunk v &= fnc == tl()->fence_index(); // last chunk fnc == plex fnc v &= lo == hd->IChunk::low_index(); // first lo == plex lo v &= base == hd->base_index() - lch * csize; // base is correct; v &= lch < fch; v &= fch <= maxch; // within allocation; // loop for others: int k = lch; // to cross-check nch int found_ch = 0; // to make sure ch is in list; const IChunk* t = (hd); for (;;) { v &= chunks[k++] == t; // each chunk is at proper index if (t == ch) ++found_ch; v &= t->IChunk::OK(); // each chunk is OK if (t == tl()) break; else // and has indices contiguous to succ { v &= t->top_index() == t->next()->base_index(); if (t != hd) // internal chunks full { v &= !t->empty(); v &= !t->can_grow_low(); v &= !t->can_grow_high(); } t = t->next(); } } v &= found_ch == 1; v &= fch == k; if (!v) error("invariant failure"); return v; } ./g++-include/gen/SLBag.ccP100644 0 1 4165 5522102360 13701 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".SLBag.h" int SLBag::OK() { int v = p.OK(); v &= count == p.length(); if (!v) error("invariant failure"); return v; } Pix SLBag::seek( item, Pix i) { if (i == 0) i = first(); else next(i); for (; i != 0 && (!(EQ(p(i), item))); p.next(i)); return i; } int SLBag::nof( item) { int n = 0; for (Pix p = first(); p; next(p)) if (EQ((*this)(p), item)) ++n; return n; } void SLBag::del( item) { Pix i = p.first(); if (i == 0) return; else if (EQ(p(i), item)) { --count; p.del_front(); } else { Pix trail = i; p.next(i); while (i != 0) { if (EQ(p(i), item)) { --count; p.del_after(trail); return; } trail = i; p.next(i); } } } void SLBag::remove( item) { Pix i = p.first(); while (i != 0 && EQ(p(i), item)) { --count; p.del_front(); i = p.first(); } if (i != 0) { Pix trail = i; p.next(i); while (i != 0) { if (EQ(p(i), item)) { --count; p.del_after(trail); i = trail; p.next(i); } else { trail = i; p.next(i); } } } } ./g++-include/gen/SLList.ccP100644 0 1 12171 5522102360 14137 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- // WARNING: This file is obsolete. Use ../SLList.cc, if you can. /* Copyright (C) 1988 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include #include #include ".SLList.h" void SLList::error(const char* msg) { (*lib_error_handler)("SLList", msg); } int SLList::length() { int l = 0; SLListNode* t = last; if (t != 0) do { ++l; t = t->tl; } while (t != last); return l; } SLList::SLList(const SLList& a) { if (a.last == 0) last = 0; else { SLListNode* p = a.last->tl; SLListNode* h = new SLListNode(p->hd); last = h; for (;;) { if (p == a.last) { last->tl = h; return; } p = p->tl; SLListNode* n = new SLListNode(p->hd); last->tl = n; last = n; } } } SLList& SLList::operator = (const SLList& a) { if (last != a.last) { clear(); if (a.last != 0) { SLListNode* p = a.last->tl; SLListNode* h = new SLListNode(p->hd); last = h; for (;;) { if (p == a.last) { last->tl = h; break; } p = p->tl; SLListNode* n = new SLListNode(p->hd); last->tl = n; last = n; } } } return *this; } void SLList::clear() { if (last == 0) return; SLListNode* p = last->tl; last->tl = 0; last = 0; while (p != 0) { SLListNode* nxt = p->tl; delete(p); p = nxt; } } Pix SLList::prepend( item) { SLListNode* t = new SLListNode(item); if (last == 0) t->tl = last = t; else { t->tl = last->tl; last->tl = t; } return Pix(t); } Pix SLList::prepend(SLListNode* t) { if (t == 0) return 0; if (last == 0) t->tl = last = t; else { t->tl = last->tl; last->tl = t; } return Pix(t); } Pix SLList::append( item) { SLListNode* t = new SLListNode(item); if (last == 0) t->tl = last = t; else { t->tl = last->tl; last->tl = t; last = t; } return Pix(t); } Pix SLList::append(SLListNode* t) { if (t == 0) return 0; if (last == 0) t->tl = last = t; else { t->tl = last->tl; last->tl = t; last = t; } return Pix(t); } void SLList::join(SLList& b) { SLListNode* t = b.last; b.last = 0; if (last == 0) last = t; else if (t != 0) { SLListNode* f = last->tl; last->tl = t->tl; t->tl = f; last = t; } } Pix SLList::ins_after(Pix p, item) { SLListNode* u = (SLListNode*)p; SLListNode* t = new SLListNode(item); if (last == 0) t->tl = last = t; else if (u == 0) // ins_after 0 means prepend { t->tl = last->tl; last->tl = t; } else { t->tl = u->tl; u->tl = t; if (u == last) last = t; } return Pix(t); } void SLList::del_after(Pix p) { SLListNode* u = (SLListNode*)p; if (last == 0 || u == last) error("cannot del_after last"); if (u == 0) u = last; // del_after 0 means delete first SLListNode* t = u->tl; if (u == t) last = 0; else { u->tl = t->tl; if (last == t) last = u; } delete t; } int SLList::owns(Pix p) { SLListNode* t = last; if (t != 0 && p != 0) { do { if (Pix(t) == p) return 1; t = t->tl; } while (t != last); } return 0; } SLList::remove_front() { if (last == 0) error("remove_front of empty list"); SLListNode* t = last->tl; res = t->hd; if (t == last) last = 0; else last->tl = t->tl; delete t; return res; } int SLList::remove_front(& x) { if (last == 0) return 0; else { SLListNode* t = last->tl; x = t->hd; if (t == last) last = 0; else last->tl = t->tl; delete t; return 1; } } void SLList::del_front() { if (last == 0) error("del_front of empty list"); SLListNode* t = last->tl; if (t == last) last = 0; else last->tl = t->tl; delete t; } int SLList::OK() { int v = 1; if (last != 0) { SLListNode* t = last; long count = LONG_MAX; // Lots of chances to find last! do { count--; t = t->tl; } while (count > 0 && t != last); v &= count > 0; } if (!v) error("invariant failure"); return v; } ./g++-include/gen/SLQueue.ccP100644 0 1 107 5522102361 14245 0ustar rootdaemon#ifdef __GNUG__ #pragma implementation #endif #include ".SLQueue.h" ./g++-include/gen/SLSet.ccP100644 0 1 3225 5522102362 13741 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".SLSet.h" int SLSet::OK() { int v = p.OK(); v &= count == p.length(); if (!v) error("invariant failure"); return v; } Pix SLSet::seek( item) { for (Pix i = p.first(); i != 0 && !EQ(p(i),item); p.next(i)); return i; } Pix SLSet::add( item) { Pix i = seek(item); if (i == 0) { ++count; i = p.append(item); } return i; } void SLSet::del( item) { Pix i = p.first(); if (i == 0) return; else if (EQ(p(i), item)) { --count; p.del_front(); } else { Pix trail = i; p.next(i); while (i != 0) { if (EQ(p(i), item)) { --count; p.del_after(trail); return; } trail = i; p.next(i); } } } ./g++-include/gen/SLStack.ccP100644 0 1 107 5522102363 14230 0ustar rootdaemon#ifdef __GNUG__ #pragma implementation #endif #include ".SLStack.h" ./g++-include/gen/Set.ccP100644 0 1 4637 5522102364 13514 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include ".Set.h" Pix Set::seek( item) { for (Pix i = first(); i != 0 && !(EQ((*this)(i), item)); next(i)); return i; } int Set::owns(Pix idx) { if (idx == 0) return 0; for (Pix i = first(); i; next(i)) if (i == idx) return 1; return 0; } void Set::clear() { Pix i = first(); while (i != 0) { del((*this)(i)); i = first(); } } int Set::contains ( item) { return seek(item) != 0; } int Set::operator <= (Set& b) { if (count > b.count) return 0; if (count == 0) return 1; for (Pix i = first(); i; next(i)) if (b.seek((*this)(i)) == 0) return 0; return 1; } int Set::operator == (Set& b) { int n = count; if (n != b.count) return 0; if (n == 0) return 1; Pix i = first(); Pix j = b.first(); while (n-- > 0) { if ((b.seek((*this)(i)) == 0) || (seek(b(j)) == 0)) return 0; next(i); b.next(j); } return 1; } int Set::operator != (Set& b) { return !(*this == b); } void Set::operator |= (Set& b) { if (&b != this) for (Pix i = b.first(); i; b.next(i)) add(b(i)); } void Set::operator -= (Set& b) { if (&b == this) clear(); else for (Pix i = b.first(); i; b.next(i)) del(b(i)); } void Set::operator &= (Set& b) { if (&b != this) { Pix i = first(); Pix n = i; while (i != 0) { next(n); if (b.seek((*this)(i)) == 0) del((*this)(i)); i = n; } } } void Set::error(const char* msg) { (*lib_error_handler)("Set", msg); } ./g++-include/gen/SkipBag.ccP100644 0 1 14653 5522102364 14320 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* 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. */ /* * Bags implemented via William Pugh SkipList algorithms. * CACM, June 1990, p 668-676. * */ #include #include #include ".SkipBag.h" MLCG* SkipBag::gen = 0; int SkipBaginit::count = 0; static int countbits(long bits) { int n = 0; while(bits>>=1L) n++; return n; } SkipBag::SkipBag(long size) : level(0), header(new SkipBagNode (countbits(size)+1)), max_levels (countbits(size)+1), random_bits(gen->asLong()), randoms_left(BITS_IN_RANDOM / 2) { SkipBagNodePtr *buffer_start = header->forward; SkipBagNodePtr *trav = &header->forward[max_levels]; count = 0; while (trav > buffer_start) *--trav = (SkipBagNodePtr) header; } SkipBag::SkipBag(SkipBag& b) : level (0), header (new SkipBagNode (b.max_levels)), max_levels (b.max_levels), random_bits (gen->asLong()), randoms_left (BITS_IN_RANDOM / 2) { SkipBagNodePtr *buffer_start = header->forward; SkipBagNodePtr *trav = &header->forward[max_levels]; count = 0; while (trav > buffer_start) *--trav = (SkipBagNodePtr)header; for (SkipBagNodePtr t = b.leftmost(); t; t = b.succ(t)) add(t->item); } Pix SkipBag::add ( item) { SkipBagNodePtr *update = new SkipBagNodePtr[max_levels+1]; SkipBagNodePtr curr = (SkipBagNodePtr) this->header; int l = level; SkipBagNodePtr temp; do { while ((temp = curr->forward[l])!=header && CMP(temp->item, item) < 0) curr = temp; update[l] = curr; } while (--l >= 0); if ((l = random_level ()) > level) { l = ++level; update[l] = (SkipBagNodePtr)header; }; temp = new RealSkipBagNode (item, l); SkipBagNodePtr *temp_forward = temp->forward; do { SkipBagNodePtr *curr_forward = update[l]->forward; temp_forward[l] = curr_forward[l]; curr_forward[l] = temp; } while (--l >= 0); count++; delete update; return Pix(temp); } void SkipBag::del( key) { int l = level; int curr_level = level; SkipBagNodePtr *update = new SkipBagNodePtr[max_levels+1]; SkipBagNodePtr curr = (SkipBagNodePtr)header; SkipBagNodePtr temp; do { while ((temp = curr->forward[l])!=header && CMP(temp->item,key) < 0) curr = temp; update[l] = curr; } while (--l >= 0); if (CMP(temp->item,key)==0) { SkipBagNodePtr *temp_forward = temp->forward; for (l = 0; l <= curr_level && (curr = update[l])->forward[l] == temp; l++) curr->forward[l] = temp_forward[l]; delete temp; SkipBagNodePtr *forward = header->forward; while (forward[curr_level]==header && curr_level > 0) curr_level--; level = curr_level; count--; delete update; return; } } SkipBagNodePtr SkipBag::rightmost() { SkipBagNodePtr temp; SkipBagNode* curr = header; int l = level; do while ((temp = curr->forward[l])!=header) curr = temp; while (--l >= 0); return temp==header ? 0 : temp; } SkipBagNodePtr SkipBag::pred(SkipBagNodePtr t) { SkipBagNodePtr temp, curr = (SkipBagNodePtr) header; int l = level; do while ((temp = curr->forward[l])!=t) curr = temp; while (--l >= 0); return curr == header ? 0 : curr; } void SkipBag::_kill() { SkipBagNode *p = this->header->forward[0]; while (p != header) { SkipBagNodePtr q = p->forward[0]; delete p; p = q; } } void SkipBag::clear() { SkipBagNodePtr *buffer_start = header->forward; SkipBagNodePtr *trav = &header->forward[level+1]; _kill(); count = 0; while (trav > buffer_start) *--trav = (SkipBagNodePtr)header; } Pix SkipBag::seek( key, Pix i) { SkipBagNodePtr temp; SkipBagNode *curr = header; int l = level; if (i) curr = (SkipBagNode *)i; do { while ((temp = curr->forward[l])!=header && CMP(temp->item, key) < 0) curr = temp; } while (--l >= 0); if (CMP(temp->item, key) != 0) return 0; else { return Pix(temp); } } int SkipBag::nof( item) { int n = 0; SkipBagNodePtr t = (SkipBagNodePtr)(seek(item)); if (t != 0) { do { ++n; t = succ(t); } while (t != 0 && EQ(item, t->item)); } return n; } void SkipBag::remove( key) { Pix t = seek(key); while (t != 0) { del(key); t = seek(key); } } /* * 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 SkipBag::random_level (void) { 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 SkipBag::OK() { int v = 1; if (header == 0) v = 0; else { int n = 0; SkipBagNodePtr trail = leftmost(); SkipBagNodePtr t = 0; if (trail) t = succ(trail); if (t) n++; while (t != 0) { ++n; v &= CMP(trail->item, t->item) < 0; trail = t; t = succ(t); } v &= n == count; } if (!v) error("invariant failure"); return v; } SkipBaginit::SkipBaginit() { if (!count) SkipBag::gen = new MLCG(time(0)); count++; } SkipBaginit::~SkipBaginit() { count--; if (!count) delete SkipBag::gen; } ./g++-include/gen/SkipMap.ccP100644 0 1 14720 5522102365 14340 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include #include "..SkipMap.h" /* * Bags implemented via William Pugh SkipList algorithms. * CACM, June 1990, p 668-676. * */ MLCG* SkipMap::gen = 0; int SkipMapinit::count = 0; static int countbits(long bits) { int n = 0; while(bits>>=1) n++; return n; } SkipMap::SkipMap( dflt, long size) : Map(dflt), level(0), header(new SkipMapNode (countbits(size)+1)), max_levels (countbits(size)+1), random_bits(gen->asLong()), randoms_left(BITS_IN_RANDOM / 2) { SkipMapNodePtr *buffer_start = header->forward; SkipMapNodePtr *trav = &header->forward[max_levels]; count = 0; while (trav > buffer_start) *--trav = (SkipMapNodePtr) header; } SkipMap::SkipMap(SkipMap& b) : Map(b.def), level (0), header (new SkipMapNode (b.max_levels)), max_levels (b.max_levels), random_bits (gen->asLong()), randoms_left (BITS_IN_RANDOM / 2) { SkipMapNodePtr *buffer_start = header->forward; SkipMapNodePtr *trav = &header->forward[max_levels]; count = 0; while (trav > buffer_start) *--trav = (SkipMapNodePtr)header; for (SkipMapNodePtr t = b.leftmost(); t; t = b.succ(t)) (*this)[t->item] = t->cont; } & SkipMap::operator [] ( item) { SkipMapNodePtr *update = new SkipMapNodePtr[max_levels+1]; SkipMapNodePtr curr = (SkipMapNodePtr) this->header; int l = level; SkipMapNodePtr temp; do { while ((temp = curr->forward[l])!=header && CMP(temp->item, item) < 0) curr = temp; update[l] = curr; } while (--l >= 0); if (temp != header && CMP(temp->item, item) == 0) { delete update; return temp->cont; } if ((l = random_level ()) > level) { l = ++level; update[l] = (SkipMapNodePtr)header; }; temp = new RealSkipMapNode (item, def, l); SkipMapNodePtr *temp_forward = temp->forward; do { SkipMapNodePtr *curr_forward = update[l]->forward; temp_forward[l] = curr_forward[l]; curr_forward[l] = temp; } while (--l >= 0); count++; delete update; return temp->cont; } void SkipMap::del( key) { int l = level; int curr_level = level; SkipMapNodePtr *update = new SkipMapNodePtr[max_levels+1]; SkipMapNodePtr curr = (SkipMapNodePtr)header; SkipMapNodePtr temp; do { while ((temp = curr->forward[l])!=header && CMP(temp->item,key) < 0) curr = temp; update[l] = curr; } while (--l >= 0); if (CMP(temp->item,key)==0) { SkipMapNodePtr *temp_forward = temp->forward; for (l = 0; l <= curr_level && (curr = update[l])->forward[l] == temp; l++) curr->forward[l] = temp_forward[l]; delete temp; SkipMapNodePtr *forward = header->forward; while (forward[curr_level]==header && curr_level > 0) curr_level--; level = curr_level; count--; delete update; return; } } SkipMapNodePtr SkipMap::rightmost() { SkipMapNodePtr temp; SkipMapNode* curr = header; int l = level; do while ((temp = curr->forward[l])!=header) curr = temp; while (--l >= 0); return temp==header ? 0 : temp; } SkipMapNodePtr SkipMap::pred(SkipMapNodePtr t) { SkipMapNodePtr temp, curr = (SkipMapNodePtr) header; int l = level; do while ((temp = curr->forward[l])!=t) curr = temp; while (--l >= 0); return curr == header ? 0 : curr; } void SkipMap::_kill() { SkipMapNode *p = this->header->forward[0]; while (p != header) { SkipMapNodePtr q = p->forward[0]; delete p; p = q; } } void SkipMap::clear() { SkipMapNodePtr *buffer_start = header->forward; SkipMapNodePtr *trav = &header->forward[level+1]; _kill(); count = 0; while (trav > buffer_start) *--trav = (SkipMapNodePtr)header; } Pix SkipMap::seek( key) { SkipMapNodePtr temp; SkipMapNode *curr = header; int l = level; do { while ((temp = curr->forward[l])!=header && CMP(temp->item, key) < 0) curr = temp; } while (--l >= 0); if (CMP(temp->item, key) != 0) 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 SkipMap::random_level (void) { 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 SkipMap::OK() { int v = 1; if (header == 0) v = 0; else { int n = 0; SkipMapNodePtr trail = leftmost(); SkipMapNodePtr t = 0; if (trail) t = succ(trail); if (t) n++; while (t != 0) { ++n; v &= CMP(trail->item, t->item) < 0; trail = t; t = succ(t); } v &= n == count; } if (!v) error("invariant failure"); return v; } SkipMapinit::SkipMapinit() { if (!count) SkipMap::gen = new MLCG(time(0)); count++; } SkipMapinit::~SkipMapinit() { count--; if (!count) delete SkipMap::gen; } ./g++-include/gen/SkipSet.ccP100644 0 1 17255 5522102366 14365 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* 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 ".SkipSet.h" MLCG* SkipSet::gen = 0; int SkipSetinit::count = 0; static int countbits(long bits) { int n = 0; while(bits>>=1L) n++; return n; } SkipSet::SkipSet(long size) : level(0), header(new SkipSetNode (countbits(size)+1)), max_levels (countbits(size)+1), random_bits(gen->asLong()), randoms_left(BITS_IN_RANDOM / 2) { SkipSetNodePtr *buffer_start = header->forward; SkipSetNodePtr *trav = &header->forward[max_levels]; count = 0; while (trav > buffer_start) *--trav = (SkipSetNodePtr) header; } SkipSet::SkipSet(SkipSet& b) : level (0), header (new SkipSetNode (b.max_levels)), max_levels (b.max_levels), random_bits (gen->asLong()), randoms_left (BITS_IN_RANDOM / 2) { SkipSetNodePtr *buffer_start = header->forward; SkipSetNodePtr *trav = &header->forward[max_levels]; count = 0; while (trav > buffer_start) *--trav = (SkipSetNodePtr)header; for (SkipSetNodePtr t = b.leftmost(); t; t = b.succ(t)) add(t->item); } /* relationals */ int SkipSet::operator == (SkipSet& y) { if (count != y.count) return 0; else { SkipSetNodePtr t = leftmost(); SkipSetNodePtr u = y.leftmost(); for (;;) { if (t == 0) return 1; else if (!EQ(t->item, u->item)) return 0; else { t = succ(t); u = y.succ(u); } } } } int SkipSet::operator <= (SkipSet& y) { if (count > y.count) return 0; else { SkipSetNodePtr t = leftmost(); SkipSetNodePtr u = y.leftmost(); for (;;) { if (t == 0) return 1; else if (u == 0) return 0; int cmp = CMP(t->item, u->item); if (cmp == 0) { t = succ(t); u = y.succ(u); } else if (cmp < 0) return 0; else u = y.succ(u); } } } void SkipSet::operator |=(SkipSet& y) { if (&y == this) return; SkipSetNodePtr u = y.leftmost(); while (u != 0) { add(u->item); u = y.succ(u); } } void SkipSet::operator &= (SkipSet& y) { if (y.count == 0) clear(); else if (&y != this && count != 0) { SkipSetNodePtr t = leftmost(); while (t != 0) { SkipSetNodePtr s = succ(t); if (y.seek(t->item) == 0) del(t->item); t = s; } } } void SkipSet::operator -=(SkipSet& y) { if (&y == this) clear(); else if (y.count != 0) { SkipSetNodePtr t = leftmost(); while (t != 0) { SkipSetNodePtr s = succ(t); if (y.seek(t->item) != 0) del(t->item); t = s; } } } Pix SkipSet::add ( i) { SkipSetNodePtr *update = new SkipSetNodePtr[max_levels+1]; SkipSetNodePtr curr = (SkipSetNodePtr) this->header; int l = level; SkipSetNodePtr temp; do { while ((temp = curr->forward[l])!=header && CMP(temp->item, i) < 0) curr = temp; update[l] = curr; } while (--l >= 0); if (temp != header && CMP(temp->item, i) == 0) return Pix(temp); if ((l = random_level ()) > level) { l = ++level; update[l] = (SkipSetNodePtr)header; }; temp = new RealSkipSetNode (i, l); SkipSetNodePtr *temp_forward = temp->forward; do { SkipSetNodePtr *curr_forward = update[l]->forward; temp_forward[l] = curr_forward[l]; curr_forward[l] = temp; } while (--l >= 0); count++; delete update; return Pix(temp); } void SkipSet::del( key) { int l = level; int curr_level = level; SkipSetNodePtr *update = new SkipSetNodePtr[max_levels+1]; SkipSetNodePtr curr = (SkipSetNodePtr)header; SkipSetNodePtr temp; do { while ((temp = curr->forward[l])!=header && CMP(temp->item,key) < 0) curr = temp; update[l] = curr; } while (--l >= 0); if (CMP(temp->item,key)==0) { SkipSetNodePtr *temp_forward = temp->forward; for (l = 0; l <= curr_level && (curr = update[l])->forward[l] == temp; l++) curr->forward[l] = temp_forward[l]; delete temp; SkipSetNodePtr *forward = header->forward; while (forward[curr_level]==header && curr_level > 0) curr_level--; level = curr_level; count--; delete update; return; } } SkipSetNodePtr SkipSet::rightmost() { SkipSetNodePtr temp; SkipSetNode* curr = header; int l = level; do while ((temp = curr->forward[l])!=header) curr = temp; while (--l >= 0); return temp==header ? 0 : temp; } SkipSetNodePtr SkipSet::pred(SkipSetNodePtr t) { SkipSetNodePtr temp, curr = (SkipSetNodePtr) header; int l = level; do while ((temp = curr->forward[l])!=t) curr = temp; while (--l >= 0); return curr == header ? 0 : curr; } void SkipSet::_kill() { SkipSetNode *p = this->header->forward[0]; while (p != header) { SkipSetNodePtr q = p->forward[0]; delete p; p = q; } } void SkipSet::clear() { SkipSetNodePtr *buffer_start = header->forward; SkipSetNodePtr *trav = &header->forward[level+1]; _kill(); count = 0; while (trav > buffer_start) *--trav = (SkipSetNodePtr)header; } Pix SkipSet::seek( key) { SkipSetNodePtr temp; SkipSetNode *curr = header; int l = level; do { while ((temp = curr->forward[l])!=header && CMP(temp->item, key) < 0) curr = temp; } while (--l >= 0); if (CMP(temp->item, key) != 0) 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 SkipSet::random_level (void) { 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 SkipSet::OK() { int v = 1; if (header == 0) v = 0; else { int n = 0; SkipSetNodePtr trail = leftmost(); SkipSetNodePtr t = 0; if (trail) t = succ(trail); if (t) n++; while (t != 0) { ++n; v &= CMP(trail->item, t->item) < 0; trail = t; t = succ(t); } v &= n == count; } if (!v) error("invariant failure"); return v; } SkipSetinit::SkipSetinit() { if (!count) SkipSet::gen = new MLCG(time(0)); count++; } SkipSetinit::~SkipSetinit() { count--; if (!count) delete SkipSet::gen; } ./g++-include/gen/SplayBag.ccP100644 0 1 20273 5522102367 14500 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include ".SplayBag.h" /* struct to simulate the special `null' node in the Sleater & Tarjan JACM 1985 splay tree algorithms All routines use a version of their `simple top-down' splay alg. (p 669) */ struct _dummySplayNode { SplayNode* lt; SplayNode* rt; SplayNode* par; } _dummy_null; /* traversal primitives */ SplayNode* SplayBag::leftmost() { SplayNode* t = root; if (t != 0) while (t->lt != 0) t = t->lt; return t; } SplayNode* SplayBag::rightmost() { SplayNode* t = root; if (t != 0) while (t->rt != 0) t = t->rt; return t; } SplayNode* SplayBag::succ(SplayNode* t) { if (t == 0) return 0; if (t->rt != 0) { t = t->rt; while (t->lt != 0) t = t->lt; return t; } else { for (;;) { if (t->par == 0 || t == t->par->lt) return t->par; else t = t->par; } } } SplayNode* SplayBag::pred(SplayNode* t) { if (t == 0) return 0; else if (t->lt != 0) { t = t->lt; while (t->rt != 0) t = t->rt; return t; } else { for (;;) { if (t->par == 0 || t == t->par->rt) return t->par; else t = t->par; } } } Pix SplayBag::seek( key, Pix i) { if (root == 0) return 0; SplayNode* t = (SplayNode*) i; if (t != 0) { int cmp = CMP(key, t->item); if (cmp == 0) { t = succ(t); if (t != 0 && EQ(key, t->item)) return Pix(t); else return 0; } else if (cmp < 0) return 0; } t = root; int comp = CMP(key, t->item); if (comp == 0) return Pix(t); SplayNode* dummy = (SplayNode*)(&_dummy_null); SplayNode* l = dummy; SplayNode* r = dummy; dummy->rt = dummy->lt = dummy->par = 0; while (comp != 0) { if (comp > 0) { SplayNode* tr = t->rt; if (tr == 0) break; else { comp = CMP(key, tr->item); if (comp <= 0 || tr->rt == 0) { l->rt = t; t->par = l; l = t; t = tr; if (comp >= 0) break; } else { if ((t->rt = tr->lt) != 0) t->rt->par = t; tr->lt = t; t->par = tr; l->rt = tr; tr->par = l; l = tr; t = tr->rt; comp = CMP(key, t->item); } } } else { SplayNode* tl = t->lt; if (tl == 0) break; else { comp = CMP(key, tl->item); if (comp >= 0 || tl->lt == 0) { r->lt = t; t->par = r; r = t; t = tl; if (comp <= 0) break; } else { if ((t->lt = tl->rt) != 0) t->lt->par = t; tl->rt = t; t->par = tl; r->lt = tl; tl->par = r; r = tl; t = tl->lt; comp = CMP(key, t->item); } } } } if ((r->lt = t->rt) != 0) r->lt->par = r; if ((l->rt = t->lt) != 0) l->rt->par = l; if ((t->lt = dummy->rt) != 0) t->lt->par = t; if ((t->rt = dummy->lt) != 0) t->rt->par = t; t->par = 0; root = t; if (comp != 0) return 0; else { l = pred(t); while (l != 0 && EQ(l->item, key)) { t = l; l = pred(l); } return Pix(t); } } int SplayBag::nof( item) { int n = 0; SplayNode* t = (SplayNode*)(seek(item)); if (t != 0) { do { ++n; t = succ(t); } while (t != 0 && EQ(item, t->item)); } return n; } Pix SplayBag::add( item) { ++count; SplayNode* newnode = new SplayNode(item); SplayNode* t = root; if (t == 0) { root = newnode; return Pix(root); } int comp = CMP(item, t->item); SplayNode* dummy = (SplayNode*)(&_dummy_null); SplayNode* l = dummy; SplayNode* r = dummy; dummy->rt = dummy->lt = dummy->par = 0; int done = 0; while (!done) { if (comp >= 0) { SplayNode* tr = t->rt; if (tr == 0) { tr = newnode; comp = 0; done = 1; } else comp = CMP(item, tr->item); if (comp <= 0) { l->rt = t; t->par = l; l = t; t = tr; } else { SplayNode* trr = tr->rt; if (trr == 0) { trr = newnode; comp = 0; done = 1; } else comp = CMP(item, trr->item); if ((t->rt = tr->lt) != 0) t->rt->par = t; tr->lt = t; t->par = tr; l->rt = tr; tr->par = l; l = tr; t = trr; } } else { SplayNode* tl = t->lt; if (tl == 0) { tl = newnode; comp = 0; done = 1; } else comp = CMP(item, tl->item); if (comp >= 0) { r->lt = t; t->par = r; r = t; t = tl; } else { SplayNode* tll = tl->lt; if (tll == 0) { tll = newnode; comp = 0; done = 1; } else comp = CMP(item, tll->item); if ((t->lt = tl->rt) != 0) t->lt->par = t; tl->rt = t; t->par = tl; r->lt = tl; tl->par = r; r = tl; t = tll; } } } if ((r->lt = t->rt) != 0) r->lt->par = r; if ((l->rt = t->lt) != 0) l->rt->par = l; if ((t->lt = dummy->rt) != 0) t->lt->par = t; if ((t->rt = dummy->lt) != 0) t->rt->par = t; t->par = 0; root = t; return Pix(root); } void SplayBag::_del(SplayNode* t) { if (t == 0) return; SplayNode* p = t->par; --count; if (t->rt == 0) { if (t == root) { if ((root = t->lt) != 0) root->par = 0; } else if (t == p->lt) { if ((p->lt = t->lt) != 0) p->lt->par = p; } else if ((p->rt = t->lt) != 0) p->rt->par = p; } else { SplayNode* r = t->rt; SplayNode* l = r->lt; for(;;) { if (l == 0) { if (t == root) { root = r; r->par = 0; } else if (t == p->lt) { p->lt = r; r->par = p; } else { p->rt = r; r->par = p; } if ((r->lt = t->lt) != 0) r->lt->par = r; break; } else { if ((r->lt = l->rt) != 0) r->lt->par = r; l->rt = r; r->par = l; r = l; l = l->lt; } } } delete t; } void SplayBag::remove( key) { SplayNode* t = (SplayNode*)(seek(key)); while (t != 0) { _del(t); t = (SplayNode*)(seek(key)); } } void SplayBag::_kill(SplayNode* t) { if (t != 0) { _kill(t->lt); _kill(t->rt); delete t; } } SplayNode* SplayBag::_copy(SplayNode* t) { if (t != 0) { SplayNode* l = _copy(t->lt); SplayNode* r = _copy(t->rt); SplayNode* x = new SplayNode(t->item, l, r); if (l != 0) l->par = x; if (r != 0) r->par = x; return x; } else return 0; } int SplayBag::OK() { int v = 1; if (root == 0) v = count == 0; else { int n = 1; SplayNode* trail = leftmost(); SplayNode* t = succ(trail); while (t != 0) { ++n; v &= CMP(trail->item, t->item) <= 0; trail = t; t = succ(t); } v &= n == count; } if (!v) error("invariant failure"); return v; } ./g++-include/gen/SplayMap.ccP100644 0 1 17414 5522102370 14521 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include "..SplayMap.h" /* struct to simulate the special `null' node in the Sleater & Tarjan JACM 1985 splay tree algorithms All routines use a version of their `simple top-down' splay alg. (p 669) */ struct _dummySplayNode { SplayNode* lt; SplayNode* rt; SplayNode* par; } _dummy_null; /* traversal primitives */ SplayNode* SplayMap::leftmost() { SplayNode* t = root; if (t != 0) while (t->lt != 0) t = t->lt; return t; } SplayNode* SplayMap::rightmost() { SplayNode* t = root; if (t != 0) while (t->rt != 0) t = t->rt; return t; } SplayNode* SplayMap::succ(SplayNode* t) { if (t == 0) return 0; if (t->rt != 0) { t = t->rt; while (t->lt != 0) t = t->lt; return t; } else { for (;;) { if (t->par == 0 || t == t->par->lt) return t->par; else t = t->par; } } } SplayNode* SplayMap::pred(SplayNode* t) { if (t == 0) return 0; else if (t->lt != 0) { t = t->lt; while (t->rt != 0) t = t->rt; return t; } else { for (;;) { if (t->par == 0 || t == t->par->rt) return t->par; else t = t->par; } } } Pix SplayMap::seek( key) { SplayNode* t = root; if (t == 0) return 0; int comp = CMP(key, t->item); if (comp == 0) return Pix(t); SplayNode* dummy = (SplayNode*)(&_dummy_null); SplayNode* l = dummy; SplayNode* r = dummy; dummy->rt = dummy->lt = dummy->par = 0; while (comp != 0) { if (comp > 0) { SplayNode* tr = t->rt; if (tr == 0) break; else { comp = CMP(key, tr->item); if (comp <= 0 || tr->rt == 0) { l->rt = t; t->par = l; l = t; t = tr; if (comp >= 0) break; } else { if ((t->rt = tr->lt) != 0) t->rt->par = t; tr->lt = t; t->par = tr; l->rt = tr; tr->par = l; l = tr; t = tr->rt; comp = CMP(key, t->item); } } } else { SplayNode* tl = t->lt; if (tl == 0) break; else { comp = CMP(key, tl->item); if (comp >= 0 || tl->lt == 0) { r->lt = t; t->par = r; r = t; t = tl; if (comp <= 0) break; } else { if ((t->lt = tl->rt) != 0) t->lt->par = t; tl->rt = t; t->par = tl; r->lt = tl; tl->par = r; r = tl; t = tl->lt; comp = CMP(key, t->item); } } } } if ((r->lt = t->rt) != 0) r->lt->par = r; if ((l->rt = t->lt) != 0) l->rt->par = l; if ((t->lt = dummy->rt) != 0) t->lt->par = t; if ((t->rt = dummy->lt) != 0) t->rt->par = t; t->par = 0; root = t; return (comp == 0) ? Pix(t) : 0; } & SplayMap::operator [] ( item) { SplayNode* t = root; if (t == 0) { ++count; root = new SplayNode(item, def); return root->cont; } int comp = CMP(item, t->item); if (comp == 0) return t->cont; SplayNode* dummy = (SplayNode*)(&_dummy_null); SplayNode* l = dummy; SplayNode* r = dummy; dummy->rt = dummy->lt = dummy->par = 0; while (comp != 0) { if (comp > 0) { SplayNode* tr = t->rt; if (tr == 0) { ++count; tr = new SplayNode(item, def); comp = 0; } else comp = CMP(item, tr->item); if (comp <= 0) { l->rt = t; t->par = l; l = t; t = tr; } else { SplayNode* trr = tr->rt; if (trr == 0) { ++count; trr = new SplayNode(item, def); comp = 0; } else comp = CMP(item, trr->item); if ((t->rt = tr->lt) != 0) t->rt->par = t; tr->lt = t; t->par = tr; l->rt = tr; tr->par = l; l = tr; t = trr; } } else { SplayNode* tl = t->lt; if (tl == 0) { ++count; tl = new SplayNode(item, def); comp = 0; } else comp = CMP(item, tl->item); if (comp >= 0) { r->lt = t; t->par = r; r = t; t = tl; } else { SplayNode* tll = tl->lt; if (tll == 0) { ++count; tll = new SplayNode(item, def); comp = 0; } else comp = CMP(item, tll->item); if ((t->lt = tl->rt) != 0) t->lt->par = t; tl->rt = t; t->par = tl; r->lt = tl; tl->par = r; r = tl; t = tll; } } } if ((r->lt = t->rt) != 0) r->lt->par = r; if ((l->rt = t->lt) != 0) l->rt->par = l; if ((t->lt = dummy->rt) != 0) t->lt->par = t; if ((t->rt = dummy->lt) != 0) t->rt->par = t; t->par = 0; root = t; return root->cont; } void SplayMap::del( key) { SplayNode* t = (SplayNode*)(seek(key)); if (t == 0) return; SplayNode* p = t->par; --count; if (t->rt == 0) { if (t == root) { if ((root = t->lt) != 0) root->par = 0; } else if (t == p->lt) { if ((p->lt = t->lt) != 0) p->lt->par = p; } else if ((p->rt = t->lt) != 0) p->rt->par = p; } else { SplayNode* r = t->rt; SplayNode* l = r->lt; for(;;) { if (l == 0) { if (t == root) { root = r; r->par = 0; } else if (t == p->lt) { p->lt = r; r->par = p; } else { p->rt = r; r->par = p; } if ((r->lt = t->lt) != 0) r->lt->par = r; break; } else { if ((r->lt = l->rt) != 0) r->lt->par = r; l->rt = r; r->par = l; r = l; l = l->lt; } } } delete t; } void SplayMap::_kill(SplayNode* t) { if (t != 0) { _kill(t->lt); _kill(t->rt); delete t; } } SplayNode* SplayMap::_copy(SplayNode* t) { if (t != 0) { SplayNode* l = _copy(t->lt); SplayNode* r = _copy(t->rt); SplayNode* x = new SplayNode(t->item, t->cont, l, r); if (l != 0) l->par = x; if (r != 0) r->par = x; return x; } else return 0; } int SplayMap::OK() { int v = 1; if (root == 0) v = count == 0; else { int n = 1; SplayNode* trail = leftmost(); SplayNode* t = succ(trail); while (t != 0) { ++n; v &= CMP(trail->item, t->item) < 0; trail = t; t = succ(t); } v &= n == count; } if (!v) error("invariant failure"); return v; } ./g++-include/gen/SplayNode.ccP100644 0 1 1611 5522102370 14641 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1992 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".SplayNode.h" ./g++-include/gen/SplayPQ.ccP100644 0 1 23306 5522102371 14322 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include ".SplayPQ.h" /* struct to simulate the special `null' node in the Sleater & Tarjan JACM 1985 splay tree algorithms All routines use a version of their `simple top-down' splay alg. (p 669) */ struct _dummySplayNode { SplayNode* lt; SplayNode* rt; SplayNode* par; } _dummy_null; /* traversal primitives */ SplayNode* SplayPQ::leftmost() { SplayNode* t = root; if (t != 0) while (t->lt != 0) t = t->lt; return t; } SplayNode* SplayPQ::rightmost() { SplayNode* t = root; if (t != 0) while (t->rt != 0) t = t->rt; return t; } SplayNode* SplayPQ::succ(SplayNode* t) { if (t == 0) return 0; if (t->rt != 0) { t = t->rt; while (t->lt != 0) t = t->lt; return t; } else { for (;;) { if (t->par == 0 || t == t->par->lt) return t->par; else t = t->par; } } } SplayNode* SplayPQ::pred(SplayNode* t) { if (t == 0) return 0; else if (t->lt != 0) { t = t->lt; while (t->rt != 0) t = t->rt; return t; } else { for (;;) { if (t->par == 0 || t == t->par->rt) return t->par; else t = t->par; } } } Pix SplayPQ::seek( key) { SplayNode* t = root; if (t == 0) return 0; int comp = CMP(key, t->item); if (comp == 0) return Pix(t); SplayNode* dummy = (SplayNode*)(&_dummy_null); SplayNode* l = dummy; SplayNode* r = dummy; dummy->rt = dummy->lt = dummy->par = 0; while (comp != 0) { if (comp > 0) { SplayNode* tr = t->rt; if (tr == 0) break; else { comp = CMP(key, tr->item); if (comp <= 0 || tr->rt == 0) { l->rt = t; t->par = l; l = t; t = tr; if (comp >= 0) break; } else { if ((t->rt = tr->lt) != 0) t->rt->par = t; tr->lt = t; t->par = tr; l->rt = tr; tr->par = l; l = tr; t = tr->rt; comp = CMP(key, t->item); } } } else { SplayNode* tl = t->lt; if (tl == 0) break; else { comp = CMP(key, tl->item); if (comp >= 0 || tl->lt == 0) { r->lt = t; t->par = r; r = t; t = tl; if (comp <= 0) break; } else { if ((t->lt = tl->rt) != 0) t->lt->par = t; tl->rt = t; t->par = tl; r->lt = tl; tl->par = r; r = tl; t = tl->lt; comp = CMP(key, t->item); } } } } if ((r->lt = t->rt) != 0) r->lt->par = r; if ((l->rt = t->lt) != 0) l->rt->par = l; if ((t->lt = dummy->rt) != 0) t->lt->par = t; if ((t->rt = dummy->lt) != 0) t->rt->par = t; t->par = 0; root = t; return (comp == 0) ? Pix(t) : 0; } Pix SplayPQ::enq( item) { ++count; SplayNode* newnode = new SplayNode(item); SplayNode* t = root; if (t == 0) { root = newnode; return Pix(root); } int comp = CMP(item, t->item); SplayNode* dummy = (SplayNode*)(&_dummy_null); SplayNode* l = dummy; SplayNode* r = dummy; dummy->rt = dummy->lt = dummy->par = 0; int done = 0; while (!done) { if (comp >= 0) { SplayNode* tr = t->rt; if (tr == 0) { tr = newnode; comp = 0; done = 1; } else comp = CMP(item, tr->item); if (comp <= 0) { l->rt = t; t->par = l; l = t; t = tr; } else { SplayNode* trr = tr->rt; if (trr == 0) { trr = newnode; comp = 0; done = 1; } else comp = CMP(item, trr->item); if ((t->rt = tr->lt) != 0) t->rt->par = t; tr->lt = t; t->par = tr; l->rt = tr; tr->par = l; l = tr; t = trr; } } else { SplayNode* tl = t->lt; if (tl == 0) { tl = newnode; comp = 0; done = 1; } else comp = CMP(item, tl->item); if (comp >= 0) { r->lt = t; t->par = r; r = t; t = tl; } else { SplayNode* tll = tl->lt; if (tll == 0) { tll = newnode; comp = 0; done = 1; } else comp = CMP(item, tll->item); if ((t->lt = tl->rt) != 0) t->lt->par = t; tl->rt = t; t->par = tl; r->lt = tl; tl->par = r; r = tl; t = tll; } } } if ((r->lt = t->rt) != 0) r->lt->par = r; if ((l->rt = t->lt) != 0) l->rt->par = l; if ((t->lt = dummy->rt) != 0) t->lt->par = t; if ((t->rt = dummy->lt) != 0) t->rt->par = t; t->par = 0; root = t; return Pix(root); } void SplayPQ::del(Pix pix) { SplayNode* t = (SplayNode*)pix; if (t == 0) return; SplayNode* p = t->par; --count; if (t->rt == 0) { if (t == root) { if ((root = t->lt) != 0) root->par = 0; } else if (t == p->lt) { if ((p->lt = t->lt) != 0) p->lt->par = p; } else if ((p->rt = t->lt) != 0) p->rt->par = p; } else { SplayNode* r = t->rt; SplayNode* l = r->lt; for(;;) { if (l == 0) { if (t == root) { root = r; r->par = 0; } else if (t == p->lt) { p->lt = r; r->par = p; } else { p->rt = r; r->par = p; } if ((r->lt = t->lt) != 0) r->lt->par = r; break; } else { if ((r->lt = l->rt) != 0) r->lt->par = r; l->rt = r; r->par = l; r = l; l = l->lt; } } } delete t; } & SplayPQ::front() { if (root == 0) error ("min: empty tree\n"); // else { SplayNode* t = root; SplayNode* l = root->lt; for(;;) { if (l == 0) { root = t; root->par = 0; return root->item; } else { if ((t->lt = l->rt) != 0) t->lt->par = t; l->rt = t; t->par = l; t = l; l = l->lt; } } } } void SplayPQ::del_front() { if (root != 0) { --count; SplayNode* t = root; SplayNode* l = root->lt; if (l == 0) { if ((root = t->rt) != 0) root->par = 0; delete t; } else { for(;;) { SplayNode* ll = l->lt; if (ll == 0) { if ((t->lt = l->rt) != 0) t->lt->par = t; delete l; break; } else { SplayNode* lll = ll->lt; if (lll == 0) { if ((l->lt = ll->rt) != 0) l->lt->par = l; delete ll; break; } else { t->lt = ll; ll->par = t; if ((l->lt = ll->rt) != 0) l->lt->par = l; ll->rt = l; l->par = ll; t = ll; l = lll; } } } } } } SplayPQ::deq() { if (root == 0) error("deq: empty tree"); // else { --count; SplayNode* t = root; SplayNode* l = root->lt; if (l == 0) { if ((root = t->rt) != 0) root->par = 0; res = t->item; delete t; return res; } else { for(;;) { SplayNode* ll = l->lt; if (ll == 0) { if ((t->lt = l->rt) != 0) t->lt->par = t; res = l->item; delete l; return res; } else { SplayNode* lll = ll->lt; if (lll == 0) { if ((l->lt = ll->rt) != 0) l->lt->par = l; res = ll->item; delete ll; return res; } else { t->lt = ll; ll->par = t; if ((l->lt = ll->rt) != 0) l->lt->par = l; ll->rt = l; l->par = ll; t = ll; l = lll; } } } } } } void SplayPQ::_kill(SplayNode* t) { if (t != 0) { _kill(t->lt); _kill(t->rt); delete t; } } SplayNode* SplayPQ::_copy(SplayNode* t) { if (t != 0) { SplayNode* l = _copy(t->lt); SplayNode* r = _copy(t->rt); SplayNode* x = new SplayNode(t->item, l, r); if (l != 0) l->par = x; if (r != 0) r->par = x; return x; } else return 0; } int SplayPQ::OK() { int v = 1; if (root == 0) v = count == 0; else { int n = 1; SplayNode* trail = leftmost(); SplayNode* t = succ(trail); while (t != 0) { ++n; v &= CMP(trail->item, t->item) < 0; trail = t; t = succ(t); } v &= n == count; } if (!v) error("invariant failure"); return v; } ./g++-include/gen/SplaySet.ccP100644 0 1 22150 5522102372 14532 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include ".SplaySet.h" /* struct to simulate the special `null' node in the Sleater & Tarjan JACM 1985 splay tree algorithms All routines use a version of their `simple top-down' splay alg. (p 669) */ struct _dummySplayNode { SplayNode* lt; SplayNode* rt; SplayNode* par; } _dummy_null; /* traversal primitives */ SplayNode* SplaySet::leftmost() { SplayNode* t = root; if (t != 0) while (t->lt != 0) t = t->lt; return t; } SplayNode* SplaySet::rightmost() { SplayNode* t = root; if (t != 0) while (t->rt != 0) t = t->rt; return t; } SplayNode* SplaySet::succ(SplayNode* t) { if (t == 0) return 0; if (t->rt != 0) { t = t->rt; while (t->lt != 0) t = t->lt; return t; } else { for (;;) { if (t->par == 0 || t == t->par->lt) return t->par; else t = t->par; } } } SplayNode* SplaySet::pred(SplayNode* t) { if (t == 0) return 0; else if (t->lt != 0) { t = t->lt; while (t->rt != 0) t = t->rt; return t; } else { for (;;) { if (t->par == 0 || t == t->par->rt) return t->par; else t = t->par; } } } Pix SplaySet::seek( key) { SplayNode* t = root; if (t == 0) return 0; int comp = CMP(key, t->item); if (comp == 0) return Pix(t); SplayNode* dummy = (SplayNode*)(&_dummy_null); SplayNode* l = dummy; SplayNode* r = dummy; dummy->rt = dummy->lt = dummy->par = 0; while (comp != 0) { if (comp > 0) { SplayNode* tr = t->rt; if (tr == 0) break; else { comp = CMP(key, tr->item); if (comp <= 0 || tr->rt == 0) { l->rt = t; t->par = l; l = t; t = tr; if (comp >= 0) break; } else { if ((t->rt = tr->lt) != 0) t->rt->par = t; tr->lt = t; t->par = tr; l->rt = tr; tr->par = l; l = tr; t = tr->rt; comp = CMP(key, t->item); } } } else { SplayNode* tl = t->lt; if (tl == 0) break; else { comp = CMP(key, tl->item); if (comp >= 0 || tl->lt == 0) { r->lt = t; t->par = r; r = t; t = tl; if (comp <= 0) break; } else { if ((t->lt = tl->rt) != 0) t->lt->par = t; tl->rt = t; t->par = tl; r->lt = tl; tl->par = r; r = tl; t = tl->lt; comp = CMP(key, t->item); } } } } if ((r->lt = t->rt) != 0) r->lt->par = r; if ((l->rt = t->lt) != 0) l->rt->par = l; if ((t->lt = dummy->rt) != 0) t->lt->par = t; if ((t->rt = dummy->lt) != 0) t->rt->par = t; t->par = 0; root = t; return (comp == 0) ? Pix(t) : 0; } Pix SplaySet::add( item) { SplayNode* t = root; if (t == 0) { ++count; root = new SplayNode(item); return Pix(root); } int comp = CMP(item, t->item); if (comp == 0) return Pix(t); SplayNode* dummy = (SplayNode*)(&_dummy_null); SplayNode* l = dummy; SplayNode* r = dummy; dummy->rt = dummy->lt = dummy->par = 0; while (comp != 0) { if (comp > 0) { SplayNode* tr = t->rt; if (tr == 0) { ++count; tr = new SplayNode(item); comp = 0; } else comp = CMP(item, tr->item); if (comp <= 0) { l->rt = t; t->par = l; l = t; t = tr; } else { SplayNode* trr = tr->rt; if (trr == 0) { ++count; trr = new SplayNode(item); comp = 0; } else comp = CMP(item, trr->item); if ((t->rt = tr->lt) != 0) t->rt->par = t; tr->lt = t; t->par = tr; l->rt = tr; tr->par = l; l = tr; t = trr; } } else { SplayNode* tl = t->lt; if (tl == 0) { ++count; tl = new SplayNode(item); comp = 0; } else comp = CMP(item, tl->item); if (comp >= 0) { r->lt = t; t->par = r; r = t; t = tl; } else { SplayNode* tll = tl->lt; if (tll == 0) { ++count; tll = new SplayNode(item); comp = 0; } else comp = CMP(item, tll->item); if ((t->lt = tl->rt) != 0) t->lt->par = t; tl->rt = t; t->par = tl; r->lt = tl; tl->par = r; r = tl; t = tll; } } } if ((r->lt = t->rt) != 0) r->lt->par = r; if ((l->rt = t->lt) != 0) l->rt->par = l; if ((t->lt = dummy->rt) != 0) t->lt->par = t; if ((t->rt = dummy->lt) != 0) t->rt->par = t; t->par = 0; root = t; return Pix(root); } void SplaySet::del( key) { SplayNode* t = (SplayNode*)(seek(key)); if (t == 0) return; SplayNode* p = t->par; --count; if (t->rt == 0) { if (t == root) { if ((root = t->lt) != 0) root->par = 0; } else if (t == p->lt) { if ((p->lt = t->lt) != 0) p->lt->par = p; } else if ((p->rt = t->lt) != 0) p->rt->par = p; } else { SplayNode* r = t->rt; SplayNode* l = r->lt; for(;;) { if (l == 0) { if (t == root) { root = r; r->par = 0; } else if (t == p->lt) { p->lt = r; r->par = p; } else { p->rt = r; r->par = p; } if ((r->lt = t->lt) != 0) r->lt->par = r; break; } else { if ((r->lt = l->rt) != 0) r->lt->par = r; l->rt = r; r->par = l; r = l; l = l->lt; } } } delete t; } void SplaySet::_kill(SplayNode* t) { if (t != 0) { _kill(t->lt); _kill(t->rt); delete t; } } SplayNode* SplaySet::_copy(SplayNode* t) { if (t != 0) { SplayNode* l = _copy(t->lt); SplayNode* r = _copy(t->rt); SplayNode* x = new SplayNode(t->item, l, r); if (l != 0) l->par = x; if (r != 0) r->par = x; return x; } else return 0; } /* relationals */ int SplaySet::operator == (SplaySet& y) { if (count != y.count) return 0; else { SplayNode* t = leftmost(); SplayNode* u = y.leftmost(); for (;;) { if (t == 0) return 1; else if (!EQ(t->item, u->item)) return 0; else { t = succ(t); u = y.succ(u); } } } } int SplaySet::operator <= (SplaySet& y) { if (count > y.count) return 0; else { SplayNode* t = leftmost(); SplayNode* u = y.leftmost(); for (;;) { if (t == 0) return 1; else if (u == 0) return 0; int cmp = CMP(t->item, u->item); if (cmp == 0) { t = succ(t); u = y.succ(u); } else if (cmp < 0) return 0; else u = y.succ(u); } } } void SplaySet::operator |=(SplaySet& y) { if (&y == this) return; SplayNode* u = y.leftmost(); while (u != 0) { add(u->item); u = y.succ(u); } } void SplaySet::operator &= (SplaySet& y) { if (y.count == 0) clear(); else if (&y != this && count != 0) { SplayNode* t = leftmost(); while (t != 0) { SplayNode* s = succ(t); if (y.seek(t->item) == 0) del(t->item); t = s; } } } void SplaySet::operator -=(SplaySet& y) { if (&y == this) clear(); else if (y.count != 0) { SplayNode* t = leftmost(); while (t != 0) { SplayNode* s = succ(t); if (y.seek(t->item) != 0) del(t->item); t = s; } } } int SplaySet::OK() { int v = 1; if (root == 0) v = count == 0; else { int n = 1; SplayNode* trail = leftmost(); SplayNode* t = succ(trail); while (t != 0) { ++n; v &= CMP(trail->item, t->item) < 0; trail = t; t = succ(t); } v &= n == count; } if (!v) error("invariant failure"); return v; } ./g++-include/gen/Stack.ccP100644 0 1 260 5522102373 13772 0ustar rootdaemon#ifdef __GNUG__ #pragma implementation #endif #include ".Stack.h" Stack::~Stack() {} void Stack::error(const char* msg) { (*lib_error_handler)("Stack", msg); } ./g++-include/gen/VHBag.ccP100644 0 1 14175 5522102374 13727 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".VHBag.h" /* codes for status fields */ #define EMPTYCELL 0 #define VALIDCELL 1 #define DELETEDCELL 2 VHBag::VHBag(unsigned int sz) { tab = new [size = sz]; status = new char[size]; for (unsigned int i = 0; i < size; ++i) status[i] = EMPTYCELL; count = 0; } VHBag::VHBag(VHBag& a) { tab = new [size = a.size]; status = new char[size]; for (unsigned int i = 0; i < size; ++i) status[i] = EMPTYCELL; count = 0; for (Pix p = a.first(); p; a.next(p)) add(a(p)); } /* * hashing method: double hash based on high bits of hash fct, * followed by linear probe. Can't do too much better if table * sizes not constrained to be prime. */ static inline unsigned int doublehashinc(unsigned int h, unsigned int s) { unsigned int dh = ((h / s) % s); return (dh > 1)? dh : 1; } Pix VHBag::seek( key, Pix p) { * t = (*) p; if (t == 0 || !EQ(*t, key)) { unsigned int hashval = HASH(key); unsigned int h = hashval % size; for (unsigned int i = 0; i <= size; ++i) { if (status[h] == EMPTYCELL) return 0; else if (status[h] == VALIDCELL && EQ(key, tab[h])) return Pix(&tab[h]); if (i == 0) h = (h + doublehashinc(hashval, size)) % size; else if (++h >= size) h -= size; } return 0; } else { int seent = 0; unsigned int hashval = HASH(key); unsigned int h = hashval % size; for (unsigned int i = 0; i <= size; ++i) { if (status[h] == EMPTYCELL) return 0; else if (&tab[h] == t) seent = 1; else if (seent && status[h] == VALIDCELL && EQ(key, tab[h])) return Pix(&tab[h]); if (i == 0) h = (h + doublehashinc(hashval, size)) % size; else if (++h >= size) h -= size; } return 0; } } int VHBag::nof( item) { int n = 0; unsigned int hashval = HASH(item); unsigned int h = hashval % size; unsigned int firsth = size; for (unsigned int i = 0; i <= size; ++i) { if (status[h] == EMPTYCELL) return n; else if (h != firsth && status[h] == VALIDCELL && EQ(item, tab[h])) { ++n; if (firsth >= size) firsth = h; } if (i == 0) h = (h + doublehashinc(hashval, size)) % size; else if (++h >= size) h -= size; } return n; } Pix VHBag::add( item) { if (HASHTABLE_TOO_CROWDED(count, size)) resize(); unsigned int bestspot = size; unsigned int hashval = HASH(item); unsigned int h = hashval % size; for (unsigned int i = 0; i <= size; ++i) { if (status[h] == EMPTYCELL) { if (bestspot >= size) bestspot = h; tab[bestspot] = item; status[bestspot] = VALIDCELL; ++count; return Pix(&tab[bestspot]); } else if (status[h] == DELETEDCELL) { if (bestspot >= size) bestspot = h; } if (i == 0) h = (h + doublehashinc(hashval, size)) % size; else if (++h >= size) h -= size; } tab[bestspot] = item; status[bestspot] = VALIDCELL; ++count; return Pix(&tab[bestspot]); } void VHBag::del( key) { unsigned int hashval = HASH(key); unsigned int h = hashval % size; for (unsigned int i = 0; i <= size; ++i) { if (status[h] == EMPTYCELL) return; else if (status[h] == VALIDCELL && EQ(key, tab[h])) { status[h] = DELETEDCELL; --count; return; } if (i == 0) h = (h + doublehashinc(hashval, size)) % size; else if (++h >= size) h -= size; } } void VHBag::remove( key) { unsigned int hashval = HASH(key); unsigned int h = hashval % size; for (unsigned int i = 0; i <= size; ++i) { if (status[h] == EMPTYCELL) return; else if (status[h] == VALIDCELL && EQ(key, tab[h])) { status[h] = DELETEDCELL; --count; } if (i == 0) h = (h + doublehashinc(hashval, size)) % size; else if (++h >= size) h -= size; } } void VHBag::clear() { for (unsigned int i = 0; i < size; ++i) status[i] = EMPTYCELL; count = 0; } void VHBag::resize(unsigned int newsize) { if (newsize <= count) { newsize = DEFAULT_INITIAL_CAPACITY; while (HASHTABLE_TOO_CROWDED(count, newsize)) newsize <<= 1; } * oldtab = tab; char* oldstatus = status; unsigned int oldsize = size; tab = new [size = newsize]; status = new char[size]; for (unsigned int i = 0; i < size; ++i) status[i] = EMPTYCELL; count = 0; for (i = 0; i < oldsize; ++i) if (oldstatus[i] == VALIDCELL) add(oldtab[i]); delete [] oldtab; delete oldstatus; } Pix VHBag::first() { for (unsigned int pos = 0; pos < size; ++pos) if (status[pos] == VALIDCELL) return Pix(&tab[pos]); return 0; } void VHBag::next(Pix& i) { if (i == 0) return; unsigned int pos = ((unsigned)i - (unsigned)tab) / sizeof() + 1; for (; pos < size; ++pos) if (status[pos] == VALIDCELL) { i = Pix(&tab[pos]); return; } i = 0; } int VHBag::OK() { int v = tab != 0; v &= status != 0; int n = 0; for (unsigned int i = 0; i < size; ++i) { if (status[i] == VALIDCELL) ++n; else if (status[i] != DELETEDCELL && status[i] != EMPTYCELL) v = 0; } v &= n == count; if (!v) error("invariant failure"); return v; } ./g++-include/gen/VHMap.ccP100644 0 1 11721 5522102375 13746 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include "..VHMap.h" /* codes for status fields */ #define EMPTYCELL 0 #define VALIDCELL 1 #define DELETEDCELL 2 VHMap::VHMap( dflt, unsigned int sz) :Map(dflt) { tab = new [size = sz]; cont = new [size]; status = new char[size]; for (unsigned int i = 0; i < size; ++i) status[i] = EMPTYCELL; } VHMap::VHMap(VHMap& a) : Map(a.def) { tab = new [size = a.size]; cont = new [size]; status = new char[size]; for (unsigned int i = 0; i < size; ++i) status[i] = EMPTYCELL; count = 0; for (Pix p = a.first(); p; a.next(p)) (*this)[a.key(p)] = a.contents(p); } /* * hashing method: double hash based on high bits of hash fct, * followed by linear probe. Can't do too much better if table * sizes not constrained to be prime. */ static inline unsigned int doublehashinc(unsigned int h, unsigned int s) { unsigned int dh = ((h / s) % s); return (dh > 1)? dh : 1; } Pix VHMap::seek( key) { unsigned int hashval = HASH(key); unsigned int h = hashval % size; for (unsigned int i = 0; i <= size; ++i) { if (status[h] == EMPTYCELL) return 0; else if (status[h] == VALIDCELL && EQ(key, tab[h])) return Pix(&tab[h]); if (i == 0) h = (h + doublehashinc(hashval, size)) % size; else if (++h >= size) h -= size; } return 0; } & VHMap::operator []( item) { if (HASHTABLE_TOO_CROWDED(count, size)) resize(); unsigned int bestspot = size; unsigned int hashval = HASH(item); unsigned int h = hashval % size; for (unsigned int i = 0; i <= size; ++i) { if (status[h] == EMPTYCELL) { ++count; if (bestspot >= size) bestspot = h; tab[bestspot] = item; status[bestspot] = VALIDCELL; cont[bestspot] = def; return cont[bestspot]; } else if (status[h] == DELETEDCELL) { if (bestspot >= size) bestspot = h; } else if (EQ(tab[h],item)) return cont[h]; if (i == 0) h = (h + doublehashinc(hashval, size)) % size; else if (++h >= size) h -= size; } ++count; status[bestspot] = VALIDCELL; tab[bestspot] = item; cont[bestspot] = def; return cont[bestspot]; } void VHMap::del( key) { unsigned int hashval = HASH(key); unsigned int h = hashval % size; for (unsigned int i = 0; i <= size; ++i) { if (status[h] == EMPTYCELL) return; else if (status[h] == VALIDCELL && EQ(key, tab[h])) { status[h] = DELETEDCELL; --count; return; } if (i == 0) h = (h + doublehashinc(hashval, size)) % size; else if (++h >= size) h -= size; } } void VHMap::clear() { for (unsigned int i = 0; i < size; ++i) status[i] = EMPTYCELL; count = 0; } void VHMap::resize(unsigned int newsize) { if (newsize <= count) { newsize = DEFAULT_INITIAL_CAPACITY; while (HASHTABLE_TOO_CROWDED(count, newsize)) newsize <<= 1; } * oldtab = tab; * oldcont = cont; char* oldstatus = status; unsigned int oldsize = size; tab = new [size = newsize]; cont = new [size]; status = new char[size]; for (unsigned int i = 0; i < size; ++i) status[i] = EMPTYCELL; count = 0; for (i = 0; i < oldsize; ++i) if (oldstatus[i] == VALIDCELL) (*this)[oldtab[i]] = oldcont[i]; delete [] oldtab; delete [] oldcont; delete oldstatus; } Pix VHMap::first() { for (unsigned int pos = 0; pos < size; ++pos) if (status[pos] == VALIDCELL) return Pix(&tab[pos]); return 0; } void VHMap::next(Pix& i) { if (i == 0) return; unsigned int pos = ((unsigned)i - (unsigned)tab) / sizeof() + 1; for (; pos < size; ++pos) if (status[pos] == VALIDCELL) { i = Pix(&tab[pos]); return; } i = 0; } int VHMap::OK() { int v = tab != 0; v &= status != 0; int n = 0; for (unsigned int i = 0; i < size; ++i) { if (status[i] == VALIDCELL) ++n; else if (status[i] != DELETEDCELL && status[i] != EMPTYCELL) v = 0; } v &= n == count; if (!v) error("invariant failure"); return v; } ./g++-include/gen/VHSet.ccP100644 0 1 13561 5522102375 13770 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".VHSet.h" /* codes for status fields */ #define EMPTYCELL 0 #define VALIDCELL 1 #define DELETEDCELL 2 VHSet::VHSet(unsigned int sz) { tab = new [size = sz]; status = new char[size]; for (unsigned int i = 0; i < size; ++i) status[i] = EMPTYCELL; count = 0; } VHSet::VHSet(VHSet& a) { tab = new [size = a.size]; status = new char[size]; for (unsigned int i = 0; i < size; ++i) status[i] = EMPTYCELL; count = 0; for (Pix p = a.first(); p; a.next(p)) add(a(p)); } /* * hashing method: double hash based on high bits of hash fct, * followed by linear probe. Can't do too much better if table * sizes not constrained to be prime. */ static inline unsigned int doublehashinc(unsigned int h, unsigned int s) { unsigned int dh = ((h / s) % s); return (dh > 1)? dh : 1; } Pix VHSet::seek( key) { unsigned int hashval = HASH(key); unsigned int h = hashval % size; for (unsigned int i = 0; i <= size; ++i) { if (status[h] == EMPTYCELL) return 0; else if (status[h] == VALIDCELL && EQ(key, tab[h])) return Pix(&tab[h]); if (i == 0) h = (h + doublehashinc(hashval, size)) % size; else if (++h >= size) h -= size; } return 0; } Pix VHSet::add( item) { if (HASHTABLE_TOO_CROWDED(count, size)) resize(); unsigned int bestspot = size; unsigned int hashval = HASH(item); unsigned int h = hashval % size; for (unsigned int i = 0; i <= size; ++i) { if (status[h] == EMPTYCELL) { if (bestspot >= size) bestspot = h; tab[bestspot] = item; status[bestspot] = VALIDCELL; ++count; return Pix(&tab[bestspot]); } else if (status[h] == DELETEDCELL) { if (bestspot >= size) bestspot = h; } else if (EQ(tab[h],item)) return Pix(&tab[h]); if (i == 0) h = (h + doublehashinc(hashval, size)) % size; else if (++h >= size) h -= size; } tab[bestspot] = item; status[bestspot] = VALIDCELL; ++count; return Pix(&tab[bestspot]); } void VHSet::del( key) { unsigned int hashval = HASH(key); unsigned int h = hashval % size; for (unsigned int i = 0; i <= size; ++i) { if (status[h] == EMPTYCELL) return; else if (status[h] == VALIDCELL && EQ(key, tab[h])) { status[h] = DELETEDCELL; --count; return; } if (i == 0) h = (h + doublehashinc(hashval, size)) % size; else if (++h >= size) h -= size; } } void VHSet::clear() { for (unsigned int i = 0; i < size; ++i) status[i] = EMPTYCELL; count = 0; } void VHSet::resize(unsigned int newsize) { if (newsize <= count) { newsize = DEFAULT_INITIAL_CAPACITY; while (HASHTABLE_TOO_CROWDED(count, newsize)) newsize <<= 1; } * oldtab = tab; char* oldstatus = status; unsigned int oldsize = size; tab = new [size = newsize]; status = new char[size]; for (unsigned int i = 0; i < size; ++i) status[i] = EMPTYCELL; count = 0; for (i = 0; i < oldsize; ++i) if (oldstatus[i] == VALIDCELL) add(oldtab[i]); delete [] oldtab; delete oldstatus; } Pix VHSet::first() { for (unsigned int pos = 0; pos < size; ++pos) if (status[pos] == VALIDCELL) return Pix(&tab[pos]); return 0; } void VHSet::next(Pix& i) { if (i == 0) return; unsigned int pos = ((unsigned)i - (unsigned)tab) / sizeof() + 1; for (; pos < size; ++pos) if (status[pos] == VALIDCELL) { i = Pix(&tab[pos]); return; } i = 0; } int VHSet:: operator == (VHSet& b) { if (count != b.count) return 0; else { for (unsigned int i = 0; i < size; ++i) if (status[i] == VALIDCELL && b.seek(tab[i]) == 0) return 0; for (i = 0; i < b.size; ++i) if (b.status[i] == VALIDCELL && seek(b.tab[i]) == 0) return 0; return 1; } } int VHSet::operator <= (VHSet& b) { if (count > b.count) return 0; else { for (unsigned int i = 0; i < size; ++i) if (status[i] == VALIDCELL && b.seek(tab[i]) == 0) return 0; return 1; } } void VHSet::operator |= (VHSet& b) { if (&b == this || b.count == 0) return; for (unsigned int i = 0; i < b.size; ++i) if (b.status[i] == VALIDCELL) add(b.tab[i]); } void VHSet::operator &= (VHSet& b) { if (&b == this || count == 0) return; for (unsigned int i = 0; i < size; ++i) { if (status[i] == VALIDCELL && b.seek(tab[i]) == 0) { status[i] = DELETEDCELL; --count; } } } void VHSet::operator -= (VHSet& b) { for (unsigned int i = 0; i < size; ++i) { if (status[i] == VALIDCELL && b.seek(tab[i]) != 0) { status[i] = DELETEDCELL; --count; } } } int VHSet::OK() { int v = tab != 0; v &= status != 0; int n = 0; for (unsigned int i = 0; i < size; ++i) { if (status[i] == VALIDCELL) ++n; else if (status[i] != DELETEDCELL && status[i] != EMPTYCELL) v = 0; } v &= n == count; if (!v) error("invariant failure"); return v; } ./g++-include/gen/VOHSet.ccP100644 0 1 16172 5522102376 14111 0ustar rootdaemon// 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 Doug Schmidt 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include ".VOHSet.h" /* codes for status fields */ #define EMPTYCELL 0 #define VALIDCELL 1 #define DELETEDCELL 2 VOHSet::VOHSet(int sz) { // The size of the hash table is always the smallest power of 2 >= the size // indicated by the user. This allows several optimizations, including // the use of actual double hashing and elimination of the mod instruction. size = 1; while (size < sz) size <<= 1; tab = new [size]; status = new char[size]; for (int i = 0; i < size; ++i) status[i] = EMPTYCELL; count = cnt = 0; } VOHSet::VOHSet(VOHSet& a) { tab = new [size = a.size]; status = new char[size]; for (int i = 0; i < size; ++i) status[i] = EMPTYCELL; count = cnt = 0; for (Pix p = a.first(); p; a.next(p)) add(a(p)); } Pix VOHSet::seek( key) { // Uses ordered double hashing to perform a search of the table. // This greatly speeds up the average-case time for an unsuccessful search. unsigned hashval = HASH(key); // We can avoid the mod operation since size is a power of 2. unsigned h = hashval & (size - 1); // The increment must be odd, since all odd numbers are relatively // prime to a power of 2!! unsigned inc = ((((hashval / size) << 1) + 1) & (size - 1)); // There is always at least 1 empty cell, so this loop is guaranteed to halt! while (status[h] != EMPTYCELL) { int cmp = CMP (key, tab[h]); if (cmp == 0) { if (status[h] == VALIDCELL) return Pix(&tab[h]); else return 0; } else if (cmp < 0) return 0; else h = ((h + inc) & (size - 1)); } return 0; } // This adds an item if it doesn't already exist. By performing the initial // comparison we assure that the table always contains at least 1 empty // spot. This speeds up later searching by a constant factor. // The insertion algorithm uses ordered double hashing. See Standish's // 1980 ``Data Structure's Techniques'' book for details. Pix VOHSet::add( x) { if (size <= cnt+1) resize(); unsigned hashval = HASH(x); unsigned h = hashval & (size - 1); if (status[h] != VALIDCELL) // save some work if possible { if (status[h] == EMPTYCELL) cnt++; count++; tab[h] = x; status[h] = VALIDCELL; return Pix(&tab[h]); } item = x; Pix mypix = 0; unsigned inc = ((((hashval / size) << 1) + 1) & (size - 1)); for (;;) { if (status[h] != VALIDCELL) { if (status[h] == EMPTYCELL) cnt++; count++; tab[h] = item; status[h] = VALIDCELL; return (mypix == 0)? Pix(&tab[h]) : mypix; } int cmp = CMP(item, tab[h]); if (cmp == 0) return (mypix == 0)? Pix(&tab[h]) : mypix; else if (cmp < 0) { temp = tab[h]; tab[h] = item; item = temp; if (mypix == 0) mypix = Pix(&tab[h]); hashval = HASH(item); h = hashval & (size - 1); inc = ((((hashval / size) << 1) + 1) & (size - 1)); } else h = ((h + inc) & (size - 1)); } } void VOHSet::del( key) { // This performs a deletion by marking the item's status field. // Note that we only decrease the count, *not* the cnt, since this // would cause trouble for subsequent steps in the algorithm. See // Reingold and Hanson's ``Data Structure's'' book for a justification // of this approach. unsigned hashval = HASH(key); unsigned h = hashval & (size - 1); unsigned inc = ((((hashval / size) << 1) + 1) & (size - 1)); while (status[h] != EMPTYCELL) { int cmp = CMP(key, tab[h]); if (cmp > 0) h = ((h + inc) & (size - 1)); else if (status[h] == VALIDCELL && cmp == 0) { status[h] = DELETEDCELL; count--; return; } else return; } } void VOHSet::clear() { for (int i = 0; i < size; ++i) status[i] = EMPTYCELL; count = cnt = 0; } void VOHSet::resize(int newsize) { if (newsize <= count) newsize = count; int s = 1; while (s <= newsize) s <<= 1; newsize = s; * oldtab = tab; char* oldstatus = status; int oldsize = size; tab = new [size = newsize]; status = new char[size]; for (int i = 0; i < size; ++i) status[i] = EMPTYCELL; count = cnt = 0; for (i = 0; i < oldsize; ++i) if (oldstatus[i] == VALIDCELL) add(oldtab[i]); delete [] oldtab; delete oldstatus; } Pix VOHSet::first() { for (int pos = 0; pos < size; ++pos) if (status[pos] == VALIDCELL) return Pix(&tab[pos]); return 0; } void VOHSet::next(Pix& i) { if (i == 0) return; int pos = ((unsigned)i - (unsigned)tab) / sizeof() + 1; for (; pos < size; ++pos) if (status[pos] == VALIDCELL) { i = Pix(&tab[pos]); return; } i = 0; } int VOHSet:: operator == (VOHSet& b) { if (count != b.count) return 0; else { for (int i = 0; i < size; ++i) if (status[i] == VALIDCELL && b.seek(tab[i]) == 0) return 0; for (i = 0; i < b.size; ++i) if (b.status[i] == VALIDCELL && seek(b.tab[i]) == 0) return 0; return 1; } } int VOHSet:: operator != (VOHSet& b) { return !(*this == b); } int VOHSet::operator <= (VOHSet& b) { if (count > b.count) return 0; else { for (int i = 0; i < size; ++i) if (status[i] == VALIDCELL && b.seek(tab[i]) == 0) return 0; return 1; } } void VOHSet::operator |= (VOHSet& b) { if (&b == this || b.count == 0) return; for (int i = 0; i < b.size; ++i) if (b.status[i] == VALIDCELL) add(b.tab[i]); } void VOHSet::operator &= (VOHSet& b) { if (&b == this || count == 0) return; for (int i = 0; i < size; ++i) { if (status[i] == VALIDCELL && b.seek(tab[i]) == 0) { status[i] = DELETEDCELL; --count; } } } void VOHSet::operator -= (VOHSet& b) { for (int i = 0; i < size; ++i) { if (status[i] == VALIDCELL && b.seek(tab[i]) != 0) { status[i] = DELETEDCELL; --count; } } } int VOHSet::OK() { int v = tab != 0; v &= status != 0; int n = 0; for (int i = 0; i < size; ++i) { if (status[i] == VALIDCELL) ++n; else if (status[i] != DELETEDCELL && status[i] != EMPTYCELL) v = 0; } v &= n == count; if (!v) error("invariant failure"); return v; } ./g++-include/gen/VQueue.ccP100644 0 1 4140 5522102377 14164 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include ".VQueue.h" VQueue::VQueue(VQueue& b) :size(b.size), cnt(b.cnt), inp(b.inp), outp(b.outp), s(new [b.size]) { int j = outp; for (int i = 0; i < cnt; ++i) { s[j] = b.s[j]; if (++j == size) j = 0; } } void VQueue::operator = (VQueue& b) { if (&b == this) return; if (size != b.size) { delete [] s; s = new [b.size]; size = b.size; } inp = b.inp; outp = b.outp; cnt = b.cnt; int j = outp; for (int i = 0; i < cnt; ++i) { s[j] = b.s[j]; if (++j == size) j = 0; } } void VQueue::resize(int newsz) { if (newsz < cnt) error("resize: new size too small"); * news = new [newsz]; int j = outp; for (int i = 0; i < cnt; ++i) { news[i] = s[j]; if (++j == size) j = 0; } inp = j; outp = 0; delete [] s; s = news; size = newsz; } int VQueue::OK() { int v = s != 0; // have space v &= size >= 0; // a legal size v &= inp >= 0 && inp <= size; // pointers with bounds v &= outp >= 0 && outp <= size; int c = (size + inp - outp) % size; v &= cnt == size || cnt == c; // correct count if (!v) error("invariant failure"); return v; } ./g++-include/gen/VStack.ccP100644 0 1 3414 5522102400 14133 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include ".VStack.h" // error handling VStack::VStack(VStack& b) :size(b.size), ptr(b.ptr), s(new [b.size]) { for (int i = 0; i < ptr; ++i) s[i] = b.s[i]; } void VStack::operator = (VStack& b) { if (&b == this) return; if (size < b.ptr) { delete [] s; s = new [b.size]; size = b.size; } ptr = b.ptr; for (int i = 0; i < ptr; ++i) s[i] = b.s[i]; } void VStack::resize(int newsz) { if (newsz < ptr) error("resize: new size too small"); * news = new [newsz]; for (int i = 0; i < ptr; ++i) news[i] = s[i]; delete [] s; s = news; size = newsz; } int VStack::OK() { int v = s != 0; // have space v &= size >= 0; // a legal size v &= ptr <= size; // ptr within bounds v &= ptr >= 0; if (!v) error("invariant failure"); return v; } ./g++-include/gen/Vec.ccP100644 0 1 30021 5522102401 13470 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include #include #include ".Vec.h" // error handling void default_Vec_error_handler(const char* msg) { cerr << "Fatal Vec error. " << msg << "\n"; exit(1); } one_arg_error_handler_t Vec_error_handler = default_Vec_error_handler; one_arg_error_handler_t set_Vec_error_handler(one_arg_error_handler_t f) { one_arg_error_handler_t old = Vec_error_handler; Vec_error_handler = f; return old; } void Vec::error(const char* msg) { (*Vec_error_handler)(msg); } void Vec::range_error() { (*Vec_error_handler)("Index out of range."); } Vec::Vec(Vec& v) { s = new [len = v.len]; * top = &(s[len]); * t = s; * u = v.s; while (t < top) *t++ = *u++; } Vec::Vec(int l, fill_value) { s = new [len = l]; * top = &(s[len]); * t = s; while (t < top) *t++ = fill_value; } Vec& Vec::operator = (Vec& v) { if (this != &v) { delete [] s; s = new [len = v.len]; * top = &(s[len]); * t = s; * u = v.s; while (t < top) *t++ = *u++; } return *this; } void Vec::apply(Procedure f) { * top = &(s[len]); * t = s; while (t < top) (*f)(*t++); } // can't just realloc since there may be need for constructors/destructors void Vec::resize(int newl) { * news = new [newl]; * p = news; int minl = (len < newl)? len : newl; * top = &(s[minl]); * t = s; while (t < top) *p++ = *t++; delete [] s; s = news; len = newl; } Vec concat(Vec & a, Vec & b) { int newl = a.len + b.len; * news = new [newl]; * p = news; * top = &(a.s[a.len]); * t = a.s; while (t < top) *p++ = *t++; top = &(b.s[b.len]); t = b.s; while (t < top) *p++ = *t++; return Vec(newl, news); } Vec combine(Combiner f, Vec& a, Vec& b) { int newl = (a.len < b.len)? a.len : b.len; * news = new [newl]; * p = news; * top = &(a.s[newl]); * t = a.s; * u = b.s; while (t < top) *p++ = (*f)(*t++, *u++); return Vec(newl, news); } Vec::reduce(Combiner f, base) { r = base; * top = &(s[len]); * t = s; while (t < top) r = (*f)(r, *t++); return r; } Vec reverse(Vec& a) { * news = new [a.len]; if (a.len != 0) { * lo = news; * hi = &(news[a.len - 1]); while (lo < hi) { tmp = *lo; *lo++ = *hi; *hi-- = tmp; } } return Vec(a.len, news); } void Vec::reverse() { if (len != 0) { * lo = s; * hi = &(s[len - 1]); while (lo < hi) { tmp = *lo; *lo++ = *hi; *hi-- = tmp; } } } int Vec::index( targ) { for (int i = 0; i < len; ++i) if (EQ(targ, s[i])) return i; return -1; } Vec map(Mapper f, Vec& a) { * news = new [a.len]; * p = news; * top = &(a.s[a.len]); * t = a.s; while(t < top) *p++ = (*f)(*t++); return Vec(a.len, news); } int operator == (Vec& a, Vec& b) { if (a.len != b.len) return 0; * top = &(a.s[a.len]); * t = a.s; * u = b.s; while (t < top) if (!(EQ(*t++, *u++))) return 0; return 1; } void Vec::fill( val, int from, int n) { int to; if (n < 0) to = len - 1; else to = from + n - 1; if ((unsigned)from > (unsigned)to) range_error(); * t = &(s[from]); * top = &(s[to]); while (t <= top) *t++ = val; } Vec Vec::at(int from, int n) { int to; if (n < 0) { n = len - from; to = len - 1; } else to = from + n - 1; if ((unsigned)from > (unsigned)to) range_error(); * news = new [n]; * p = news; * t = &(s[from]); * top = &(s[to]); while (t <= top) *p++ = *t++; return Vec(n, news); } Vec merge(Vec & a, Vec & b, Comparator f) { int newl = a.len + b.len; * news = new [newl]; * p = news; * topa = &(a.s[a.len]); * as = a.s; * topb = &(b.s[b.len]); * bs = b.s; for (;;) { if (as >= topa) { while (bs < topb) *p++ = *bs++; break; } else if (bs >= topb) { while (as < topa) *p++ = *as++; break; } else if ((*f)(*as, *bs) <= 0) *p++ = *as++; else *p++ = *bs++; } return Vec(newl, news); } static int gsort(*, int, Comparator); void Vec::sort (Comparator compar) { gsort(s, len, compar); } // An adaptation of Schmidt's new quicksort static inline void SWAP(* A, * B) { tmp = *A; *A = *B; *B = tmp; } /* This should be replaced by a standard ANSI macro. */ #define BYTES_PER_WORD 8 #define BYTES_PER_LONG 4 /* The next 4 #defines implement a very fast in-line stack abstraction. */ #define STACK_SIZE (BYTES_PER_WORD * BYTES_PER_LONG) #define PUSH(LOW,HIGH) do {top->lo = LOW;top++->hi = HIGH;} while (0) #define POP(LOW,HIGH) do {LOW = (--top)->lo;HIGH = top->hi;} while (0) #define STACK_NOT_EMPTY (stack < top) /* Discontinue quicksort algorithm when partition gets below this size. This particular magic number was chosen to work best on a Sun 4/260. */ #define MAX_THRESH 4 /* Order size using quicksort. This implementation incorporates four optimizations discussed in Sedgewick: 1. Non-recursive, using an explicit stack of pointer that store the next array partition to sort. To save time, this maximum amount of space required to store an array of MAX_INT is allocated on the stack. Assuming a 32-bit integer, this needs only 32 * sizeof (stack_node) == 136 bits. Pretty cheap, actually. 2. Chose the pivot element using a median-of-three decision tree. This reduces the probability of selecting a bad pivot value and eliminates certain extraneous comparisons. 3. Only quicksorts TOTAL_ELEMS / MAX_THRESH partitions, leaving insertion sort to order the MAX_THRESH items within each partition. This is a big win, since insertion sort is faster for small, mostly sorted array segements. 4. The larger of the two sub-partitions is always pushed onto the stack first, with the algorithm then concentrating on the smaller partition. This *guarantees* no more than log (n) stack size is needed! */ static int gsort ( *base_ptr, int total_elems, Comparator cmp) { /* Stack node declarations used to store unfulfilled partition obligations. */ struct stack_node { *lo; *hi; }; pivot_buffer; int max_thresh = MAX_THRESH; if (total_elems > MAX_THRESH) { *lo = base_ptr; *hi = lo + (total_elems - 1); *left_ptr; *right_ptr; stack_node stack[STACK_SIZE]; /* Largest size needed for 32-bit int!!! */ stack_node *top = stack + 1; while (STACK_NOT_EMPTY) { { *pivot = &pivot_buffer; { /* Select median value from among LO, MID, and HI. Rearrange LO and HI so the three values are sorted. This lowers the probability of picking a pathological pivot value and skips a comparison for both the LEFT_PTR and RIGHT_PTR. */ *mid = lo + ((hi - lo) >> 1); if ((*cmp) (*mid, *lo) < 0) SWAP (mid, lo); if ((*cmp) (*hi, *mid) < 0) { SWAP (mid, hi); if ((*cmp) (*mid, *lo) < 0) SWAP (mid, lo); } *pivot = *mid; pivot = &pivot_buffer; } left_ptr = lo + 1; right_ptr = hi - 1; /* Here's the famous ``collapse the walls'' section of quicksort. Gotta like those tight inner loops! They are the main reason that this algorithm runs much faster than others. */ do { while ((*cmp) (*left_ptr, *pivot) < 0) left_ptr += 1; while ((*cmp) (*pivot, *right_ptr) < 0) right_ptr -= 1; if (left_ptr < right_ptr) { SWAP (left_ptr, right_ptr); left_ptr += 1; right_ptr -= 1; } else if (left_ptr == right_ptr) { left_ptr += 1; right_ptr -= 1; break; } } while (left_ptr <= right_ptr); } /* Set up pointers for next iteration. First determine whether left and right partitions are below the threshold size. If so, ignore one or both. Otherwise, push the larger partition's bounds on the stack and continue sorting the smaller one. */ if ((right_ptr - lo) <= max_thresh) { if ((hi - left_ptr) <= max_thresh) /* Ignore both small partitions. */ POP (lo, hi); else /* Ignore small left partition. */ lo = left_ptr; } else if ((hi - left_ptr) <= max_thresh) /* Ignore small right partition. */ hi = right_ptr; else if ((right_ptr - lo) > (hi - left_ptr)) /* Push larger left partition indices. */ { PUSH (lo, right_ptr); lo = left_ptr; } else /* Push larger right partition indices. */ { PUSH (left_ptr, hi); hi = right_ptr; } } } /* Once the BASE_PTR array is partially sorted by quicksort the rest is completely sorted using insertion sort, since this is efficient for partitions below MAX_THRESH size. BASE_PTR points to the beginning of the array to sort, and END_PTR points at the very last element in the array (*not* one beyond it!). */ { *end_ptr = base_ptr + 1 * (total_elems - 1); *run_ptr; *tmp_ptr = base_ptr; *thresh = (end_ptr < (base_ptr + max_thresh))? end_ptr : (base_ptr + max_thresh); /* Find smallest element in first threshold and place it at the array's beginning. This is the smallest array element, and the operation speeds up insertion sort's inner loop. */ for (run_ptr = tmp_ptr + 1; run_ptr <= thresh; run_ptr += 1) if ((*cmp) (*run_ptr, *tmp_ptr) < 0) tmp_ptr = run_ptr; if (tmp_ptr != base_ptr) SWAP (tmp_ptr, base_ptr); /* Insertion sort, running from left-hand-side up to `right-hand-side.' Pretty much straight out of the original GNU qsort routine. */ for (run_ptr = base_ptr + 1; (tmp_ptr = run_ptr += 1) <= end_ptr; ) { while ((*cmp) (*run_ptr, *(tmp_ptr -= 1)) < 0) ; if ((tmp_ptr += 1) != run_ptr) { *trav; for (trav = run_ptr + 1; --trav >= run_ptr;) { c = *trav; *hi, *lo; for (hi = lo = trav; (lo -= 1) >= tmp_ptr; hi = lo) *hi = *lo; *hi = c; } } } } return 1; } ./g++-include/gen/XPBag.ccP100644 0 1 3354 5522102402 13706 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".XPBag.h" int XPBag::OK() { int v = p.OK(); v &= count == p.length(); if (!v) error("invariant failure"); return v; } Pix XPBag::seek( item, Pix i) { if (i == 0) i = p.first(); else next(i); for (; i != 0; p.next(i)) if (EQ(p(i), item)) return i; return 0; } int XPBag::nof( item) { int n = 0; for (int i = p.low(); i < p.fence(); p.next(i)) if (EQ(p[i], item)) ++n; return n; } void XPBag::del( item) { for (int i = p.low(); i < p.fence(); p.next(i)) { if (EQ(p[i], item)) { --count; p[i] = p.low_element(); p.del_low(); return; } } } void XPBag::remove( item) { for (int i = p.low(); i < p.fence(); p.next(i)) { if (EQ(p[i], item)) { --count; p[i] = p.low_element(); p.del_low(); } } } ./g++-include/gen/XPDeque.ccP100644 0 1 107 5522102403 14232 0ustar rootdaemon#ifdef __GNUG__ #pragma implementation #endif #include ".XPDeque.h" ./g++-include/gen/XPPQ.ccP100644 0 1 5622 5522102403 13536 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".XPPQ.h" int XPPQ::OK() { int v = p.OK(); v &= p.low() == 1; v &= count == p.length(); if (!v) error("invariant failure"); return v; } Pix XPPQ::seek( item) { for (int i = p.low(); i < p.fence(); p.next(i)) if (EQ(p[i],item)) return p.index_to_Pix(i); return 0; } // standard 2-ary heap ops // pointers are used a lot to avoid thrashing across chunks with plexes Pix XPPQ::enq( item) { p.add_high(item); * pk = &(p.high_element()); int par = ++count >> 1; while (par != 0) { * ppar = &(p[par]); if (!(LE(*ppar, item))) { *pk = *ppar; pk = ppar; par >>= 1; } else break; } *pk = item; return Pix(pk); } void XPPQ::del_front() { if (count == 0) error("empty PQ"); --count; * pk = &(p.low_element()); * ph = &(p.high_element()); int child = 2; while (child <= count) { * pchild = &(p[child]); if (child < count) { * prchild = &(p[child+1]); if (!(LE(*pchild, *prchild))) { pchild = prchild; ++child; } } if (!(LE(*ph, *pchild))) { *pk = *pchild; pk = pchild; child <<= 1; } else break; } *pk = *ph; p.del_high(); } void XPPQ::del(Pix i) { if (i == 0) error("null Pix"); --count; int k = p.Pix_to_index(i); * pk = &(p[k]); * ph = &(p.high_element()); int child = k << 1; while (child <= count) { * pchild = &(p[child]); if (child < count) { * prchild = &(p[child+1]); if (!(LE(*pchild, *prchild))) { pchild = prchild; ++child; } } if (!(LE(*ph, *pchild))) { *pk = *pchild; pk = pchild; child <<= 1; } else break; } int par = child >> 2; while (par != 0) { * ppar = &(p[par]); if (!(LE(*ppar, *ph))) { *pk = *ppar; pk = ppar; par >>= 1; } else break; } *pk = *ph; p.del_high(); } ./g++-include/gen/XPQueue.ccP100644 0 1 107 5522102404 14254 0ustar rootdaemon#ifdef __GNUG__ #pragma implementation #endif #include ".XPQueue.h" ./g++-include/gen/XPSet.ccP100644 0 1 3044 5522102405 13747 0ustar rootdaemon// 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) 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".XPSet.h" int XPSet::OK() { int v = p.OK(); v &= count == p.length(); if (!v) error("invariant failure"); return v; } Pix XPSet::seek( item) { for (int i = p.low(); i < p.fence(); p.next(i)) if (EQ(p[i],item)) return p.index_to_Pix(i); return 0; } Pix XPSet::add( item) { Pix i = seek(item); if (i == 0) { ++count; i = p.index_to_Pix(p.add_high(item)); } return i; } void XPSet::del( item) { for (int i = p.low(); i < p.fence(); p.next(i)) { if (EQ(p[i], item)) { --count; p[i] = p.low_element(); p.del_low(); return; } } } ./g++-include/gen/XPStack.ccP100644 0 1 107 5522102406 14237 0ustar rootdaemon#ifdef __GNUG__ #pragma implementation #endif #include ".XPStack.h" ./g++-include/gen/XPlex.ccP100644 0 1 17716 5522102407 14041 0ustar rootdaemon// 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. */ #ifdef __GNUG__ #pragma implementation #endif #include ".XPlex.h" XPlex:: XPlex() { lo = fnc = 0; csize = DEFAULT_INITIAL_CAPACITY; * data = new [csize]; set_cache(new IChunk(data, lo, lo, fnc, lo+csize)); hd = ch; } XPlex:: XPlex(int chunksize) { if (chunksize == 0) error("invalid constructor specification"); lo = fnc = 0; if (chunksize > 0) { csize = chunksize; * data = new [csize]; set_cache(new IChunk(data, lo, lo, fnc, csize)); hd = ch; } else { csize = -chunksize; * data = new [csize]; set_cache(new IChunk(data, chunksize, lo, fnc, fnc)); hd = ch; } } XPlex:: XPlex(int l, int chunksize) { if (chunksize == 0) error("invalid constructor specification"); lo = fnc = l; if (chunksize > 0) { csize = chunksize; * data = new [csize]; set_cache(new IChunk(data, lo, lo, fnc, csize+lo)); hd = ch; } else { csize = -chunksize; * data = new [csize]; set_cache(new IChunk(data, chunksize+lo, lo, fnc, fnc)); hd = ch; } } void XPlex::make_initial_chunks(int up) { int need = fnc - lo; hd = 0; if (up) { int l = lo; do { int sz; if (need >= csize) sz = csize; else sz = need; * data = new [csize]; IChunk* h = new IChunk(data, l, l, l+sz, l+csize); if (hd != 0) h->link_to_next(hd); else hd = h; l += sz; need -= sz; } while (need > 0); } else { int hi = fnc; do { int sz; if (need >= csize) sz = csize; else sz = need; * data = new [csize]; IChunk* h = new IChunk(data, hi-csize, hi-sz, hi, hi); if (hd != 0) h->link_to_next(hd); hd = h; hi -= sz; need -= sz; } while (need > 0); } set_cache(hd); } XPlex:: XPlex(int l, int hi, const initval, int chunksize) { lo = l; fnc = hi + 1; if (chunksize == 0) { csize = fnc - l; make_initial_chunks(1); } else if (chunksize < 0) { csize = -chunksize; make_initial_chunks(0); } else { csize = chunksize; make_initial_chunks(1); } fill(initval); } XPlex::XPlex(const XPlex& a) { lo = a.lo; fnc = a.fnc; csize = a.csize; make_initial_chunks(); for (int i = a.low(); i < a.fence(); a.next(i)) (*this)[i] = a[i]; } void XPlex::operator= (const XPlex& a) { if (&a != this) { invalidate(); lo = a.lo; fnc = a.fnc; csize = a.csize; make_initial_chunks(); for (int i = a.low(); i < a.fence(); a.next(i)) (*this)[i] = a[i]; } } void XPlex::cache(int idx) const { const IChunk* tail = tl(); const IChunk* t = ch; while (idx >= t->fence_index()) { if (t == tail) index_error(); t = (t->next()); } while (idx < t->low_index()) { if (t == hd) index_error(); t = (t->prev()); } set_cache(t); } void XPlex::cache(const * p) const { const IChunk* old = ch; const IChunk* t = ch; while (!t->actual_pointer(p)) { t = (t->next()); if (t == old) index_error(); } set_cache(t); } int XPlex::owns(Pix px) const { * p = (*)px; const IChunk* old = ch; const IChunk* t = ch; while (!t->actual_pointer(p)) { t = (t->next()); if (t == old) { set_cache(t); return 0; } } set_cache(t); return 1; } * XPlex::dosucc(const * p) const { if (p == 0) return 0; const IChunk* old = ch; const IChunk* t = ch; while (!t->actual_pointer(p)) { t = (t->next()); if (t == old) return 0; } int i = t->index_of(p) + 1; if (i >= fnc) return 0; if (i >= t->fence_index()) t = (t->next()); set_cache(t); return (t->pointer_to(i)); } * XPlex::dopred(const * p) const { if (p == 0) return 0; const IChunk* old = ch; const IChunk* t = ch; while (!t->actual_pointer(p)) { t = (t->prev()); if (t == old) return 0; } int i = t->index_of(p) - 1; if (i < lo) return 0; if (i < t->low_index()) t = (t->prev()); set_cache(t); return (t->pointer_to(i)); } int XPlex::add_high(const elem) { IChunk* t = tl(); if (!t->can_grow_high()) { if (t->IChunk::empty() && one_chunk()) t->clear(fnc); else { * data = new [csize]; t = (new IChunk(data, fnc, fnc, fnc,fnc+csize)); t->link_to_prev(tl()); } } *((t->IChunk::grow_high())) = elem; set_cache(t); return fnc++; } int XPlex::del_high () { if (empty()) empty_error(); IChunk* t = tl(); t->IChunk::shrink_high(); if (t->IChunk::empty() && !one_chunk()) { IChunk* pred = t->prev(); del_chunk(t); t = pred; } set_cache(t); return --fnc - 1; } int XPlex::add_low (const elem) { IChunk* t = hd; if (!t->can_grow_low()) { if (t->IChunk::empty() && one_chunk()) t->cleardown(lo); else { * data = new [csize]; hd = new IChunk(data, lo-csize, lo, lo, lo); hd->link_to_next(t); t = hd; } } *((t->IChunk::grow_low())) = elem; set_cache(t); return --lo; } int XPlex::del_low () { if (empty()) empty_error(); IChunk* t = hd; t->IChunk::shrink_low(); if (t->IChunk::empty() && !one_chunk()) { hd = t->next(); del_chunk(t); t = hd; } set_cache(t); return ++lo; } void XPlex::reverse() { tmp; int l = lo; int h = fnc - 1; IChunk* loch = hd; IChunk* hich = tl(); while (l < h) { * lptr = loch->pointer_to(l); * hptr = hich->pointer_to(h); tmp = *lptr; *lptr = *hptr; *hptr = tmp; if (++l >= loch->fence_index()) loch = loch->next(); if (--h < hich->low_index()) hich = hich->prev(); } } void XPlex::fill(const x) { for (int i = lo; i < fnc; ++i) (*this)[i] = x; } void XPlex::fill(const x, int l, int hi) { for (int i = l; i <= hi; ++i) (*this)[i] = x; } void XPlex::clear() { if (fnc != lo) { IChunk* t = tl(); while (t != hd) { IChunk* prv = t->prev(); del_chunk(t); t = prv; } t->IChunk::clear(lo); set_cache(t); fnc = lo; } } int 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))->IChunk::low_index(); // first lo == plex lo // loop for others: int found_ch = 0; // to make sure ch is in list; const IChunk* t = (hd); for (;;) { if (t == ch) ++found_ch; v &= t->IChunk::OK(); // each chunk is OK if (t == tl()) break; else // and has indices contiguous to succ { v &= t->top_index() == t->next()->base_index(); if (t != hd) // internal chunks full { v &= !t->empty(); v &= !t->can_grow_low(); v &= !t->can_grow_high(); } t = t->next(); } } v &= found_ch == 1; if (!v) error("invariant failure"); return v; } ./g++-include/gen/AVLMap.hP100644 0 1 6341 5522102410 13665 0ustar rootdaemon// 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) 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. */ #ifndef _AVLMap_h #ifdef __GNUG__ #pragma interface #endif #define _AVLMap_h 1 #include "..Map.h" struct AVLNode { AVLNode* lt; AVLNode* rt; item; cont; char stat; AVLNode( h, c, AVLNode* l=0, AVLNode* r=0); ~AVLNode(); }; inline AVLNode::AVLNode( h, c, AVLNode* l, AVLNode* r) :item(h), cont(c), lt(l), rt(r), stat(0) {} inline AVLNode::~AVLNode() {} typedef AVLNode* AVLNodePtr; class AVLMap : public Map { protected: AVLNode* root; AVLNode* leftmost(); AVLNode* rightmost(); AVLNode* pred(AVLNode* t); AVLNode* succ(AVLNode* t); void _kill(AVLNode* t); void _add(AVLNode*& t); void _del(AVLNode* p, AVLNode*& t); public: AVLMap( dflt); AVLMap(AVLMap& a); ~AVLMap(); & operator [] ( key); void del( key); Pix first(); void next(Pix& i); & key(Pix i); & contents(Pix i); Pix seek( key); int contains( key); void clear(); Pix last(); void prev(Pix& i); int OK(); }; inline AVLMap::~AVLMap() { _kill(root); } inline AVLMap::AVLMap( dflt) :Map(dflt) { root = 0; } inline Pix AVLMap::first() { return Pix(leftmost()); } inline Pix AVLMap::last() { return Pix(rightmost()); } inline void AVLMap::next(Pix& i) { if (i != 0) i = Pix(succ((AVLNode*)i)); } inline void AVLMap::prev(Pix& i) { if (i != 0) i = Pix(pred((AVLNode*)i)); } inline & AVLMap::key(Pix i) { if (i == 0) error("null Pix"); return ((AVLNode*)i)->item; } inline & AVLMap::contents(Pix i) { if (i == 0) error("null Pix"); return ((AVLNode*)i)->cont; } inline void AVLMap::clear() { _kill(root); count = 0; root = 0; } inline int AVLMap::contains( key) { return seek(key) != 0; } #endif ./g++-include/gen/AVLSet.hP100644 0 1 6435 5522102410 13707 0ustar rootdaemon// 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) 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. */ #ifndef _AVL_h #ifdef __GNUG__ #pragma interface #endif #define _AVL_h 1 #include ".Set.h" struct AVLNode { AVLNode* lt; AVLNode* rt; item; char stat; AVLNode( h, AVLNode* l=0, AVLNode* r=0); ~AVLNode(); }; inline AVLNode::AVLNode( h, AVLNode* l, AVLNode* r) :item(h), lt(l), rt(r), stat(0) {} inline AVLNode::~AVLNode() {} typedef AVLNode* AVLNodePtr; class AVLSet : public Set { protected: AVLNode* root; AVLSet(AVLNode* p, int l); AVLNode* leftmost(); AVLNode* rightmost(); AVLNode* pred(AVLNode* t); AVLNode* succ(AVLNode* t); void _kill(AVLNode* t); void _add(AVLNode*& t); void _del(AVLNode* p, AVLNode*& t); public: AVLSet(); AVLSet(AVLSet& a); ~AVLSet(); Pix add( item); void del( item); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); int owns(Pix i); Pix seek( item); Pix last(); void prev(Pix& i); void operator |= (AVLSet& b); void operator -= (AVLSet& b); void operator &= (AVLSet& b); int operator == (AVLSet& b); int operator != (AVLSet& b); int operator <= (AVLSet& b); int OK(); }; inline AVLSet::~AVLSet() { _kill(root); } inline AVLSet::AVLSet() { root = 0; count = 0; } inline AVLSet::AVLSet(AVLNode* p, int l) { root = p; count = l; } inline int AVLSet::operator != (AVLSet& b) { return ! ((*this) == b); } inline Pix AVLSet::first() { return Pix(leftmost()); } inline Pix AVLSet::last() { return Pix(rightmost()); } inline void AVLSet::next(Pix& i) { if (i != 0) i = Pix(succ((AVLNode*)i)); } inline void AVLSet::prev(Pix& i) { if (i != 0) i = Pix(pred((AVLNode*)i)); } inline & AVLSet::operator () (Pix i) { if (i == 0) error("null Pix"); return ((AVLNode*)i)->item; } inline void AVLSet::clear() { _kill(root); count = 0; root = 0; } inline int AVLSet::contains( key) { return seek(key) != 0; } #endif ./g++-include/gen/AVec.hP100644 0 1 7000 5522102411 13415 0ustar rootdaemon// 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) 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. */ #ifndef _AVec_h #ifdef __GNUG__ #pragma interface #endif #define _AVec_h 1 #include ".Vec.h" class AVec : public Vec { protected: void check_len(int l); * vec(); AVec(int l, * d); public: AVec (); AVec (int l); AVec (int l, fill_value); AVec (AVec&); ~AVec (); AVec& operator = (AVec& a); AVec& operator = ( fill_value); // vector by scalar -> vector operations friend AVec operator + (AVec& a, b); friend AVec operator - (AVec& a, b); friend AVec operator * (AVec& a, b); friend AVec operator / (AVec& a, b); AVec& operator += ( b); AVec& operator -= ( b); AVec& operator *= ( b); AVec& operator /= ( b); // vector by vector -> vector operations friend AVec operator + (AVec& a, AVec& b); friend AVec operator - (AVec& a, AVec& b); AVec& operator += (AVec& b); AVec& operator -= (AVec& b); AVec operator - (); friend AVec product(AVec& a, AVec& b); AVec& product(AVec& b); friend AVec quotient(AVec& a, AVec& b); AVec& quotient(AVec& b); // vector -> scalar operations friend operator * (AVec& a, AVec& b); sum(); min(); max(); sumsq(); // indexing int min_index(); int max_index(); // redundant but necesssary friend AVec concat(AVec& a, AVec& b); friend AVec map(Mapper f, AVec& a); friend AVec merge(AVec& a, AVec& b, Comparator f); friend AVec combine(Combiner f, AVec& a, AVec& b); friend AVec reverse(AVec& a); AVec at(int from = 0, int n = -1); }; inline AVec::AVec() {} inline AVec::AVec(int l) :Vec(l) {} inline AVec::AVec(int l, fill_value) : Vec (l, fill_value) {} inline AVec::AVec(AVec& v) :Vec(v) {} inline AVec::AVec(int l, * d) :Vec(l, d) {} inline AVec::~AVec() {} inline * AVec::vec() { return s; } inline void AVec::check_len(int l) { if (l != len) error("nonconformant vectors."); } #endif ./g++-include/gen/BSTSet.hP100644 0 1 6405 5522102412 13714 0ustar rootdaemon// 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) 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. */ #ifndef _BSTSet_h #ifdef __GNUG__ #pragma interface #endif #define _BSTSet_h 1 #include ".Set.h" #ifndef _BSTNode #define _BSTNode 1 struct BSTNode { BSTNode* lt; BSTNode* rt; BSTNode* par; item; BSTNode( h, BSTNode* l=0, BSTNode* r=0, BSTNode* p = 0); ~BSTNode(); }; inline BSTNode::BSTNode( h, BSTNode* l, BSTNode* r, BSTNode* p) :item(h), lt(l), rt(r), par(p) {} inline BSTNode::~BSTNode() {} typedef BSTNode* BSTNodePtr; #endif class BSTSet : public Set { protected: BSTNode* root; BSTNode* leftmost(); BSTNode* rightmost(); BSTNode* pred(BSTNode* t); BSTNode* succ(BSTNode* t); void _kill(BSTNode* t); BSTNode* _copy(BSTNode* t); public: BSTSet(); BSTSet(BSTSet& a); ~BSTSet(); Pix add( item); void del( item); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); Pix seek( item); Pix last(); void prev(Pix& i); int operator == (BSTSet& b); int operator != (BSTSet& b); int operator <= (BSTSet& b); void balance(); int OK(); }; inline BSTSet::~BSTSet() { _kill(root); } inline BSTSet::BSTSet() { root = 0; count = 0; } inline BSTSet::BSTSet(BSTSet& a) { count = a.count; root = _copy(a.root); } inline int BSTSet::operator != (BSTSet& b) { return ! (*this == b); } inline Pix BSTSet::first() { return Pix(leftmost()); } inline Pix BSTSet::last() { return Pix(rightmost()); } inline void BSTSet::next(Pix& i) { if (i != 0) i = Pix(succ((BSTNode*)i)); } inline void BSTSet::prev(Pix& i) { if (i != 0) i = Pix(pred((BSTNode*)i)); } inline & BSTSet::operator () (Pix i) { if (i == 0) error("null Pix"); return ((BSTNode*)i)->item; } inline void BSTSet::clear() { _kill(root); count = 0; root = 0; } inline int BSTSet::contains( key) { return seek(key) != 0; } #endif ./g++-include/gen/Bag.hP100644 0 1 4467 5522102413 13310 0ustar rootdaemon// 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) 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. */ #ifndef _Bag_h #ifdef __GNUG__ #pragma interface #endif #define _Bag_h 1 #include #include ".defs.h" class Bag { protected: int count; public: virtual ~Bag(); int length(); // current number of items int empty(); virtual Pix add( item) = 0; // add item; return Pix virtual void del( item) = 0; // delete 1 occurrence of item #undef remove virtual void remove( item); // delete all occurrences virtual void clear(); // delete all items virtual int contains( item); // is item in Bag? virtual int nof( item); // how many in Bag? virtual Pix first() = 0; // Pix of first item or 0 virtual void next(Pix& i) = 0; // advance to next or 0 virtual & operator () (Pix i) = 0; // access item at i virtual Pix seek( item, Pix from=0); // Pix of next occurrence virtual int owns(Pix i); // is i a valid Pix ? void error(const char* msg); virtual int OK() = 0; // rep invariant }; inline Bag::~Bag() {} inline int Bag::length() { return count; } inline int Bag::empty() { return count == 0; } inline int Bag::contains( item) { return seek(item) != 0; } #endif ./g++-include/gen/CHBag.hP100644 0 1 3475 5522102414 13522 0ustar rootdaemon// 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) 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. */ #ifndef _CHBag_h #ifdef __GNUG__ #pragma interface #endif #define _CHBag_h 1 #include ".Bag.h" #include ".CHNode.h" class CHBag : public Bag { protected: CHNode** tab; unsigned int size; public: CHBag(unsigned int sz = DEFAULT_INITIAL_CAPACITY); CHBag(CHBag& a); ~CHBag(); Pix add( item); void del( item); void remove(item); int nof( item); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); Pix seek( item, Pix from = 0); int OK(); }; inline CHBag::~CHBag() { clear(); delete tab; } inline int CHBag::contains( key) { return seek(key) != 0; } inline & CHBag::operator () (Pix i) { if (i == 0) error("null Pix"); return ((CHNode*)i)->hd; } #endif ./g++-include/gen/CHMap.hP100644 0 1 4643 5522102414 13544 0ustar rootdaemon// 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) 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. */ #ifndef _CHMap_h #ifdef __GNUG__ #pragma interface #endif #define _CHMap_h 1 #include "..Map.h" #ifndef _CHNode_h #define _CHNode_h 1 struct CHNode { CHNode* tl; hd; cont; CHNode(); CHNode( h, c, CHNode* t = 0); ~CHNode(); }; inline CHNode::CHNode() {} inline CHNode::CHNode( h, c, CHNode* t) : hd(h), cont(c), tl(t) {} inline CHNode::~CHNode() {} typedef CHNode* CHNodePtr; #endif class CHMap : public Map { protected: CHNode** tab; unsigned int size; public: CHMap( dflt,unsigned int sz=DEFAULT_INITIAL_CAPACITY); CHMap(CHMap& a); ~CHMap(); & operator [] ( key); void del( key); Pix first(); void next(Pix& i); & key(Pix i); & contents(Pix i); Pix seek( key); int contains( key); void clear(); int OK(); }; inline CHMap::~CHMap() { clear(); delete tab; } inline int CHMap::contains( key) { return seek(key) != 0; } inline & CHMap::key(Pix p) { if (p == 0) error("null Pix"); return ((CHNode*)p)->hd; } inline & CHMap::contents(Pix p) { if (p == 0) error("null Pix"); return ((CHNode*)p)->cont; } #endif ./g++-include/gen/CHNode.hP100644 0 1 2532 5522102415 13710 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988, 1982 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) 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. */ #ifndef _CHNode_h #define _CHNode_h 1 #ifdef __GNUG__ #pragma interface #endif #include ".defs.h" struct CHNode { CHNode* tl; hd; CHNode(); CHNode( h, CHNode* t = 0); ~CHNode(); }; inline CHNode::CHNode() {} inline CHNode::CHNode( h, CHNode* t) :hd(h), tl(t) {} inline CHNode::~CHNode() {} typedef CHNode* CHNodePtr; #endif ./g++-include/gen/CHSet.hP100644 0 1 4076 5522102416 13564 0ustar rootdaemon// 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) 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. */ #ifndef _CHSet_h #ifdef __GNUG__ #pragma interface #endif #define _CHSet_h 1 #include ".Set.h" #include ".CHNode.h" class CHSet : public Set { protected: CHNode** tab; unsigned int size; public: CHSet(unsigned int sz = DEFAULT_INITIAL_CAPACITY); CHSet(CHSet& a); ~CHSet(); Pix add( item); void del( item); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); Pix seek( item); void operator |= (CHSet& b); void operator -= (CHSet& b); void operator &= (CHSet& b); int operator == (CHSet& b); int operator != (CHSet& b); int operator <= (CHSet& b); int OK(); }; inline CHSet::~CHSet() { clear(); delete tab; } inline int CHSet::contains( key) { return seek(key) != 0; } inline & CHSet::operator () (Pix i) { if (i == 0) error("null Pix"); return ((CHNode*)i)->hd; } inline int CHSet::operator != (CHSet& b) { return ! ((*this) == b); } #endif ./g++-include/gen/DLDeque.hP100644 0 1 4744 5522102417 14104 0ustar rootdaemon// 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) 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. */ #ifndef _DLDeque_h #ifdef __GNUG__ #pragma interface #endif #define _DLDeque_h #include ".DLList.h" #include ".Deque.h" class DLDeque : public Deque { DLList p; public: DLDeque(); DLDeque(const DLDeque& d); ~DLDeque(); void operator = (const DLDeque&); void push( item); // insert at front void enq( item); // insert at rear & front(); & rear(); deq(); void del_front(); void del_rear(); void clear(); int empty(); int full(); int length(); int OK(); }; inline DLDeque::DLDeque() : p() {} inline DLDeque::DLDeque(const DLDeque& d) : p(d.p) {} inline DLDeque::~DLDeque() {} inline void DLDeque::push(item) { p.prepend(item); } inline void DLDeque::enq(item) { p.append(item); } inline DLDeque::deq() { return p.remove_front(); } inline & DLDeque::front() { return p.front(); } inline & DLDeque::rear() { return p.rear(); } inline void DLDeque::del_front() { p.del_front(); } inline void DLDeque::del_rear() { p.del_rear(); } inline void DLDeque::operator =(const DLDeque& s) { p.operator = (s.p); } inline int DLDeque::empty() { return p.empty(); } inline int DLDeque::full() { return 0; } inline int DLDeque::length() { return p.length(); } inline int DLDeque::OK() { return p.OK(); } inline void DLDeque::clear() { p.clear(); } #endif ./g++-include/gen/DLList.hP100644 0 1 7337 5522102420 13747 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- // WARNING: This file is obsolete. Use ../DLList.h, if you can. /* Copyright (C) 1988 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) 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. */ #ifndef _DLList_h #ifdef __GNUG__ #pragma interface #endif #define _DLList_h 1 #include #include ".defs.h" #ifndef _DLListNode_h #define _DLListNode_h 1 struct DLListNode { DLListNode* bk; DLListNode* fd; hd; DLListNode(); DLListNode(const h, DLListNode* p = 0, DLListNode* n = 0); ~DLListNode(); }; inline DLListNode::DLListNode() {} inline DLListNode::DLListNode(const h, DLListNode* p, DLListNode* n) :hd(h), bk(p), fd(n) {} inline DLListNode::~DLListNode() {} typedef DLListNode* DLListNodePtr; #endif class DLList { friend class DLListTrav; DLListNode* h; public: DLList(); DLList(const DLList& a); ~DLList(); DLList& operator = (const DLList& a); int empty(); int length(); void clear(); Pix prepend( item); Pix append( item); void join(DLList&); & front(); remove_front(); void del_front(); & rear(); remove_rear(); void del_rear(); & operator () (Pix p); Pix first(); Pix last(); void next(Pix& p); void prev(Pix& p); int owns(Pix p); Pix ins_after(Pix p, item); Pix ins_before(Pix p, item); void del(Pix& p, int dir = 1); void del_after(Pix& p); void error(const char* msg); int OK(); }; inline DLList::~DLList() { clear(); } inline DLList::DLList() { h = 0; } inline int DLList::empty() { return h == 0; } inline void DLList::next(Pix& p) { p = (p == 0 || p == h->bk)? 0 : Pix(((DLListNode*)p)->fd); } inline void DLList::prev(Pix& p) { p = (p == 0 || p == h)? 0 : Pix(((DLListNode*)p)->bk); } inline Pix DLList::first() { return Pix(h); } inline Pix DLList::last() { return (h == 0)? 0 : Pix(h->bk); } inline & DLList::operator () (Pix p) { if (p == 0) error("null Pix"); return ((DLListNode*)p)->hd; } inline & DLList::front() { if (h == 0) error("front: empty list"); return h->hd; } inline & DLList::rear() { if (h == 0) error("rear: empty list"); return h->bk->hd; } #endif ./g++-include/gen/Deque.hP100644 0 1 3313 5522102421 13646 0ustar rootdaemon// 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. */ #ifndef _Deque_h #ifdef __GNUG__ #pragma interface #endif #define _Deque_h #include #include ".defs.h" class Deque { public: Deque() { } virtual ~Deque(); virtual void push( item) = 0; // insert at front virtual void enq( item) = 0; // insert at rear virtual & front() = 0; virtual & rear() = 0; virtual deq() = 0; virtual void del_front() = 0; virtual void del_rear() = 0; virtual int empty() = 0; virtual int full() = 0; virtual int length() = 0; virtual void clear() = 0; virtual int OK() = 0; void error(const char*); }; #endif ./g++-include/gen/FPQueue.hP100644 0 1 4500 5522102421 14114 0ustar rootdaemon// 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. */ #ifndef _FPQueue_h #ifdef __GNUG__ #pragma interface #endif #define _FPQueue_h #include ".FPlex.h" #include ".Queue.h" class FPQueue : public Queue { FPlex p; public: FPQueue(int chunksize = DEFAULT_INITIAL_CAPACITY); FPQueue(const FPQueue& q); ~FPQueue(); void operator = (const FPQueue&); void enq( item); deq(); & front(); void del_front(); void clear(); int empty(); int full(); int length(); int OK(); }; inline FPQueue::FPQueue(int chunksize) : p(chunksize) {} inline FPQueue::FPQueue(const FPQueue& q) : p(q.p) {} inline FPQueue::~FPQueue() {} inline void FPQueue::enq(item) { p.add_high(item); } inline FPQueue::deq() { res = p.low_element(); p.del_low(); return res; } inline & FPQueue::front() { return p.low_element(); } inline void FPQueue::del_front() { p.del_low(); } inline void FPQueue::operator =(const FPQueue& s) { p = s.p; } inline int FPQueue::empty() { return p.empty(); } inline int FPQueue::full() { return p.full(); } inline int FPQueue::length() { return p.length(); } inline int FPQueue::OK() { return p.OK(); } inline void FPQueue::clear() { p.clear(); } #endif ./g++-include/gen/FPStack.hP100644 0 1 4511 5522102422 14100 0ustar rootdaemon// 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. */ #ifndef _FPStack_h #ifdef __GNUG__ #pragma interface #endif #define _FPStack_h #include ".FPlex.h" #include ".Stack.h" class FPStack : public Stack { FPlex p; public: FPStack(int chunksize = DEFAULT_INITIAL_CAPACITY); FPStack(const FPStack& s); ~FPStack(); void operator = (const FPStack&); void push( item); pop(); & top(); void del_top(); int empty(); int full(); int length(); void clear(); int OK(); }; inline FPStack::FPStack(int chunksize) : p(chunksize) {} inline FPStack::FPStack(const FPStack& s) : p(s.p) {} inline FPStack::~FPStack() {} inline void FPStack::push(item) { p.add_high(item); } inline FPStack::pop() { res = p.high_element(); p.del_high(); return res; } inline & FPStack::top() { return p.high_element(); } inline void FPStack::del_top() { p.del_high(); } inline void FPStack::operator =(const FPStack& s) { p = s.p; } inline int FPStack::empty() { return p.empty(); } inline int FPStack::full() { return p.full(); } inline int FPStack::length() { return p.length(); } inline int FPStack::OK() { return p.OK(); } inline void FPStack::clear() { p.clear(); } #endif ./g++-include/gen/FPlex.hP100644 0 1 13725 5522102423 13653 0ustar rootdaemon// 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. */ #ifndef _FPlex_h #ifdef __GNUG__ #pragma interface #endif #define _FPlex_h 1 #include ".Plex.h" class FPlex : public Plex { public: FPlex(); // set low = 0; // fence = 0; // csize = default FPlex(int maxsize); // low = 0; // fence = 0; // csize = maxsize FPlex(int lo, // low = lo; int maxsize); // fence=lo // csize = maxsize FPlex(int lo, // low = lo int hi, // fence = hi+1 const initval,// fill with initval, int maxsize = 0); // csize = maxsize // or fence - lo if 0 FPlex(const FPlex&); // X(X&) ~FPlex(); void operator= (const FPlex&); // virtuals & high_element (); & low_element (); const & high_element () const; const & low_element () const; Pix first() const; Pix last() const; void prev(Pix& ptr) const; void next(Pix& ptr) const; int owns(Pix p) const; & operator () (Pix p); const & operator () (Pix p) const; int low() const; int high() const; int valid(int idx) const; void prev(int& idx) const; void next(int& x) const; & operator [] (int index); const & operator [] (int index) const; int Pix_to_index(Pix p) const; Pix index_to_Pix(int idx) const; int can_add_high() const; int can_add_low() const; int full() const; int add_high(const elem); int del_high (); int add_low (const elem); int del_low (); void fill(const x); void fill(const x, int from, int to); void clear(); void reverse(); int OK () const; }; inline int FPlex::valid (int idx) const { return idx >= lo && idx < fnc; } inline int FPlex::low() const { return lo; } inline int FPlex::high() const { return fnc - 1; } inline Pix FPlex::first() const { return (Pix)(hd->IChunk::first_pointer()); } inline void FPlex::prev(Pix& p) const { p = Pix(hd->IChunk::pred((*) p)); } inline void FPlex::next(Pix& p) const { p = Pix(hd->IChunk::succ((*) p)); } inline Pix FPlex::last() const { return Pix(hd->IChunk::last_pointer()); } inline int FPlex::full () const { return fnc - lo == csize; } inline void FPlex::prev(int& idx) const { --idx; } inline void FPlex::next(int& idx) const { ++idx; } inline & FPlex:: operator [] (int idx) { if (idx < lo || idx >= fnc) index_error(); return *(hd->pointer_to(idx)); } inline & FPlex:: operator () (Pix p) { return *((*)p); } inline & FPlex::low_element () { if (empty()) index_error(); return *(hd->pointer_to(lo)); } inline & FPlex::high_element () { if (empty()) index_error(); return *(hd->pointer_to(fnc - 1)); } inline const & FPlex:: operator [] (int idx) const { if (idx < lo || idx >= fnc) index_error(); return *(hd->pointer_to(idx)); } inline const & FPlex:: operator () (Pix p) const { return *((const *)p); } inline const & FPlex::low_element () const { if (empty()) index_error(); return *(hd->pointer_to(lo)); } inline const & FPlex::high_element () const { if (empty()) index_error(); return *(hd->pointer_to(fnc - 1)); } inline int FPlex::can_add_high() const { return hd->can_grow_high(); } inline int FPlex::can_add_low() const { return hd->can_grow_low(); } inline int FPlex::add_high(const elem) { if (!can_add_high()) full_error(); *((hd->IChunk::grow_high())) = elem; return fnc++; } inline int FPlex::del_high () { if (empty()) empty_error(); hd->IChunk::shrink_high(); return --fnc - 1; } inline int FPlex::add_low (const elem) { if (!can_add_low()) full_error(); *((hd->IChunk::grow_low())) = elem; return --lo; } inline int FPlex::del_low () { if (empty()) empty_error(); hd->IChunk::shrink_low(); return ++lo; } inline int FPlex::owns (Pix p) const { return hd->actual_pointer((*)p); } inline int FPlex::Pix_to_index(Pix p) const { if (!hd->actual_pointer((const *)p)) index_error(); return hd->index_of((const *)p); } inline Pix FPlex::index_to_Pix(int idx) const { if (idx < lo || idx >= fnc) index_error(); return Pix(hd->pointer_to(idx)); } inline FPlex::~FPlex() {} #endif ./g++-include/gen/List.hP100644 0 1 13644 5522102424 13551 0ustar rootdaemon// 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) 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. */ #ifndef _List_h #ifdef __GNUG__ #pragma interface #endif #define _List_h 1 #include #include ".defs.h" #ifndef __typedefs #define __typedefs 1 typedef void (*Procedure)(); typedef (*Mapper)(); typedef (*Combiner)(, ); typedef int (*Predicate)(); typedef int (*Comparator)(, ); #endif struct ListNode { ListNode* tl; short ref; hd; }; extern ListNode NilListNode; class List { protected: ListNode* P; List(ListNode* p); public: List(); List( head); List( head, List& tl); List(List& a); List(Pix p); ~List(); List& operator = (List& a); int null(); int valid(); operator const void* (); int operator ! (); int length(); int list_length(); & get(); & head(); & operator [] (int n); List nth(int n); List tail(); List last(); List find( targ); List find(List& targ); int contains( targ); int contains(List& targ); int position( targ); friend List copy(List& a); friend List concat(List& a, List& b); friend List append(List& a, List& b); friend List map(Mapper f, List& a); friend List merge(List& a, List& b, Comparator f); friend List combine(Combiner f, List& a, List& b); friend List reverse(List& a); friend List select(Predicate f, List& a); #undef remove friend List remove( targ, List& a); friend List remove(Predicate f, List& a); friend List subst( old, repl, List& a); void push( x); pop(); void set_tail(List& p); void append(List& p); void prepend(List& p); void del( targ); void del(Predicate f); void select(Predicate f); void subst( old, repl); void reverse(); void sort(Comparator f); void apply(Procedure f); reduce(Combiner f, base); friend int operator == (List& a, List& b); friend int operator != (List& a, List& b); Pix first(); void next(Pix& p); Pix seek( item); & operator () (Pix p); int owns(Pix p); void error(const char*); int OK(); }; inline void reference(ListNode* p) { if (p->ref >= 0) ++p->ref; } inline void dereference(ListNode* p) { while (p->ref > 0 && --p->ref == 0) { ListNode* n = p->tl; delete(p); p = n; } } inline ListNode* newListNode( h) { ListNode* p = new ListNode; p->ref = 1; p->hd = h; return p; } inline ListNode* newListNode( h, ListNode* t) { ListNode* p = new ListNode; p->ref = 1; p->hd = h; p->tl = t; return p; } inline List::~List() { dereference(P); } inline List::List() { P = &NilListNode; } inline List::List(ListNode* p) { P = p; } inline List::List( head) { P = newListNode(head); P->tl = &NilListNode; } inline List::List( head, List& tl) { P = newListNode(head, tl.P); reference(P->tl); } inline List::List(List& a) { reference(a.P); P = a.P; } inline & List::get() { return P->hd; } inline & List::head() { return P->hd; } inline List List::tail() { reference(P->tl); return List(P->tl); } inline int List::null() { return P == &NilListNode; } inline int List::valid() { return P != &NilListNode; } inline List::operator const void* () { return (P == &NilListNode)? 0 : this; } inline int List::operator ! () { return (P == &NilListNode); } inline void List::push( head) { ListNode* oldp = P; P = newListNode(head, oldp); } inline int operator != (List& x, List& y) { return !(x == y); } inline Pix List::first() { return (P == &NilListNode)? 0 : Pix(P); } inline & List::operator () (Pix p) { return ((ListNode*)p)->hd; } inline void List::next(Pix& p) { if (p != 0) { p = Pix(((ListNode*)p)->tl); if (p == &NilListNode) p = 0; } } inline List::List(Pix p) { P = (ListNode*)p; reference(P); } #endif ./g++-include/gen/MPlex.hP100644 0 1 24535 5522102425 13665 0ustar rootdaemon// 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. */ #ifndef _MPlex_h #ifdef __GNUG__ #pragma interface #endif #define _MPlex_h 1 #include ".Plex.h" // Number of bits per long, used in MChunk bit map operations #define _MAP_BITS 32 class MChunk : public IChunk { protected: unsigned long* map; // bitmap of slots int unused; // number of unused internal slots void mark(int); // bitmap operations void free(int); int valid(int) const; public: MChunk(* d, // ptr to array of elements int base_idx, // initial indices int low_idx, // & initially clear map int fence_idx, int top_idx); ~MChunk(); // virtuals int first_index() const; int last_index() const; int succ(int idx) const; int pred(int idx) const; * first_pointer() const; * last_pointer() const; * succ(*) const; * pred(*) const; int empty() const; int full() const; int valid_index(int i) const; int valid_pointer(const * p) const; * grow_high (); * grow_low (); void shrink_high (); void shrink_low (); void clear(int); void cleardown(int); int OK() const; // extensions int unused_indices() const; // how many free slot in low..fence? int unused_index() const; // return index of free slot int del(int i); // delete data indexed by i // return true if was present int undel(int idx); // un-delete data indexed by i // return true if already present void reset_low(); // reset low = lowest valid index; void reset_high(); // same for high }; class MPlex: public Plex { MChunk* ch; // cached chunk int unused; // # of free slots between low & fence void make_initial_chunks(int up = 1); void cache(int idx) const; void cache(const * p) const; int dopred(int) const; int dosucc(int) const; void set_cache(const MChunk* t) const; // logically, // not physically const public: MPlex(); // set low = 0; // fence = 0; // csize = default MPlex(int ch_size); // low = 0; // fence = 0; // csize = ch_size MPlex(int lo, // low = lo; int ch_size); // fence=lo // csize = ch_size MPlex(int lo, // low = lo int hi, // fence = hi+1 const initval,// fill with initval, int ch_size = 0); // csize= ch_size // or fence-lo if 0 MPlex(const MPlex&); void operator= (const MPlex&); // virtuals & high_element (); & low_element (); const & high_element () const; const & low_element () const; Pix first() const; Pix last() const ; void prev(Pix& ptr) const; void next(Pix& ptr) const; int owns(Pix p) const; & operator () (Pix p); const & operator () (Pix p) const; int low() const; int high() const; int valid(int idx) const; void prev(int& idx) const; void next(int& x) const; & operator [] (int index); const & operator [] (int index) const; int Pix_to_index(Pix p) const; Pix index_to_Pix(int idx) const; int can_add_high() const; int can_add_low() const; int full() const; int add_high(const elem); int del_high (); int add_low (const elem); int del_low (); void clear(); int OK () const; // extensions int count() const; // # valid elements int available() const; // # deleted elements int unused_index()const; // return index of a deleted elem Pix unused_Pix() const; // return Pix of a deleted elem int del_index(int idx); // logically delete at idx; // return true if was present int del_Pix(Pix p); // delete at p void undel_index(int idx); // undelete at idx; void undel_Pix(Pix p); // undelete at p; void adjust_bounds(); // reset lo, hi to lowest & // highest valid indices int add(const elem); // add anywhere }; inline MChunk:: ~MChunk() { delete map; } inline void MChunk::mark(int idx) { unsigned int i = idx - base; map[i / _MAP_BITS] |= 1 << (i & (_MAP_BITS - 1)); } inline void MChunk::free(int idx) { unsigned int i = idx - base; map[i / _MAP_BITS] &= ~(1 << (i & (_MAP_BITS - 1))); } inline int MChunk::valid(int idx) const { unsigned int i = idx - base; return map[i / _MAP_BITS] & (1 << (i & (_MAP_BITS - 1))); } inline int MChunk:: valid_index(int i) const { return i >= low && i < fence && valid(i); } inline int MChunk:: valid_pointer(const * p) const { int i = ((int)p - (int)data) / sizeof(); return i >= 0 && i < (fence - base) && (map[(unsigned)i / _MAP_BITS] & (1 << (i & (_MAP_BITS - 1)))); } inline int MChunk::empty() const { return fence - low - unused == 0; } inline int MChunk::full() const { return unused + (top - fence) + (low - base) == 0; } inline int MChunk::succ(int idx) const { int i = (idx < low)? low : idx + 1; while (i < fence && !valid(i)) ++i; return i; } inline int MChunk::pred(int idx) const { int i = (idx > fence)? (fence - 1) : idx - 1; while (i >= low && !valid(i)) --i; return i; } inline int MChunk::unused_indices() const { return unused; } inline * MChunk:: grow_high () { if (!can_grow_high()) full_error(); mark(fence); return &(data[fence++ - base]); } inline * MChunk:: grow_low () { if (!can_grow_low()) full_error(); mark(--low); return &(data[low - base]); } inline void MChunk::reset_low() { while (low < fence && !valid(low)) { --unused; ++low; } } inline void MChunk::reset_high() { while (fence > low && !valid(fence - 1)) { --unused; --fence; } } inline int MPlex::full () const { return 0; } inline int MPlex::can_add_high() const { return 1; } inline int MPlex::can_add_low() const { return 1; } inline int MPlex::available() const { return unused; } inline int MPlex::count() const { return fnc - lo - unused; } inline void MPlex::set_cache(const MChunk* t) const { ((MPlex*)(this))->ch = (MChunk*)t; } inline & MPlex:: operator [] (int idx) { if (!ch->MChunk::valid_index(idx)) cache(idx); return * (ch->pointer_to(idx)); } inline const & MPlex:: operator [] (int idx) const { if (!ch->MChunk::valid_index(idx)) cache(idx); return * ((const *)(ch->pointer_to(idx))); } inline int MPlex::Pix_to_index(Pix p) const { if (!ch->MChunk::valid_pointer((*)p)) cache((*)p); return ch->index_of((*)p); } inline int MPlex::high() const { return (((const MChunk*)tl())->MChunk::valid_index(fnc-1)) ? fnc-1 : dopred(fnc-1); } inline int MPlex::low() const { return (((const MChunk*)hd)->MChunk::valid_index(lo))? lo : dosucc(lo); } inline & MPlex::low_element () { return (*this)[low()]; } inline const & MPlex::low_element () const { return (*this)[low()]; } inline & MPlex::high_element () { return (*this)[high()]; } inline const & MPlex::high_element () const { return (*this)[high()]; } inline Pix MPlex::index_to_Pix(int idx) const { if (!ch->MChunk::valid_index(idx)) cache(idx); return Pix(ch->pointer_to(idx)); } inline void MPlex::next(int& idx) const { idx = (ch->MChunk::valid_index(idx+1))? idx+1 : dosucc(idx); } inline void MPlex::prev(int& idx) const { idx = (ch->MChunk::valid_index(idx-1))? idx-1 : dopred(idx); } inline Pix MPlex::first() const { return index_to_Pix(low()); } inline Pix MPlex::last() const { return index_to_Pix(high()); } inline void MPlex::undel_Pix(Pix p) { undel_index(Pix_to_index(p)); } inline int MPlex::del_Pix(Pix p) { return del_index(Pix_to_index(p)); } inline & MPlex:: operator () (Pix p) { return *((*)p); } inline const & MPlex:: operator () (Pix p) const { return *((const *)p); } #endif ./g++-include/gen/Map.hP100644 0 1 4640 5522102426 13331 0ustar rootdaemon// 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) 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. */ #ifndef _Map_h #ifdef __GNUG__ #pragma interface #endif #define _Map_h 1 #include #include ".defs.h" class Map { protected: int count; def; public: Map( dflt); virtual ~Map(); int length(); // current number of items int empty(); virtual int contains( key); // is key mapped? virtual void clear(); // delete all items virtual & operator [] ( key) = 0; // access contents by key virtual void del( key) = 0; // delete entry virtual Pix first() = 0; // Pix of first item or 0 virtual void next(Pix& i) = 0; // advance to next or 0 virtual & key(Pix i) = 0; // access key at i virtual & contents(Pix i) = 0; // access contents at i virtual int owns(Pix i); // is i a valid Pix ? virtual Pix seek( key); // Pix of key & dflt(); // access default val void error(const char* msg); virtual int OK() = 0; // rep invariant }; inline Map::~Map() {} inline int Map::length() { return count; } inline int Map::empty() { return count == 0; } inline & Map::dflt() { return def; } inline Map::Map( dflt) :def(dflt) { count = 0; } #endif ./g++-include/gen/OSLBag.hP100644 0 1 4027 5522102426 13662 0ustar rootdaemon// 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) 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. */ #ifndef _OSLBag_h #ifdef __GNUG__ #pragma interface #endif #define _OSLBag_h 1 #include ".Bag.h" #include ".SLList.h" class OSLBag : public Bag { protected: SLList p; public: OSLBag(); OSLBag(const OSLBag&); Pix add( item); void del( item); void remove(item); int contains( item); int nof( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); int owns(Pix i); Pix seek( item, Pix from = 0); int OK(); }; inline OSLBag::OSLBag() : p() { count = 0; } inline OSLBag::OSLBag(const OSLBag& s) : p(s.p) { count = s.count; } inline Pix OSLBag::first() { return p.first(); } inline void OSLBag::next(Pix & idx) { p.next(idx); } inline & OSLBag::operator ()(Pix idx) { return p(idx); } inline void OSLBag::clear() { count = 0; p.clear(); } inline int OSLBag::owns (Pix idx) { return p.owns(idx); } inline int OSLBag::contains( item) { return seek(item) != 0; } #endif ./g++-include/gen/OSLSet.hP100644 0 1 4440 5522102427 13724 0ustar rootdaemon// 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) 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. */ #ifndef _OSLSet_h #ifdef __GNUG__ #pragma interface #endif #define _OSLSet_h 1 #include ".Set.h" #include ".SLList.h" class OSLSet : public Set { protected: SLList p; public: OSLSet(); OSLSet(const OSLSet&); Pix add( item); void del( item); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); int owns(Pix i); Pix seek( item); void operator |= (OSLSet& b); void operator -= (OSLSet& b); void operator &= (OSLSet& b); int operator == (OSLSet& b); int operator != (OSLSet& b); int operator <= (OSLSet& b); int OK(); }; inline OSLSet::OSLSet() : p() { count = 0; } inline OSLSet::OSLSet(const OSLSet& s) : p(s.p) { count = s.count; } inline Pix OSLSet::first() { return p.first(); } inline void OSLSet::next(Pix & idx) { p.next(idx); } inline & OSLSet::operator ()(Pix idx) { return p(idx); } inline void OSLSet::clear() { count = 0; p.clear(); } inline int OSLSet::contains ( item) { return seek(item) != 0; } inline int OSLSet::owns (Pix idx) { return p.owns(idx); } inline int OSLSet::operator != (OSLSet& b) { return !(*this == b); } #endif ./g++-include/gen/OXPBag.hP100644 0 1 2371 5522102430 13666 0ustar rootdaemon#ifndef _OXPBag_h #ifdef __GNUG__ #pragma interface #endif #define _OXPBag_h 1 #include ".Bag.h" #include ".XPlex.h" class OXPBag : public Bag { protected: XPlex p; public: OXPBag(int chunksize = DEFAULT_INITIAL_CAPACITY); OXPBag(const OXPBag&); Pix add( item); void del( item); #undef remove void remove(item); int nof( item); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); int owns(Pix i); Pix seek( item, Pix from = 0); int OK(); }; inline OXPBag::OXPBag(int chunksize) : p(chunksize) { count = 0; } inline OXPBag::OXPBag(const OXPBag& s) : p(s.p) { count = s.count; } inline Pix OXPBag::first() { return p.first(); } inline void OXPBag::next(Pix & idx) { p.next(idx); } inline & OXPBag::operator ()(Pix idx) { return p(idx); } inline void OXPBag::clear() { count = 0; p.clear(); } inline int OXPBag::owns (Pix idx) { return p.owns(idx); } inline int OXPBag::contains( item) { return seek(item) != 0; } #endif ./g++-include/gen/OXPSet.hP100644 0 1 4544 5522102431 13735 0ustar rootdaemon// 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) 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. */ #ifndef _OXPSet_h #ifdef __GNUG__ #pragma interface #endif #define _OXPSet_h 1 #include ".Set.h" #include ".XPlex.h" class OXPSet : public Set { protected: XPlex p; public: OXPSet(int chunksize = DEFAULT_INITIAL_CAPACITY); OXPSet(const OXPSet&); Pix add( item); void del( item); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); int owns(Pix i); Pix seek( item); void operator |= (OXPSet& b); void operator -= (OXPSet& b); void operator &= (OXPSet& b); int operator == (OXPSet& b); int operator != (OXPSet& b); int operator <= (OXPSet& b); int OK(); }; inline OXPSet::OXPSet(int chunksize) : p(chunksize) { count = 0; } inline OXPSet::OXPSet(const OXPSet& s) : p(s.p) { count = s.count; } inline Pix OXPSet::first() { return p.first(); } inline void OXPSet::next(Pix & idx) { p.next(idx); } inline & OXPSet::operator ()(Pix idx) { return p(idx); } inline void OXPSet::clear() { count = 0; p.clear(); } inline int OXPSet::contains ( item) { return seek(item) != 0; } inline int OXPSet::owns (Pix idx) { return p.owns(idx); } inline int OXPSet::operator != (OXPSet& b) { return !(*this == b); } #endif ./g++-include/gen/PHPQ.hP100644 0 1 4644 5522102432 13365 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) adapted for libg++ by Doug Lea (dl@rocky.oswego.edu) 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. */ #ifndef PHPQ_h #ifdef __GNUG__ #pragma interface #endif #define PHPQ_h 1 #include ".PQ.h" #ifndef PHPQIndex #define PHPQIndex unsigned short #endif struct PHPQNode { PHPQIndex sibling; PHPQIndex children; item; char valid; }; class PHPQ : public PQ { PHPQNode* storage; // table -- freelist in storage[0].sibling int root; int size; void prealloc(int); int check_sibling_list(int); public: PHPQ(int sz = DEFAULT_INITIAL_CAPACITY); PHPQ(PHPQ&); ~PHPQ(); Pix enq( item); deq(); & front(); void del_front(); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); void del(Pix i); Pix seek( item); int OK(); // rep invariant }; inline PHPQ::~PHPQ() { delete [] storage; } inline PHPQ::deq() { if (count == 0) error("deq of empty PQ"); x = storage[root].item; del_front(); return x; } inline & PHPQ::front() { if (count == 0) error("front of empty PQ"); return storage[root].item; } inline int PHPQ::contains( item) { return seek(item) != 0; } inline & PHPQ::operator() (Pix p) { if (p == 0) error("null Pix"); return storage[int(p)].item; } #endif ./g++-include/gen/PQ.hP100644 0 1 4505 5522102433 13132 0ustar rootdaemon// 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) 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. */ #ifndef _PQ_h #ifdef __GNUG__ #pragma interface #endif #define _PQ_h 1 #include #include ".defs.h" class PQ { protected: int count; public: PQ(); virtual ~PQ(); int length(); // current number of items int empty(); virtual Pix enq( item) = 0; // add item; return Pix virtual deq(); // return & remove min virtual & front() = 0; // access min item virtual void del_front() = 0; // delete min item virtual int contains( item); // is item in PQ? virtual void clear(); // delete all items virtual Pix first() = 0; // Pix of first item or 0 virtual void next(Pix& i) = 0; // advance to next or 0 virtual & operator () (Pix i) = 0; // access item at i virtual void del(Pix i) = 0; // delete item at i virtual int owns(Pix i); // is i a valid Pix ? virtual Pix seek( item); // Pix of item void error(const char* msg); virtual int OK() = 0; // rep invariant }; inline PQ::PQ() :count(0) {} inline PQ::~PQ() {} inline int PQ::length() { return count; } inline int PQ::empty() { return count == 0; } #endif ./g++-include/gen/PSList.hP100644 0 1 2126 5522102433 13765 0ustar rootdaemon/* : Light weight list: This will simply reuse code from a VoidP List, which was genclassed from the SLList libg++ class. The classes generated from this file will all be derived classes from class VoidSLList or intSLList. Note that class SLList does not offer all the functionality of List classes, such as sharing of sub-lists. However, no additional code is needed at all and no .cc file is generated. So it costs nothing to use these type-safe lists. Only member functions needing type casting are re-defined */ #ifndef _SList_h #define _SList_h 1 #include "VoidP.SLList.h" #include ".defs.h" class SList : public VoidPSLList { public: SList() {} SList(SList& a) : (a) {} ~SList() {} SList& operator = (SList& a) { return (SList&) VoidPSLList::operator= (a); } & operator () (Pix p) { return (&) (VoidPSLList::operator() (p)); } & front() { return (&) VoidPSLList::front(); } & rear() { return (&) VoidPSLList::rear(); } remove_front() { return () VoidPSLList::remove_front(); } }; #endif /* conditional include */ ./g++-include/gen/PVec.hP100644 0 1 5015 5522102434 13445 0ustar rootdaemon/* : light weight Vector: This will simply reuse code from */ /* a VoidP Vec, which was genclassed from the Vec libg++ class. */ /* The classes generated from this file will all be derived classes */ /* from class VoidVec or intVec. No .cc file is generated. So */ /* it costs nothing to use these type-safe Vectors. Only member */ /* functions needing type casting are re-defined. */ /* */ #ifndef _Vec_h #define _Vec_h 1 #include "VoidP.Vec.h" #include ".defs.h" #ifndef __typedefs #define __typedefs 1 typedef void (*Procedure)( ); typedef (*Mapper)( ); typedef (*Combiner)( , ); typedef int (*Predicate)( ); typedef int (*Comparator)( , ); #endif class Vec : public VoidPVec { protected: Vec(int l, * d) : (l, (VoidP*) d) {}; public: Vec() {}; Vec(int l) : (l) {}; Vec(int l, fill_value) : (l, fill_value) {}; Vec(Vec& v) : (v) {}; Vec(VoidPVec& v) {fake_copy(v, s, len);} ~Vec() {}; Vec& operator = (Vec& a) {return (Vec&) VoidPVec::operator= (a);} Vec at(int from, int n) {return (Vec) VoidPVec::at(from, n);} & operator [] (int n) {return (&)VoidPVec::operator[] (n);} & elem(int n) {return (&)VoidPVec::elem(n);} friend Vec concat(Vec& a, Vec& b); friend Vec map(Mapper f, Vec & a); friend Vec merge(Vec & a, Vec & b, Comparator f); friend Vec combine(Combiner f, Vec & a, Vec & b); friend Vec reverse(Vec& a); void sort(Comparator f); void apply(Procedure f); reduce(Combiner f, base); }; inline Vec concat(Vec& a, Vec& b) {return (Vec)concat((VoidPVec&)a, (VoidPVec&)b);} inline Vec map(Mapper f, Vec & a) { return (Vec)map((VoidPMapper)f, (VoidPVec&)a); } inline Vec merge(Vec & a, Vec & b, Comparator f) { return (Vec)merge((VoidPVec&)a, (VoidPVec&)b, (VoidPComparator)f); } inline Vec combine(Combiner f, Vec & a, Vec & b) { return (Vec)combine((VoidPCombiner)f, (VoidPVec&)a, (VoidPVec&)b); } inline Vec reverse(Vec& a) { return (Vec)reverse((VoidPVec&)a);} inline void Vec::sort(Comparator f) { VoidPVec::sort((VoidPComparator) f); } inline void Vec::apply(Procedure f) { VoidPVec::apply((VoidPProcedure) f); } inline Vec::reduce(Combiner f, base) { return ()VoidPVec::reduce((VoidPCombiner)f, base);} #endif /* conditional include */ ./g++-include/gen/Plex.hP100644 0 1 31334 5522102435 13544 0ustar rootdaemon// 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. */ #ifndef _Plex_h #ifdef __GNUG__ #pragma interface #endif #define _Plex_h 1 #include #include #include ".defs.h" // Plexes are made out of IChunks #include class IChunk { //public: // kludge until C++ `protected' policies settled protected: * data; // data, from client int base; // lowest possible index int low; // lowest valid index int fence; // highest valid index + 1 int top; // highest possible index + 1 IChunk* nxt; // circular links IChunk* prv; public: // constructors IChunk(* d, // ptr to array of elements int base_idx, // initial indices int low_idx, int fence_idx, int top_idx); virtual ~IChunk(); // status reports int size() const; // number of slots virtual int empty() const ; virtual int full() const ; int can_grow_high () const ; // there is space to add data int can_grow_low () const; int base_index() const; // lowest possible index; int low_index() const; // lowest actual index; virtual int first_index() const; // lowest valid index or fence if none virtual int last_index() const; // highest valid index or low-1 if none int fence_index() const; // highest actual index + 1 int top_index() const; // highest possible index + 1 // indexing conversion int possible_index(int i) const; // i between base and top int actual_index(int i) const; // i between low and fence virtual int valid_index(int i) const; // i not deleted (mainly for mchunks) int possible_pointer(const * p) const; // same for ptr int actual_pointer(const * p) const; virtual int valid_pointer(const * p) const; * pointer_to(int i) const ; // pointer to data indexed by i // caution: i is not checked for validity int index_of(const * p) const; // index of data pointed to by p // caution: p is not checked for validity virtual int succ(int idx) const; // next valid index or fence if none virtual int pred(int idx) const; // previous index or low - 1 if none virtual * first_pointer() const; // pointer to first valid pos or 0 virtual * last_pointer() const; // pointer to first valid pos or 0 virtual * succ(* p) const; // next pointer or 0 virtual * pred(* p) const; // previous pointer or 0 // modification virtual * grow_high (); // return spot to add an element virtual * grow_low (); virtual void shrink_high (); // logically delete top index virtual void shrink_low (); virtual void clear(int lo); // reset to empty ch with base = lo virtual void cleardown(int hi); // reset to empty ch with top = hi void re_index(int lo); // re-index so lo is new low // chunk traversal IChunk* next() const; IChunk* prev() const; void link_to_prev(IChunk* prev); void link_to_next(IChunk* next); void unlink(); // state checks * invalidate(); // mark self as invalid; return data // for possible deletion virtual int OK() const; // representation invariant void error(const char*) const; void empty_error() const; void full_error() const; void index_error() const; }; // Plex is a partly `abstract' class: few of the virtuals // are implemented at the Plex level, only in the subclasses class Plex { protected: IChunk* hd; // a chunk holding the data int lo; // lowest index int fnc; // highest index + 1 int csize; // size of the chunk void invalidate(); // mark so OK() is false void del_chunk(IChunk*); // delete a chunk IChunk* tl() const; // last chunk; int one_chunk() const; // true if hd == tl() public: // constructors, etc. Plex(); // no-op virtual ~Plex(); // Access functions virtual & operator [] (int idx) = 0; // access by index; virtual & operator () (Pix p) = 0; // access by Pix; virtual & high_element () = 0; // access high element virtual & low_element () = 0; // access low element // read-only versions for const Plexes virtual const & operator [] (int idx) const = 0; // access by index; virtual const & operator () (Pix p) const = 0; // access by Pix; virtual const & high_element () const = 0; // access high element virtual const & low_element () const = 0; // access low element // Index functions virtual int valid (int idx) const = 0; // idx is an OK index virtual int low() const = 0; // lowest index or fence if none virtual int high() const = 0; // highest index or low-1 if none int ecnef() const; // low limit index (low-1) int fence() const; // high limit index (high+1) virtual void prev(int& idx) const= 0; // set idx to preceding index // caution: pred may be out of bounds virtual void next(int& idx) const = 0; // set to next index // caution: succ may be out of bounds virtual Pix first() const = 0; // Pix to low element or 0 virtual Pix last() const = 0; // Pix to high element or 0 virtual void prev(Pix& pix) const = 0; // preceding pix or 0 virtual void next(Pix& pix) const = 0; // next pix or 0 virtual int owns(Pix p) const = 0; // p is an OK Pix // index<->Pix virtual int Pix_to_index(Pix p) const = 0; // get index via Pix virtual Pix index_to_Pix(int idx) const = 0; // Pix via index // Growth virtual int add_high(const elem) =0;// add new element at high end // return new high virtual int add_low(const elem) = 0; // add new low element, // return new low // Shrinkage virtual int del_high() = 0; // remove the element at high end // return new high virtual int del_low() = 0; // delete low element, return new lo // caution: del_low/high // does not necessarily // immediately call ::~ // operations on multiple elements virtual void fill(const x); // set all elements = x virtual void fill(const x, int from, int to); // fill from to to virtual void clear() = 0; // reset to zero-sized Plex virtual int reset_low(int newlow); // change low index,return old virtual void reverse(); // reverse in-place virtual void append(const Plex& a); // concatenate a copy virtual void prepend(const Plex& a); // prepend a copy // status virtual int can_add_high() const = 0; virtual int can_add_low() const = 0; int length () const; // number of slots int empty () const; // is the plex empty? virtual int full() const = 0; // it it full? int chunk_size() const; // report chunk size; virtual int OK() const = 0; // representation invariant void error(const char* msg) const; void index_error() const; void empty_error() const; void full_error() const; }; // IChunk ops inline int IChunk:: size() const { return top - base; } inline int IChunk:: base_index() const { return base; } inline int IChunk:: low_index() const { return low; } inline int IChunk:: fence_index() const { return fence; } inline int IChunk:: top_index() const { return top; } inline * IChunk:: pointer_to(int i) const { return &(data[i-base]); } inline int IChunk:: index_of(const * p) const { return ((int)p - (int)data) / sizeof() + base; } inline int IChunk:: possible_index(int i) const { return i >= base && i < top; } inline int IChunk:: possible_pointer(const * p) const { return p >= data && p < &(data[top-base]); } inline int IChunk:: actual_index(int i) const { return i >= low && i < fence; } inline int IChunk:: actual_pointer(const * p) const { return p >= data && p < &(data[fence-base]); } inline int IChunk:: can_grow_high () const { return fence < top; } inline int IChunk:: can_grow_low () const { return base < low; } inline * IChunk:: invalidate() { * p = data; data = 0; return p; } inline IChunk* IChunk::prev() const { return prv; } inline IChunk* IChunk::next() const { return nxt; } inline void IChunk::link_to_prev(IChunk* prev) { nxt = prev->nxt; prv = prev; nxt->prv = this; prv->nxt = this; } inline void IChunk::link_to_next(IChunk* next) { prv = next->prv; nxt = next; nxt->prv = this; prv->nxt = this; } inline void IChunk::unlink() { IChunk* n = nxt; IChunk* p = prv; n->prv = p; p->nxt = n; prv = nxt = this; } inline int IChunk:: empty() const { return low == fence; } inline int IChunk:: full() const { return top - base == fence - low; } inline int IChunk:: first_index() const { return (low == fence)? fence : low; } inline int IChunk:: last_index() const { return (low == fence)? low - 1 : fence - 1; } inline int IChunk:: succ(int i) const { return (i < low) ? low : i + 1; } inline int IChunk:: pred(int i) const { return (i > fence) ? (fence - 1) : i - 1; } inline int IChunk:: valid_index(int i) const { return i >= low && i < fence; } inline int IChunk:: valid_pointer(const * p) const { return p >= &(data[low - base]) && p < &(data[fence - base]); } inline * IChunk:: grow_high () { if (!can_grow_high()) full_error(); return &(data[fence++ - base]); } inline * IChunk:: grow_low () { if (!can_grow_low()) full_error(); return &(data[--low - base]); } inline void IChunk:: shrink_high () { if (empty()) empty_error(); --fence; } inline void IChunk:: shrink_low () { if (empty()) empty_error(); ++low; } inline * IChunk::first_pointer() const { return (low == fence)? 0 : &(data[low - base]); } inline * IChunk::last_pointer() const { return (low == fence)? 0 : &(data[fence - base - 1]); } inline * IChunk::succ(* p) const { return ((p+1) < &(data[low - base]) || (p+1) >= &(data[fence - base])) ? 0 : (p+1); } inline * IChunk::pred(* p) const { return ((p-1) < &(data[low - base]) || (p-1) >= &(data[fence - base])) ? 0 : (p-1); } // generic Plex operations inline Plex::Plex() {} inline int Plex::chunk_size() const { return csize; } inline int Plex::ecnef () const { return lo - 1; } inline int Plex::fence () const { return fnc; } inline int Plex::length () const { return fnc - lo; } inline int Plex::empty () const { return fnc == lo; } inline IChunk* Plex::tl() const { return hd->prev(); } inline int Plex::one_chunk() const { return hd == hd->prev(); } #endif ./g++-include/gen/Queue.hP100644 0 1 2742 5522102436 13702 0ustar rootdaemon// 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) 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. */ #ifndef _Queue_h #ifdef __GNUG__ #pragma interface #endif #define _Queue_h #include #include ".defs.h" class Queue { public: Queue() { } virtual ~Queue(); virtual void enq( item) = 0; virtual deq() = 0; virtual & front() = 0; virtual void del_front() = 0; virtual void clear() = 0; virtual int empty() = 0; virtual int full() = 0; virtual int length() = 0; void error(const char*); virtual int OK() = 0; }; #endif ./g++-include/gen/RAVLMap.hP100644 0 1 6665 5522102437 14031 0ustar rootdaemon// 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) ranking code from Paul Anderson (paul%lfcs.ed.ac.uk) 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. */ #ifndef _RAVLMap_h #ifdef __GNUG__ #pragma interface #endif #define _RAVLMap_h 1 #include "..Map.h" struct RAVLNode { RAVLNode* lt; RAVLNode* rt; item; cont; int rank; char stat; RAVLNode( h, c, RAVLNode* l=0, RAVLNode* r=0, int k=1); ~RAVLNode(); }; inline RAVLNode::RAVLNode( h, c, RAVLNode* l, RAVLNode* r, int k) :item(h), cont(c), lt(l), rt(r), rank(k), stat(0) {} inline RAVLNode::~RAVLNode() {} typedef RAVLNode* RAVLNodePtr; class RAVLMap : public Map { protected: RAVLNode* root; RAVLNode* leftmost(); RAVLNode* rightmost(); RAVLNode* pred(RAVLNode* t); RAVLNode* succ(RAVLNode* t); void _kill(RAVLNode* t); void _add(RAVLNode*& t); void _del(RAVLNode* p, RAVLNode*& t); public: RAVLMap( dflt); RAVLMap(RAVLMap& a); ~RAVLMap(); & operator [] ( key); void del( key); Pix first(); void next(Pix& i); & key(Pix i); & contents(Pix i); Pix seek( key); int contains( key); Pix ranktoPix(int i); int rankof( key); void clear(); Pix last(); void prev(Pix& i); int OK(); }; inline RAVLMap::~RAVLMap() { _kill(root); } inline RAVLMap::RAVLMap( dflt) :Map(dflt) { root = 0; } inline Pix RAVLMap::first() { return Pix(leftmost()); } inline Pix RAVLMap::last() { return Pix(rightmost()); } inline void RAVLMap::next(Pix& i) { if (i != 0) i = Pix(succ((RAVLNode*)i)); } inline void RAVLMap::prev(Pix& i) { if (i != 0) i = Pix(pred((RAVLNode*)i)); } inline & RAVLMap::key(Pix i) { if (i == 0) error("null Pix"); return ((RAVLNode*)i)->item; } inline & RAVLMap::contents(Pix i) { if (i == 0) error("null Pix"); return ((RAVLNode*)i)->cont; } inline void RAVLMap::clear() { _kill(root); count = 0; root = 0; } inline int RAVLMap::contains( key) { return seek(key) != 0; } #endif ./g++-include/gen/RPlex.hP100644 0 1 14604 5522102440 13663 0ustar rootdaemon// 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. */ #ifndef _RPlex_h #ifdef __GNUG__ #pragma interface #endif #define _RPlex_h 1 #include ".Plex.h" // minimum number of chunks to index #ifndef MIN_NCHUNKS #define MIN_NCHUNKS 16 #endif class RPlex: public 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 IChunk** chunks; // array of chunks IChunk* ch; // cached chunk void make_initial_chunks(int up = 1); void cache(int idx) const; void cache(const * p) const; * dopred(const * p) const; * dosucc(const * p) const; void set_cache(const IChunk* t) const; // logically, // not physically const public: RPlex(); // set low = 0; // fence = 0; // csize = default RPlex(int ch_size); // low = 0; // fence = 0; // csize = ch_size RPlex(int lo, // low = lo; int ch_size); // fence=lo // csize = ch_size RPlex(int lo, // low = lo int hi, // fence = hi+1 const initval,// fill with initval, int ch_size = 0); // csize= ch_size // or fence-lo if 0 RPlex(const RPlex&); ~RPlex(); void operator= (const RPlex&); // virtuals & high_element (); & low_element (); const & high_element () const; const & low_element () const; Pix first() const; Pix last() const; void prev(Pix& ptr) const; void next(Pix& ptr) const; int owns(Pix p) const; & operator () (Pix p); const & operator () (Pix p) const; int low() const; int high() const; int valid(int idx) const; void prev(int& idx) const; void next(int& x) const; & operator [] (int index); const & operator [] (int index) const; int Pix_to_index(Pix p) const; Pix index_to_Pix(int idx) const; int can_add_high() const; int can_add_low() const; int full() const; int add_high(const elem); int del_high (); int add_low (const elem); int del_low (); void fill(const x); void fill(const x, int from, int to); void clear(); void reverse(); int reset_low(int newlow); int OK () const; }; inline void RPlex::prev(int& idx) const { --idx; } inline void RPlex::next(int& idx) const { ++idx; } inline int RPlex::full () const { return 0; } inline int RPlex::can_add_high() const { return 1; } inline int RPlex::can_add_low() const { return 1; } inline int RPlex::valid (int idx) const { return idx >= lo && idx < fnc; } inline int RPlex::low() const { return lo; } inline int RPlex::high() const { return fnc - 1; } inline void RPlex::set_cache(const IChunk* t) const { ((RPlex*)(this))->ch = (IChunk*)t; } inline void RPlex::cache(int idx) const { if (idx < lo || idx >= fnc) index_error(); set_cache(chunks[(idx - base) / csize]); } inline & RPlex::low_element () { cache(lo); return *(ch->pointer_to(lo)); } inline & RPlex::high_element () { cache(fnc-1); return *(ch->pointer_to(fnc - 1)); } inline const & RPlex::low_element () const { cache(lo); return *((const *)(ch->pointer_to(lo))); } inline const & RPlex::high_element () const { cache(fnc-1); return *((const *)(ch->pointer_to(fnc - 1))); } inline int RPlex::Pix_to_index(Pix px) const { * p = (*)px; if (!ch->actual_pointer(p)) cache(p); return ch->index_of(p); } inline Pix RPlex::index_to_Pix(int idx) const { if (!ch->actual_index(idx)) cache(idx); return (Pix)(ch->pointer_to(idx)); } inline Pix RPlex::first() const { return Pix(hd->IChunk::first_pointer()); } inline Pix RPlex::last() const { return Pix(tl()->IChunk::last_pointer()); } inline void RPlex::prev(Pix& p) const { Pix q = Pix(ch->IChunk::pred((*)p)); p = (q == 0)? Pix(dopred((*)p)) : q; } inline void RPlex::next(Pix& p) const { Pix q = Pix(ch->IChunk::succ((*)p)); p = (q == 0)? Pix(dosucc((*)p)) : q; } inline & RPlex:: operator () (Pix p) { return *((*)p); } inline & RPlex:: operator [] (int idx) { cache(idx); return *(ch->pointer_to(idx)); } inline const & RPlex:: operator () (Pix p) const { return *((const *)p); } inline const & RPlex:: operator [] (int idx) const { cache(idx); return *((const *)(ch->pointer_to(idx))); } inline RPlex::~RPlex() { delete chunks; } #endif ./g++-include/gen/SLBag.hP100644 0 1 4122 5522102441 13534 0ustar rootdaemon// 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) 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. */ #ifndef _SLBag_h #ifdef __GNUG__ #pragma interface #endif #define _SLBag_h 1 #include ".Bag.h" #include ".SLList.h" class SLBag : public Bag { protected: SLList p; public: SLBag(); SLBag(const SLBag&); Pix add( item); void del( item); void remove(item); int contains( item); int nof( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); int owns(Pix i); Pix seek( item, Pix from = 0); int OK(); }; inline SLBag::SLBag() : p() { count = 0; } inline SLBag::SLBag(const SLBag& s) : p(s.p) { count = s.count; } inline Pix SLBag::first() { return p.first(); } inline void SLBag::next(Pix & idx) { p.next(idx); } inline & SLBag::operator ()(Pix idx) { return p(idx); } inline void SLBag::clear() { count = 0; p.clear(); } inline int SLBag::owns (Pix idx) { return p.owns(idx); } inline Pix SLBag::add( item) { ++count; return p.append(item); } inline int SLBag::contains( item) { return seek(item) != 0; } #endif ./g++-include/gen/SLList.hP100644 0 1 6317 5522102441 13766 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- // WARNING: This file is obsolete. Use ../SLList.h, if you can. /* Copyright (C) 1988 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) 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. */ #ifndef _SLList_h #ifdef __GNUG__ #pragma interface #endif #define _SLList_h 1 #include #include ".defs.h" #ifndef _SLListNode_h #define _SLListNode_h 1 struct SLListNode { SLListNode* tl; hd; SLListNode() { } SLListNode(const h, SLListNode* t = 0); ~SLListNode() { } }; inline SLListNode::SLListNode(const h, SLListNode* t) :hd(h), tl(t) {} typedef SLListNode* SLListNodePtr; #endif class SLList { protected: SLListNode* last; public: SLList(); SLList(const SLList& a); ~SLList(); SLList& operator = (const SLList& a); int empty(); int length(); void clear(); Pix prepend( item); Pix append( item); void join(SLList&); Pix prepend(SLListNode*); Pix append(SLListNode*); & operator () (Pix p); Pix first(); void next(Pix& p); int owns(Pix p); Pix ins_after(Pix p, item); void del_after(Pix p); & front(); & rear(); remove_front(); int remove_front(& x); void del_front(); void error(const char* msg); int OK(); }; inline SLList::~SLList() { clear(); } inline SLList::SLList() { last = 0; } inline int SLList::empty() { return last == 0; } inline Pix SLList::first() { return (last == 0)? 0 : Pix(last->tl); } inline void SLList::next(Pix& p) { p = (p == 0 || p == last)? 0 : Pix(((SLListNode*)(p))->tl); } inline & SLList::operator () (Pix p) { if (p == 0) error("null Pix"); return ((SLListNode*)(p))->hd; } inline & SLList::front() { if (last == 0) error("front: empty list"); return last->tl->hd; } inline & SLList::rear() { if (last == 0) error("rear: empty list"); return last->hd; } #endif ./g++-include/gen/SLQueue.hP100644 0 1 4234 5522102442 14134 0ustar rootdaemon// 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) 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. */ #ifndef _SLQueue_h #ifdef __GNUG__ #pragma interface #endif #define _SLQueue_h #include ".SLList.h" #include ".Queue.h" class SLQueue : public Queue { SLList p; public: SLQueue(); SLQueue(const SLQueue& q); ~SLQueue(); void operator = (const SLQueue&); void enq( item); deq(); & front(); void del_front(); void clear(); int empty(); int full(); int length(); int OK(); }; inline SLQueue::SLQueue() :p() {} inline SLQueue::SLQueue(const SLQueue& q) : p(q.p) {} inline SLQueue::~SLQueue() {} inline void SLQueue::enq(item) { p.append(item); } inline SLQueue::deq() { return p.remove_front(); } inline & SLQueue::front() { return p.front(); } inline void SLQueue::del_front() { p.del_front(); } inline void SLQueue::operator =(const SLQueue& s) { p = s.p; } inline int SLQueue::empty() { return p.empty(); } inline int SLQueue::full() { return 0; } inline int SLQueue::length() { return p.length(); } inline int SLQueue::OK() { return p.OK(); } inline void SLQueue::clear() { p.clear(); } #endif ./g++-include/gen/SLSet.hP100644 0 1 3665 5522102443 13613 0ustar rootdaemon// 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) 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. */ #ifndef _SLSet_h #ifdef __GNUG__ #pragma interface #endif #define _SLSet_h 1 #include ".Set.h" #include ".SLList.h" class SLSet : public Set { protected: SLList p; public: SLSet(); SLSet(const SLSet&); Pix add( item); void del( item); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); int owns(Pix i); Pix seek( item); int OK(); }; inline SLSet::SLSet() : p() { count = 0; } inline SLSet::SLSet(const SLSet& s) : p(s.p) { count = s.count; } inline Pix SLSet::first() { return p.first(); } inline void SLSet::next(Pix & idx) { p.next(idx); } inline & SLSet::operator ()(Pix idx) { return p(idx); } inline void SLSet::clear() { count = 0; p.clear(); } inline int SLSet::contains ( item) { return seek(item) != 0; } inline int SLSet::owns (Pix idx) { return p.owns(idx); } #endif ./g++-include/gen/SLStack.hP100644 0 1 4244 5522102444 14120 0ustar rootdaemon// 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) 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. */ #ifndef _SLStack_h #ifdef __GNUG__ #pragma interface #endif #define _SLStack_h 1 #include ".SLList.h" #include ".Stack.h" class SLStack : public Stack { SLList p; public: SLStack(); SLStack(const SLStack& s); ~SLStack(); void operator = (const SLStack&); void push( item); pop(); & top(); void del_top(); int empty(); int full(); int length(); void clear(); int OK(); }; inline SLStack::SLStack() :p() {} inline SLStack::SLStack(const SLStack& a) : p(a.p) {} inline SLStack::~SLStack() {} inline void SLStack::push( item) { p.prepend(item); } inline SLStack::pop() { return p.remove_front(); } inline & SLStack::top() { return p.front(); } inline void SLStack::del_top() { p.del_front(); } inline void SLStack::operator =(const SLStack& s) { p = s.p; } inline int SLStack::empty() { return p.empty(); } inline int SLStack::full() { return 0; } inline int SLStack::length() { return p.length(); } inline int SLStack::OK() { return p.OK(); } inline void SLStack::clear() { p.clear(); } #endif ./g++-include/gen/Set.hP100644 0 1 4644 5522102445 13354 0ustar rootdaemon// 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) 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. */ #ifndef _Set_h #ifdef __GNUG__ #pragma interface #endif #define _Set_h 1 #include #include ".defs.h" class Set { protected: int count; public: virtual ~Set(); int length(); // current number of items int empty(); virtual Pix add( item) = 0; // add item; return Pix virtual void del( item) = 0; // delete item virtual int contains( item); // is item in set? virtual void clear(); // delete all items virtual Pix first() = 0; // Pix of first item or 0 virtual void next(Pix& i) = 0; // advance to next or 0 virtual & operator () (Pix i) = 0; // access item at i virtual int owns(Pix i); // is i a valid Pix ? virtual Pix seek( item); // Pix of item void operator |= (Set& b); // add all items in b void operator -= (Set& b); // delete items also in b void operator &= (Set& b); // delete items not in b int operator == (Set& b); int operator != (Set& b); int operator <= (Set& b); void error(const char* msg); virtual int OK() = 0; // rep invariant }; inline Set::~Set() {} inline int Set::length() { return count; } inline int Set::empty() { return count == 0; } #endif ./g++-include/gen/SkipBag.hP100644 0 1 7367 5522102446 14147 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* 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. */ /* * Bags implemented via William Pugh SkipList algorithms. * CACM, June 1990, p 668-676. * */ #ifndef _SkipBag_h #ifdef __GNUG__ #pragma interface #endif #define _SkipBag_h 1 #include ".Bag.h" #include #include class SkipBag; class RealSkipBagNode; class SkipBagNode { friend class SkipBag; private: RealSkipBagNode * * forward; SkipBagNode(int size); }; class RealSkipBagNode : public SkipBagNode { friend class SkipBag; private: item; RealSkipBagNode( h, int size); }; typedef RealSkipBagNode* SkipBagNodePtr; inline SkipBagNode::SkipBagNode(int size) : forward(new SkipBagNodePtr[size+1]) { } inline RealSkipBagNode::RealSkipBagNode( h, int size) : item(h), SkipBagNode(size) { } class SkipBag : public Bag { friend class SkipBaginit; protected: SkipBagNode* header; int level; int max_levels; int randoms_left; long random_bits; static MLCG* gen; int random_level(void); SkipBagNodePtr leftmost(void); SkipBagNodePtr rightmost(void); SkipBagNodePtr pred(SkipBagNodePtr t); SkipBagNodePtr succ(SkipBagNodePtr t); void _kill(void); private: enum { BITS_IN_RANDOM = LONGBITS-1 }; public: SkipBag(long size=DEFAULT_INITIAL_CAPACITY); SkipBag(SkipBag& a); ~SkipBag(void); Pix add( i); void del( i); void remove(i); int nof( i); int contains( i); void clear(void); Pix first(void); void next(Pix& i); & operator () (Pix i); Pix seek( i, Pix from = 0); Pix last(void); void prev(Pix& i); int OK(void); }; inline SkipBagNodePtr SkipBag::leftmost(void) { return header->forward[0]; } inline SkipBagNodePtr SkipBag::succ(SkipBagNodePtr t) { SkipBagNodePtr result = 0; if (t->forward[0]!=header) result = t->forward[0]; return result; } inline Pix SkipBag::first(void) { return Pix(leftmost()); } inline Pix SkipBag::last(void) { return Pix(rightmost()); } inline void SkipBag::next(Pix& i) { if (i != 0) i = Pix(succ((SkipBagNodePtr)i)); } inline & SkipBag::operator () (Pix i) { if (i == 0) error("null Pix"); return ((SkipBagNodePtr)i)->item; } inline void SkipBag::prev(Pix& i) { if (i != 0) i = Pix(pred((SkipBagNodePtr)i)); } inline int SkipBag::contains( key) { return seek(key) != 0; } inline SkipBag::~SkipBag() { _kill(); delete header; } static class SkipBaginit { public: SkipBaginit(); ~SkipBaginit(); private: static int count; } skipBaginit; #endif ./g++-include/gen/SkipMap.hP100644 0 1 10023 5522102446 14172 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* 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. */ /* * Bags implemented via William Pugh SkipList algorithms. * CACM, June 1990, p 668-676. * */ #ifndef _SkipMap_h #ifdef __GNUG__ #pragma interface #endif #define _SkipMap_h 1 #include "..Map.h" #include #include class SkipMap; class RealSkipMapNode; class SkipMapNode { friend class SkipMap; private: RealSkipMapNode * * forward; protected: SkipMapNode(int size); }; class RealSkipMapNode : public SkipMapNode { friend class SkipMap; private: item; cont; RealSkipMapNode( h, i, int size); }; typedef RealSkipMapNode* SkipMapNodePtr; inline SkipMapNode::SkipMapNode(int size) : forward(new SkipMapNodePtr[size+1]) { } inline RealSkipMapNode::RealSkipMapNode( h, i, int size) : item(h), cont(i), SkipMapNode(size) { } class SkipMap : public Map { friend class SkipMapinit; protected: SkipMapNode* header; int level; int max_levels; int randoms_left; long random_bits; static MLCG* gen; int random_level(void); SkipMapNodePtr leftmost(); SkipMapNodePtr rightmost(); SkipMapNodePtr pred(SkipMapNodePtr t); SkipMapNodePtr succ(SkipMapNodePtr t); void _kill(); private: enum { BITS_IN_RANDOM = LONGBITS-1 }; public: SkipMap( dflt, long size=DEFAULT_INITIAL_CAPACITY); SkipMap(SkipMap& a); ~SkipMap(); & operator [] ( key); void del( key); Pix first(); void next(Pix& i); & key(Pix i); & contents(Pix i); Pix seek( key); int contains( key); void clear(); Pix last(); void prev(Pix& i); int OK(); }; inline SkipMap::~SkipMap() { _kill(); delete header; } inline SkipMapNodePtr SkipMap::leftmost() { return header->forward[0]==header ? 0 : header->forward[0]; } inline Pix SkipMap::first() { return Pix(leftmost()); } inline Pix SkipMap::last() { return Pix(rightmost()); } inline SkipMapNodePtr SkipMap::succ(SkipMapNodePtr t) { return t->forward[0]==header ? 0 : t->forward[0]; } inline void SkipMap::next(Pix& i) { if (i != 0) i = Pix(succ((SkipMapNodePtr)i)); } inline void SkipMap::prev(Pix& i) { if (i != 0) i = Pix(pred((SkipMapNodePtr)i)); } inline & SkipMap::key (Pix i) { if (i == 0) error("null Pix"); return ((SkipMapNodePtr)i)->item; } inline & SkipMap::contents (Pix i) { if (i == 0) error("null Pix"); return ((SkipMapNodePtr)i)->cont; } inline int SkipMap::contains( key) { return seek(key) != 0; } static class SkipMapinit { public: SkipMapinit(); ~SkipMapinit(); private: static int count; } skipMapinit; #endif ./g++-include/gen/SkipSet.hP100644 0 1 10124 5522102447 14213 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* 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. * */ #ifndef _SkipSet_h #ifdef __GNUG__ #pragma interface #endif #define _SkipSet_h 1 #include ".Set.h" #include #include class SkipSet; class RealSkipSetNode; class SkipSetNode { friend class SkipSet; private: RealSkipSetNode * * forward; SkipSetNode(int size); }; class RealSkipSetNode : public SkipSetNode { friend class SkipSet; private: item; RealSkipSetNode( h, int size); }; typedef RealSkipSetNode* SkipSetNodePtr; inline SkipSetNode::SkipSetNode(int size) : forward(new SkipSetNodePtr[size+1]) { } inline RealSkipSetNode::RealSkipSetNode( h, int size) : item(h), SkipSetNode(size) { } class SkipSet : public Set { friend class SkipSetinit; protected: SkipSetNode* header; int level; int max_levels; int randoms_left; long random_bits; static MLCG* gen; int random_level(void); SkipSetNodePtr leftmost(void); SkipSetNodePtr rightmost(void); SkipSetNodePtr pred(SkipSetNodePtr t); SkipSetNodePtr succ(SkipSetNodePtr t); void _kill(void); private: enum { BITS_IN_RANDOM = LONGBITS-1 }; public: SkipSet(long size=DEFAULT_INITIAL_CAPACITY); SkipSet(SkipSet& a); ~SkipSet(); Pix add( i); void del( i); int contains( i); void clear(void); Pix first(void); void next(Pix& i); & operator () (Pix i); Pix seek( i); Pix last(void); void prev(Pix& i); void operator |= (SkipSet& b); void operator -= (SkipSet& b); void operator &= (SkipSet& b); int operator == (SkipSet& b); int operator != (SkipSet& b); int operator <= (SkipSet& b); int OK(void); }; /* * A little overkill on the inlines. * */ inline SkipSet::~SkipSet(void) { _kill(); delete header; } inline int SkipSet::operator != (SkipSet& b) { return ! (*this == b); } inline SkipSetNodePtr SkipSet::leftmost(void) { return header->forward[0]; } inline SkipSetNodePtr SkipSet::succ(SkipSetNodePtr t) { SkipSetNodePtr result = 0; if (t->forward[0]!=header) result = t->forward[0]; return result; } inline Pix SkipSet::first(void) { return Pix(leftmost()); } inline Pix SkipSet::last(void) { return Pix(rightmost()); } inline void SkipSet::next(Pix& i) { if (i != 0) i = Pix(succ((SkipSetNodePtr)i)); } inline void SkipSet::prev(Pix& i) { if (i != 0) i = Pix(pred((SkipSetNodePtr)i)); } inline & SkipSet::operator () (Pix i) { if (i == 0) error("null Pix"); return ((SkipSetNodePtr)i)->item; } inline int SkipSet::contains( key) { return seek(key) != 0; } static class SkipSetinit { public: SkipSetinit(); ~SkipSetinit(); private: static int count; } skipSetinit; #endif ./g++-include/gen/SplayBag.hP100644 0 1 7112 5522102450 14310 0ustar rootdaemon// 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) 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. */ // This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988, 1982 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) 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. */ #ifndef _SplayBag_h #ifdef __GNUG__ #pragma interface #endif #define _SplayBag_h 1 #include ".Bag.h" #include ".SplayNode.h" class SplayBag : public Bag { protected: SplayNode* root; SplayNode* leftmost(); SplayNode* rightmost(); SplayNode* pred(SplayNode* t); SplayNode* succ(SplayNode* t); void _kill(SplayNode* t); SplayNode* _copy(SplayNode* t); void _del(SplayNode* t); public: SplayBag(); SplayBag(SplayBag& a); ~SplayBag(); Pix add( item); void del( item); void remove(item); int nof( item); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); Pix seek( item, Pix from = 0); Pix last(); void prev(Pix& i); int OK(); }; inline SplayBag::~SplayBag() { _kill(root); } inline SplayBag::SplayBag() { root = 0; count = 0; } inline SplayBag::SplayBag(SplayBag& b) { count = b.count; root = _copy(b.root); } inline Pix SplayBag::first() { return Pix(leftmost()); } inline Pix SplayBag::last() { return Pix(rightmost()); } inline void SplayBag::next(Pix& i) { if (i != 0) i = Pix(succ((SplayNode*)i)); } inline void SplayBag::prev(Pix& i) { if (i != 0) i = Pix(pred((SplayNode*)i)); } inline & SplayBag::operator () (Pix i) { if (i == 0) error("null Pix"); return ((SplayNode*)i)->item; } inline void SplayBag::clear() { _kill(root); count = 0; root = 0; } inline int SplayBag::contains( key) { return seek(key) != 0; } inline void SplayBag::del( key) { _del((SplayNode*)(seek(key))); } #endif ./g++-include/gen/SplayMap.hP100644 0 1 7004 5522102451 14335 0ustar rootdaemon// 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) 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. */ #ifndef _SplayMap_h #ifdef __GNUG__ #pragma interface #endif #define _SplayMap_h 1 #include "..Map.h" #ifndef _SplayNode #define _SplayNode 1 struct SplayNode { SplayNode* lt; SplayNode* rt; SplayNode* par; item; cont; SplayNode( h, c, SplayNode* l=0, SplayNode* r=0); ~SplayNode(); }; inline SplayNode::SplayNode( h, c, SplayNode* l, SplayNode* r) :item(h), cont(c), lt(l), rt(r), par(0) {} inline SplayNode::~SplayNode() {} typedef SplayNode* SplayNodePtr; #endif class SplayMap : public Map { protected: SplayNode* root; SplayNode* leftmost(); SplayNode* rightmost(); SplayNode* pred(SplayNode* t); SplayNode* succ(SplayNode* t); void _kill(SplayNode* t); SplayNode* _copy(SplayNode* t); public: SplayMap( dflt); SplayMap(SplayMap& a); ~SplayMap(); & operator [] ( key); void del( key); Pix first(); void next(Pix& i); & key(Pix i); & contents(Pix i); Pix seek( key); int contains( key); void clear(); Pix last(); void prev(Pix& i); int OK(); }; inline SplayMap::~SplayMap() { _kill(root); } inline SplayMap::SplayMap( dflt) :Map(dflt) { root = 0; } inline SplayMap::SplayMap(SplayMap& b) :Map(b.def) { count = b.count; root = _copy(b.root); } inline Pix SplayMap::first() { return Pix(leftmost()); } inline Pix SplayMap::last() { return Pix(rightmost()); } inline void SplayMap::next(Pix& i) { if (i != 0) i = Pix(succ((SplayNode*)i)); } inline void SplayMap::prev(Pix& i) { if (i != 0) i = Pix(pred((SplayNode*)i)); } inline & SplayMap::key (Pix i) { if (i == 0) error("null Pix"); return ((SplayNode*)i)->item; } inline & SplayMap::contents (Pix i) { if (i == 0) error("null Pix"); return ((SplayNode*)i)->cont; } inline void SplayMap::clear() { _kill(root); count = 0; root = 0; } inline int SplayMap::contains( key) { return seek(key) != 0; } #endif ./g++-include/gen/SplayNode.hP100644 0 1 2620 5522102452 14505 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988, 1982 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) 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. */ #ifndef _SplayNode #define _SplayNode 1 #ifdef __GNUG__ #pragma interface #endif #include ".defs.h" struct SplayNode { SplayNode* lt; SplayNode* rt; SplayNode* par; item; SplayNode( h, SplayNode* l=0, SplayNode* r=0); ~SplayNode(); }; inline SplayNode::SplayNode( h, SplayNode* l, SplayNode* r) :item(h), lt(l), rt(r), par(0) {} inline SplayNode::~SplayNode() {} typedef SplayNode* SplayNodePtr; #endif ./g++-include/gen/SplayPQ.hP100644 0 1 5147 5522102453 14150 0ustar rootdaemon// 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) 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. */ #ifndef _SplayPQ_h #ifdef __GNUG__ #pragma interface #endif #define _SplayPQ_h 1 #include ".PQ.h" #include ".SplayNode.h" class SplayPQ : public PQ { protected: SplayNode* root; SplayNode* leftmost(); SplayNode* rightmost(); SplayNode* pred(SplayNode* t); SplayNode* succ(SplayNode* t); void _kill(SplayNode* t); SplayNode* _copy(SplayNode* t); public: SplayPQ(); SplayPQ(SplayPQ& a); virtual ~SplayPQ(); Pix enq( item); deq(); & front(); void del_front(); int contains( item); void clear(); Pix first(); Pix last(); void next(Pix& i); void prev(Pix& i); & operator () (Pix i); void del(Pix i); Pix seek( item); int OK(); // rep invariant }; inline SplayPQ::~SplayPQ() { _kill(root); } inline SplayPQ::SplayPQ() { root = 0; count = 0; } inline SplayPQ::SplayPQ(SplayPQ& b) { count = b.count; root = _copy(b.root); } inline Pix SplayPQ::first() { return Pix(leftmost()); } inline Pix SplayPQ::last() { return Pix(rightmost()); } inline void SplayPQ::next(Pix& i) { if (i != 0) i = Pix(succ((SplayNode*)i)); } inline void SplayPQ::prev(Pix& i) { if (i != 0) i = Pix(pred((SplayNode*)i)); } inline & SplayPQ::operator () (Pix i) { if (i == 0) error("null Pix"); return ((SplayNode*)i)->item; } inline void SplayPQ::clear() { _kill(root); count = 0; root = 0; } inline int SplayPQ::contains( key) { return seek(key) != 0; } #endif ./g++-include/gen/SplaySet.hP100644 0 1 6217 5522102453 14362 0ustar rootdaemon// 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) 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. */ #ifndef _SplaySet_h #ifdef __GNUG__ #pragma interface #endif #define _SplaySet_h 1 #include ".Set.h" #include ".SplayNode.h" class SplaySet : public Set { protected: SplayNode* root; SplayNode* leftmost(); SplayNode* rightmost(); SplayNode* pred(SplayNode* t); SplayNode* succ(SplayNode* t); void _kill(SplayNode* t); SplayNode* _copy(SplayNode* t); public: SplaySet(); SplaySet(SplaySet& a); ~SplaySet(); Pix add( item); void del( item); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); Pix seek( item); Pix last(); void prev(Pix& i); SplaySet& operator = (const SplaySet& b); void operator |= (SplaySet& b); void operator -= (SplaySet& b); void operator &= (SplaySet& b); int operator == (SplaySet& b); int operator != (SplaySet& b); int operator <= (SplaySet& b); int OK(); }; inline SplaySet::~SplaySet() { _kill(root); } inline SplaySet::SplaySet() { root = 0; count = 0; } inline SplaySet::SplaySet(SplaySet& b) { count = b.count; root = _copy(b.root); } inline SplaySet& SplaySet::operator = (const SplaySet& b) { if (this != &b) { _kill (root); count = b.count; root = _copy (b.root); } return *this; } inline int SplaySet::operator != (SplaySet& b) { return ! (*this == b); } inline Pix SplaySet::first() { return Pix(leftmost()); } inline Pix SplaySet::last() { return Pix(rightmost()); } inline void SplaySet::next(Pix& i) { if (i != 0) i = Pix(succ((SplayNode*)i)); } inline void SplaySet::prev(Pix& i) { if (i != 0) i = Pix(pred((SplayNode*)i)); } inline & SplaySet::operator () (Pix i) { if (i == 0) error("null Pix"); return ((SplayNode*)i)->item; } inline void SplaySet::clear() { _kill(root); count = 0; root = 0; } inline int SplaySet::contains( key) { return seek(key) != 0; } #endif ./g++-include/gen/Stack.hP100644 0 1 2754 5522102454 13666 0ustar rootdaemon// 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) 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. */ #ifndef _Stack_h #ifdef __GNUG__ #pragma interface #endif #define _Stack_h #include #include ".defs.h" class Stack { public: Stack() { } virtual ~Stack(); virtual void push( item) = 0; virtual pop() = 0; virtual & top() = 0; virtual void del_top() = 0; virtual int empty() = 0; virtual int full() = 0; virtual int length() = 0; virtual void clear() = 0; void error(const char*); virtual int OK() = 0; }; #endif ./g++-include/gen/VHBag.hP100644 0 1 3700 5522102455 13541 0ustar rootdaemon// 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) 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. */ #ifndef _VHBag_h #ifdef __GNUG__ #pragma interface #endif #define _VHBag_h 1 #include ".Bag.h" class VHBag : public Bag { protected: * tab; char* status; unsigned int size; public: VHBag(unsigned int sz = DEFAULT_INITIAL_CAPACITY); VHBag(VHBag& a); ~VHBag(); Pix add( item); void del( item); void remove(item); int nof( item); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); Pix seek( item, Pix from = 0); int capacity(); void resize(unsigned int newsize = 0); int OK(); }; inline VHBag::~VHBag() { delete [] tab; delete status; } inline int VHBag::capacity() { return size; } inline int VHBag::contains( key) { return seek(key) != 0; } inline & VHBag::operator () (Pix i) { if (i == 0) error("null Pix"); return *((*)i); } #endif ./g++-include/gen/VHMap.hP100644 0 1 4042 5522102456 13566 0ustar rootdaemon// 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) 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. */ #ifndef _VHMap_h #ifdef __GNUG__ #pragma interface #endif #define _VHMap_h 1 #include "..Map.h" class VHMap : public Map { protected: * tab; * cont; char* status; unsigned int size; public: VHMap( dflt,unsigned int sz=DEFAULT_INITIAL_CAPACITY); VHMap(VHMap& a); ~VHMap(); & operator [] ( key); void del( key); Pix first(); void next(Pix& i); & key(Pix i); & contents(Pix i); Pix seek( key); int contains( key); void clear(); void resize(unsigned int newsize = 0); int OK(); }; inline VHMap::~VHMap() { delete [] tab; delete [] cont; delete [] status; } inline int VHMap::contains( key) { return seek(key) != 0; } inline & VHMap::key(Pix i) { if (i == 0) error("null Pix"); return *((*)i); } inline & VHMap::contents(Pix i) { if (i == 0) error("null Pix"); return cont[((unsigned)(i) - (unsigned)(tab)) / sizeof()]; } #endif ./g++-include/gen/VHSet.hP100644 0 1 4305 5522102457 13607 0ustar rootdaemon// 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) 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. */ #ifndef _VHSet_h #ifdef __GNUG__ #pragma interface #endif #define _VHSet_h 1 #include ".Set.h" class VHSet : public Set { protected: * tab; char* status; unsigned int size; public: VHSet(unsigned int sz = DEFAULT_INITIAL_CAPACITY); VHSet(VHSet& a); ~VHSet(); Pix add( item); void del( item); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); Pix seek( item); void operator |= (VHSet& b); void operator -= (VHSet& b); void operator &= (VHSet& b); int operator == (VHSet& b); int operator != (VHSet& b); int operator <= (VHSet& b); int capacity(); void resize(unsigned int newsize = 0); int OK(); }; inline VHSet::~VHSet() { delete [] tab; delete status; } inline int VHSet::capacity() { return size; } inline int VHSet::contains( key) { return seek(key) != 0; } inline & VHSet::operator () (Pix i) { if (i == 0) error("null Pix"); return *((*)i); } inline int VHSet::operator != (VHSet& b) { return ! ((*this) == b); } #endif ./g++-include/gen/VOHSet.hP100644 0 1 4324 5522102460 13721 0ustar rootdaemon// 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 Doug Schmidt 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. */ #ifndef _VOHSet_h #ifdef __GNUG__ #pragma interface #endif #define _VOHSet_h 1 #include ".Set.h" class VOHSet : public Set { * tab; char* status; int size; int cnt; // keeps track of VALIDCELLs and DELETEDCELLs public: VOHSet(int sz = DEFAULT_INITIAL_CAPACITY); VOHSet(VOHSet&); ~VOHSet(); Pix add( item); void del( item); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); Pix seek( item); void operator |= (VOHSet& b); void operator -= (VOHSet& b); void operator &= (VOHSet& b); int operator == (VOHSet& b); int operator != (VOHSet& b); int operator <= (VOHSet& b); int capacity(); void resize(int newsize = 0); int OK(); }; inline VOHSet::~VOHSet() { delete [] tab; delete status; } inline int VOHSet::contains( key) { return seek(key) != 0; } inline & VOHSet::operator () (Pix p) { if (p == 0) error("null Pix"); return *((*)p); } #endif ./g++-include/gen/VQueue.hP100644 0 1 5272 5522102460 14026 0ustar rootdaemon// 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) 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. */ #ifndef _VQueue_h #ifdef __GNUG__ #pragma interface #endif #define _VQueue_h 1 #include ".Queue.h" class VQueue : public Queue { protected: int size; int cnt; int inp; int outp; * s; public: VQueue(int sz = DEFAULT_INITIAL_CAPACITY); VQueue(VQueue&); ~VQueue(); void operator = (VQueue&); void enq( item); deq(); & front(); void del_front(); int length(); int empty(); int full(); int capacity(); void resize(int sz); void clear(); int OK(); }; inline VQueue::VQueue(int sz) { s = new [size = sz]; cnt = inp = outp = 0; } inline VQueue::~VQueue() { delete [] s; } inline void VQueue::clear() { inp = outp = 0; cnt = 0; } inline int VQueue::empty() { return cnt <= 0; } inline int VQueue::capacity() { return size; } inline int VQueue::full() { return cnt >= size; } inline int VQueue::length() { return cnt; } inline void VQueue::enq( item) { if (cnt >= size) error("enq to full Queue."); ++cnt; s[inp] = item; if (++inp == size) inp = 0; } inline VQueue::deq() { if (cnt <= 0) error("deq from empty Queue."); --cnt; int i = outp; if (++outp == size) outp = 0; return s[i]; } inline void VQueue::del_front() { if (cnt <= 0) error("delete from empty Queue."); --cnt; if (++outp == size) outp = 0; } inline & VQueue::front() { if (empty()) error("top from empty Queue."); return s[outp]; } #endif ./g++-include/gen/VStack.hP100644 0 1 4733 5522102461 14011 0ustar rootdaemon// 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) 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. */ #ifndef _VStack_h #ifdef __GNUG__ #pragma interface #endif #define _VStack_h 1 #include ".Stack.h" class VStack : public Stack { protected: int size; int ptr; * s; public: VStack(int sz = DEFAULT_INITIAL_CAPACITY); VStack(VStack&); ~VStack(); void operator = (VStack&); void push( item); pop(); & top(); void del_top(); int length(); int empty(); int full(); void clear(); void resize(int sz); int capacity(); int OK(); }; inline VStack::VStack(int sz) { s = new [size = sz]; ptr = 0; } inline VStack::~VStack() { delete [] s; } inline void VStack::clear() { ptr = 0; } inline int VStack::capacity() { return size; } inline int VStack::empty() { return ptr == 0; } inline int VStack::full() { return ptr == size; } inline int VStack::length() { return ptr; } inline void VStack::push( item) { if (full()) error("push to full stack."); s[ptr++] = item; } inline VStack::pop() { if (empty()) error("pop from empty stack."); return s[--ptr]; } inline void VStack::del_top() { if (empty()) error("del_top from empty stack."); --ptr; } inline & VStack::top() { if (empty()) error("top from empty stack."); return s[ptr-1]; } #endif ./g++-include/gen/Vec.hP100644 0 1 6551 5522102462 13334 0ustar rootdaemon// 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) 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. */ #ifndef _Vec_h #ifdef __GNUG__ #pragma interface #endif #define _Vec_h 1 #include #include ".defs.h" #ifndef __typedefs #define __typedefs 1 typedef void (*Procedure)(); typedef (*Mapper)(); typedef (*Combiner)(, ); typedef int (*Predicate)(); typedef int (*Comparator)(, ); #endif class Vec { protected: int len; *s; Vec(int l, * d); public: Vec (); Vec (int l); Vec (int l, fill_value); Vec (Vec&); ~Vec (); Vec & operator = (Vec & a); Vec at(int from = 0, int n = -1); int capacity(); void resize(int newlen); & operator [] (int n); & elem(int n); friend Vec concat(Vec & a, Vec & b); friend Vec map(Mapper f, Vec & a); friend Vec merge(Vec & a, Vec & b, Comparator f); friend Vec combine(Combiner f, Vec & a, Vec & b); friend Vec reverse(Vec & a); void reverse(); void sort(Comparator f); void fill( val, int from = 0, int n = -1); void apply(Procedure f); reduce(Combiner f, base); int index( targ); friend int operator == (Vec& a, Vec& b); friend int operator != (Vec& a, Vec& b); void error(const char* msg); void range_error(); }; extern void default_Vec_error_handler(const char*); extern one_arg_error_handler_t Vec_error_handler; extern one_arg_error_handler_t set_Vec_error_handler(one_arg_error_handler_t f); inline Vec::Vec() { len = 0; s = 0; } inline Vec::Vec(int l) { s = new [len = l]; } inline Vec::Vec(int l, * d) :len(l), s(d) {} inline Vec::~Vec() { delete [] s; } inline & Vec::operator [] (int n) { if ((unsigned)n >= (unsigned)len) range_error(); return s[n]; } inline & Vec::elem(int n) { return s[n]; } inline int Vec::capacity() { return len; } inline int operator != (Vec& a, Vec& b) { return !(a == b); } #endif ./g++-include/gen/XPBag.hP100644 0 1 4275 5522102463 13562 0ustar rootdaemon// 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) 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. */ #ifndef _XPBag_h #ifdef __GNUG__ #pragma interface #endif #define _XPBag_h 1 #include ".Bag.h" #include ".XPlex.h" class XPBag : public Bag { protected: XPlex p; public: XPBag(int chunksize = DEFAULT_INITIAL_CAPACITY); XPBag(const XPBag&); Pix add( item); void del( item); #undef remove void remove(item); int nof( item); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); int owns(Pix i); Pix seek( item, Pix from = 0); int OK(); }; inline XPBag::XPBag(int chunksize) : p(chunksize) { count = 0; } inline XPBag::XPBag(const XPBag& s) : p(s.p) { count = s.count; } inline Pix XPBag::first() { return p.first(); } inline void XPBag::next(Pix & idx) { p.next(idx); } inline & XPBag::operator ()(Pix idx) { return p(idx); } inline void XPBag::clear() { count = 0; p.clear(); } inline int XPBag::owns (Pix idx) { return p.owns(idx); } inline Pix XPBag::add( item) { ++count; return p.index_to_Pix(p.add_high(item)); } inline int XPBag::contains( item) { return seek(item) != 0; } #endif ./g++-include/gen/XPDeque.hP100644 0 1 5223 5522102464 14127 0ustar rootdaemon// 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. */ #ifndef _XPDeque_h #ifdef __GNUG__ #pragma interface #endif #define _XPDeque_h #include ".XPlex.h" #include ".Deque.h" class XPDeque : public Deque { XPlex p; public: XPDeque(int chunksize = DEFAULT_INITIAL_CAPACITY); XPDeque(const XPDeque& d); ~XPDeque(); void operator = (const XPDeque&); void push( item); // insert at front void enq( item); // insert at rear & front(); & rear(); deq(); void del_front(); void del_rear(); void clear(); int empty(); int full(); int length(); int OK(); }; inline XPDeque::XPDeque(int chunksize) : p(chunksize) {} inline XPDeque::XPDeque(const XPDeque& d) : p(d.p) {} inline XPDeque::~XPDeque() {} inline void XPDeque::push(item) { p.add_low(item); } inline void XPDeque::enq(item) { p.add_high(item); } inline XPDeque::deq() { res = p.low_element(); p.del_low(); return res; } inline & XPDeque::front() { return p.low_element(); } inline & XPDeque::rear() { return p.high_element(); } inline void XPDeque::del_front() { p.del_low(); } inline void XPDeque::del_rear() { p.del_high(); } inline void XPDeque::operator =(const XPDeque& s) { p.operator = (s.p); } inline int XPDeque::empty() { return p.empty(); } inline int XPDeque::full() { return p.full(); } inline int XPDeque::length() { return p.length(); } inline int XPDeque::OK() { return p.OK(); } inline void XPDeque::clear() { p.clear(); } #endif ./g++-include/gen/XPPQ.hP100644 0 1 4365 5522102465 13413 0ustar rootdaemon// 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) 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. */ #ifndef _XPPQ_h #ifdef __GNUG__ #pragma interface #endif #define _XPPQ_h 1 #include ".PQ.h" #include ".XPlex.h" class XPPQ : public PQ { protected: XPlex p; public: XPPQ(int chunksize = DEFAULT_INITIAL_CAPACITY); XPPQ(const XPPQ&); Pix enq( item); deq(); & front(); void del_front(); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); void del(Pix i); int owns(Pix i); Pix seek( item); int OK(); // rep invariant }; inline XPPQ::XPPQ(int chunksize) : p(1, chunksize) { count = 0; } inline XPPQ::XPPQ(const XPPQ& s) : p(s.p) { count = s.count; } inline Pix XPPQ::first() { return p.first(); } inline void XPPQ::next(Pix & idx) { p.next(idx); } inline & XPPQ::operator ()(Pix idx) { return p(idx); } inline & XPPQ::front () { return p.low_element(); } inline XPPQ::deq () { x = p.low_element(); del_front(); return x; } inline void XPPQ::clear() { count = 0; p.clear(); } inline int XPPQ::contains ( item) { return seek(item) != 0; } inline int XPPQ::owns (Pix idx) { return p.owns(idx); } #endif ./g++-include/gen/XPQueue.hP100644 0 1 4534 5522102465 14155 0ustar rootdaemon// 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. */ #ifndef _XPQueue_h #ifdef __GNUG__ #pragma interface #endif #define _XPQueue_h #include ".XPlex.h" #include ".Queue.h" class XPQueue : public Queue { protected: XPlex p; public: XPQueue(int chunksize = DEFAULT_INITIAL_CAPACITY); XPQueue(const XPQueue& q); ~XPQueue(); void operator = (const XPQueue&); void enq( item); deq(); & front(); void del_front(); void clear(); int empty(); int full(); int length(); int OK(); }; inline XPQueue::XPQueue(int chunksize) : p(chunksize) {} inline XPQueue::XPQueue(const XPQueue& q) : p(q.p) {} inline XPQueue::~XPQueue() {} inline void XPQueue::enq(item) { p.add_high(item); } inline XPQueue::deq() { res = p.low_element(); p.del_low(); return res; } inline & XPQueue::front() { return p.low_element(); } inline void XPQueue::del_front() { p.del_low(); } inline void XPQueue::operator =(const XPQueue& s) { p.operator = (s.p); } inline int XPQueue::empty() { return p.empty(); } inline int XPQueue::full() { return p.full(); } inline int XPQueue::length() { return p.length(); } inline int XPQueue::OK() { return p.OK(); } inline void XPQueue::clear() { p.clear(); } #endif ./g++-include/gen/XPSet.hP100644 0 1 4001 5522102466 13612 0ustar rootdaemon// 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) 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. */ #ifndef _XPSet_h #ifdef __GNUG__ #pragma interface #endif #define _XPSet_h 1 #include ".Set.h" #include ".XPlex.h" class XPSet : public Set { protected: XPlex p; public: XPSet(int chunksize = DEFAULT_INITIAL_CAPACITY); XPSet(const XPSet&); Pix add( item); void del( item); int contains( item); void clear(); Pix first(); void next(Pix& i); & operator () (Pix i); int owns(Pix i); Pix seek( item); int OK(); }; inline XPSet::XPSet(int chunksize) : p(chunksize) { count = 0; } inline XPSet::XPSet(const XPSet& s) : p(s.p) { count = s.count; } inline Pix XPSet::first() { return p.first(); } inline void XPSet::next(Pix & idx) { p.next(idx); } inline & XPSet::operator ()(Pix idx) { return p(idx); } inline void XPSet::clear() { count = 0; p.clear(); } inline int XPSet::contains ( item) { return seek(item) != 0; } inline int XPSet::owns (Pix idx) { return p.owns(idx); } #endif ./g++-include/gen/XPStack.hP100644 0 1 4532 5522102467 14136 0ustar rootdaemon// 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. */ #ifndef _XPStack_h #ifdef __GNUG__ #pragma interface #endif #define _XPStack_h #include ".XPlex.h" #include ".Stack.h" class XPStack : public Stack { XPlex p; public: XPStack(int chunksize = DEFAULT_INITIAL_CAPACITY); XPStack(const XPStack& s); ~XPStack(); void operator = (const XPStack&); void push( item); pop(); & top(); void del_top(); int empty(); int full(); int length(); void clear(); int OK(); }; inline XPStack::XPStack(int chunksize) : p(chunksize) {} inline XPStack::XPStack(const XPStack& s) : p(s.p) {} inline XPStack::~XPStack() {} inline void XPStack::push(item) { p.add_high(item); } inline XPStack::pop() { res = p.high_element(); p.del_high(); return res; } inline & XPStack::top() { return p.high_element(); } inline void XPStack::del_top() { p.del_high(); } inline void XPStack::operator =(const XPStack& s) { p.operator = (s.p); } inline int XPStack::empty() { return p.empty(); } inline int XPStack::full() { return p.full(); } inline int XPStack::length() { return p.length(); } inline int XPStack::OK() { return p.OK(); } inline void XPStack::clear() { p.clear(); } #endif ./g++-include/gen/XPlex.hP100644 0 1 13617 5522102470 13677 0ustar rootdaemon// 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. */ #ifndef _XPlex_h #ifdef __GNUG__ #pragma interface #endif #define _XPlex_h 1 #include ".Plex.h" class XPlex: public Plex { IChunk* ch; // cached chunk void make_initial_chunks(int up = 1); void cache(int idx) const; void cache(const * p) const; * dopred(const * p) const; * dosucc(const * p) const; void set_cache(const IChunk* t) const; // logically, // not physically const public: XPlex(); // set low = 0; // fence = 0; // csize = default XPlex(int ch_size); // low = 0; // fence = 0; // csize = ch_size XPlex(int lo, // low = lo; int ch_size); // fence=lo // csize = ch_size XPlex(int lo, // low = lo int hi, // fence = hi+1 const initval,// fill with initval, int ch_size = 0); // csize= ch_size // or fence-lo if 0 XPlex(const XPlex&); void operator= (const XPlex&); // virtuals & high_element (); & low_element (); const & high_element () const; const & low_element () const; Pix first() const; Pix last() const; void prev(Pix& ptr) const; void next(Pix& ptr) const; int owns(Pix p) const; & operator () (Pix p); const & operator () (Pix p) const; int low() const; int high() const; int valid(int idx) const; void prev(int& idx) const; void next(int& x) const; & operator [] (int index); const & operator [] (int index) const; int Pix_to_index(Pix p) const; Pix index_to_Pix(int idx) const; int can_add_high() const; int can_add_low() const; int full() const; int add_high(const elem); int del_high (); int add_low (const elem); int del_low (); void fill(const x); void fill(const x, int from, int to); void clear(); void reverse(); int OK () const; }; inline void XPlex::prev(int& idx) const { --idx; } inline void XPlex::next(int& idx) const { ++idx; } inline int XPlex::full () const { return 0; } inline int XPlex::can_add_high() const { return 1; } inline int XPlex::can_add_low() const { return 1; } inline int XPlex::valid (int idx) const { return idx >= lo && idx < fnc; } inline int XPlex::low() const { return lo; } inline int XPlex::high() const { return fnc - 1; } inline & XPlex:: operator [] (int idx) { if (!ch->actual_index(idx)) cache(idx); return *(ch->pointer_to(idx)); } inline const & XPlex:: operator [] (int idx) const { if (!ch->actual_index(idx)) cache(idx); return *((const *)(ch->pointer_to(idx))); } inline & XPlex::low_element () { if (empty()) index_error(); return *(hd->pointer_to(lo)); } inline const & XPlex::low_element () const { if (empty()) index_error(); return *((const *)(hd->pointer_to(lo))); } inline & XPlex::high_element () { if (empty()) index_error(); return *(tl()->pointer_to(fnc - 1)); } inline const & XPlex::high_element () const { if (empty()) index_error(); return *((const *)(tl()->pointer_to(fnc - 1))); } inline int XPlex::Pix_to_index(Pix px) const { * p = (*)px; if (!ch->actual_pointer(p)) cache(p); return ch->index_of(p); } inline Pix XPlex::index_to_Pix(int idx) const { if (!ch->actual_index(idx)) cache(idx); return (Pix)(ch->pointer_to(idx)); } inline Pix XPlex::first() const { return Pix(hd->IChunk::first_pointer()); } inline Pix XPlex::last() const { return Pix(tl()->IChunk::last_pointer()); } inline void XPlex::prev(Pix& p) const { Pix q = Pix(ch->IChunk::pred((*) p)); p = (q == 0)? Pix(dopred((const *) p)) : q; } inline void XPlex::next(Pix& p) const { Pix q = Pix(ch->IChunk::succ((*) p)); p = (q == 0)? Pix(dosucc((const *)p)) : q; } inline & XPlex:: operator () (Pix p) { return *((*)p); } inline const & XPlex:: operator () (Pix p) const { return *((const *)p); } inline void XPlex::set_cache(const IChunk* t) const { ((XPlex*)(this))->ch = (IChunk*)t; } #endif ./g++-include/gen/defs.hP100644 0 1 3310 5522102471 13526 0ustar rootdaemon// 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) 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. */ #ifndef _defs_h #define _defs_h 1 // equality operator #ifndef EQ #define EQ(a, b) ((a) == (b)) #endif // less-than-or-equal #ifndef LE #define LE(a, b) ((a) <= (b)) #endif // comparison : less-than -> < 0; equal -> 0; greater-than -> > 0 #ifndef CMP #define CMP(a, b) ( ((a) <= (b))? (((a) == (b))? 0 : -1) : 1 ) #endif // hash function #ifndef HASH extern unsigned int hash(); #define HASH(x) hash(x) #endif // initial capacity for structures requiring one #ifndef DEFAULT_INITIAL_CAPACITY #define DEFAULT_INITIAL_CAPACITY 100 #endif // HASHTABLE_TOO_CROWDED(COUNT, SIZE) is true iff a hash table with COUNT // elements and SIZE slots is too full, and should be resized. // This is so if available space is less than 1/8. #define HASHTABLE_TOO_CROWDED(COUNT, SIZE) ((SIZE) - ((SIZE) >> 3) <= (COUNT)) #endif ./g++-include/gen/intSList.hP100644 0 1 2107 5522102472 14362 0ustar rootdaemon/* : Light weight List: This will simply reuse code from a int List, which was genclassed from the SLList libg++ class. The classes generated from this file will all be derived classes from class VoidSLList or intSLList. Note that class SLList does not offer all the functionality of List classes, such as sharing of sub-Lists. However, no additional code is needed at all and no .cc file is generated. So it costs nothing to use these type-safe Lists. Only member functions needing type casting are re-defined */ #ifndef _SList_h #define _SList_h 1 #include "int.SLList.h" #include ".defs.h" class SList : public intSLList { public: SList() {} SList(SList& a) : (a) {} ~SList() {} SList& operator = (SList& a) { return (SList&) intSLList::operator= (a); } & operator () (Pix p) { return (&) (intSLList::operator() (p)); } & front() { return (&) intSLList::front(); } & rear() { return (&) intSLList::rear(); } remove_front() { return () intSLList::remove_front(); } }; #endif /* conditional include */ ./g++-include/gen/intVec.hP100644 0 1 4732 5522102472 14047 0ustar rootdaemon/* : light weight Vector: This will simply reuse code from */ /* a int Vec, which was genclassed from the Vec libg++ class. */ /* The classes generated from this file will all be derived classes */ /* from class VoidVec or intVec. No .cc file is generated. So */ /* it costs nothing to use these type-safe Vectors. Only member */ /* functions needing type casting are re-defined. */ /* */ #ifndef _Vec_h #define _Vec_h 1 #include "int.Vec.h" #include ".defs.h" #ifndef __typedefs #define __typedefs 1 typedef void (*Procedure)( ); typedef (*Mapper)( ); typedef (*Combiner)( , ); typedef int (*Predicate)( ); typedef int (*Comparator)( , ); #endif class Vec : public intVec { protected: Vec(int l, * d) : (l, (int*) d) {}; public: Vec() {}; Vec(int l) : (l) {}; Vec(int l, fill_value) : (l, fill_value) {}; Vec(Vec& v) : (v) {}; Vec(intVec& v) {fake_copy(v, s, len);} ~Vec() {}; Vec& operator = (Vec& a) {return (Vec&) intVec::operator= (a);} Vec at(int from, int n) {return (Vec) intVec::at(from, n);} & operator [] (int n) {return (&)intVec::operator[] (n);} & elem(int n) {return (&)intVec::elem(n);} friend Vec concat(Vec& a, Vec& b); friend Vec map(Mapper f, Vec & a); friend Vec merge(Vec & a, Vec & b, Comparator f); friend Vec combine(Combiner f, Vec & a, Vec & b); friend Vec reverse(Vec& a); void sort(Comparator f); void apply(Procedure f); reduce(Combiner f, base); }; inline Vec concat(Vec& a, Vec& b) {return (Vec)concat((intVec&)a, (intVec&)b);} inline Vec map(Mapper f, Vec & a) { return (Vec)map((intMapper)f, (intVec&)a); } inline Vec merge(Vec & a, Vec & b, Comparator f) { return (Vec)merge((intVec&)a, (intVec&)b, (intComparator)f); } inline Vec combine(Combiner f, Vec & a, Vec & b) { return (Vec)combine((intCombiner)f, (intVec&)a, (intVec&)b); } inline Vec reverse(Vec& a) { return (Vec)reverse((intVec&)a);} inline void Vec::sort(Comparator f) { intVec::sort((intComparator) f); } inline void Vec::apply(Procedure f) { intVec::apply((intProcedure) f); } inline Vec::reduce(Combiner f, base) { return ()intVec::reduce((intCombiner)f, base);} #endif /* conditional include */ ./g++-include/PlotFile.h100644 0 1 6152 5522102224 13435 0ustar rootdaemon/* This is part of libio/iostream, providing -*- C++ -*- input/output. Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ /* a very simple implementation of a class to output unix "plot" format plotter files. See corresponding unix man pages for more details. written by Doug Lea (dl@rocky.oswego.edu) converted to use iostream library by Per Bothner (bothner@cygnus.com) */ #ifndef _PlotFile_h #ifdef __GNUG__ #pragma interface #endif #define _PlotFile_h #include /* Some plot libraries have the `box' command to draw boxes. Some don't. `box' is included here via moves & lines to allow both possiblilties. */ class PlotFile : public ofstream { protected: PlotFile& cmd(char c); PlotFile& operator << (const int x); PlotFile& operator << (const char *s); public: PlotFile() : ofstream() { } PlotFile(int fd) : ofstream(fd) { } PlotFile(const char *name, int mode=ios::out, int prot=0664) : ofstream(name, mode, prot) { } // PlotFile& remove() { ofstream::remove(); return *this; } // int filedesc() { return ofstream::filedesc(); } // const char* name() { return File::name(); } // void setname(const char* newname) { File::setname(newname); } // int iocount() { return File::iocount(); } PlotFile& arc(const int xi, const int yi, const int x0, const int y0, const int x1, const int y1); PlotFile& box(const int x0, const int y0, const int x1, const int y1); PlotFile& circle(const int x, const int y, const int r); PlotFile& cont(const int xi, const int yi); PlotFile& dot(const int xi, const int yi, const int dx, int n, const int* pat); PlotFile& erase(); PlotFile& label(const char* s); PlotFile& line(const int x0, const int y0, const int x1, const int y1); PlotFile& linemod(const char* s); PlotFile& move(const int xi, const int yi); PlotFile& point(const int xi, const int yi); PlotFile& space(const int x0, const int y0, const int x1, const int y1); }; #endif ./g++-include/SFile.h100644 0 1 3474 5522102224 12725 0ustar rootdaemon/* This is part of libio/iostream, providing -*- C++ -*- input/output. Copyright (C) 1988, 1992, 1993 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ #ifndef _SFile_h #ifdef __GNUG__ #pragma interface #endif #define _SFile_h 1 #include class SFile: public fstream { protected: int sz; // unit size for structured binary IO public: SFile() : fstream() { } SFile(int fd, int size); SFile(const char *name, int size, int mode, int prot=0664); void open(const char *name, int size, int mode, int prot=0664); int size() { return sz; } int setsize(int s) { int old = sz; sz = s; return old; } SFile& get(void* x); SFile& put(void* x); SFile& operator[](long i); }; #endif ./g++-include/CursesW.h100644 0 1 32614 5522114107 13337 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1989 Free Software Foundation written by Eric Newton (newton@rocky.oswego.edu) 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. */ #ifndef _CursesWindow_h #ifdef __GNUG__ #pragma interface #endif #define _CursesWindow_h #include <_G_config.h> #if _G_HAVE_CURSES #include /* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro. Undefine it here, because CursesWindow uses lines as a method. */ #undef lines // "Convert" macros to inlines, if needed. #ifdef addch inline int (addch)(char ch) { return addch(ch); } #undef addch #endif #ifdef addstr /* The (char*) cast is to hack around missing const's */ inline int (addstr)(const char * str) { return addstr((char*)str); } #undef addstr #endif #ifdef clear inline int (clear)() { return clear(); } #undef clear #endif #ifdef clearok inline int (clearok)(WINDOW* win, int bf) { return clearok(win, bf); } #undef clearok #else extern "C" int clearok(WINDOW*, int); #endif #ifdef clrtobot inline int (clrtobot)() { return clrtobot(); } #undef clrtobot #endif #ifdef clrtoeol inline int (clrtoeol)() { return clrtoeol(); } #undef clrtoeol #endif #ifdef delch inline int (delch)() { return delch(); } #undef delch #endif #ifdef deleteln inline int (deleteln)() { return deleteln(); } #undef deleteln #endif #ifdef erase inline int (erase)() { return erase(); } #undef erase #endif #ifdef flushok inline int (flushok)(WINDOW* _win, int _bf) { return flushok(_win, _bf); } #undef flushok #else #define _no_flushok #endif #ifdef getch inline int (getch)() { return getch(); } #undef getch #endif #ifdef getstr inline int (getstr)(char *_str) { return getstr(_str); } #undef getstr #endif #ifdef getyx inline void (getyx)(WINDOW* win, int& y, int& x) { getyx(win, y, x); } #undef getyx #endif #ifdef inch inline int (inch)() { return inch(); } #undef inch #endif #ifdef insch inline int (insch)(char c) { return insch(c); } #undef insch #endif #ifdef insertln inline int (insertln)() { return insertln(); } #undef insertln #endif #ifdef leaveok inline int (leaveok)(WINDOW* win, int bf) { return leaveok(win, bf); } #undef leaveok #else extern "C" int leaveok(WINDOW* win, int bf); #endif #ifdef move inline int (move)(int x, int y) { return move(x, y); } #undef move #endif #ifdef refresh inline int (rfresh)() { return refresh(); } #undef refresh #endif #ifdef scrollok inline int (scrollok)(WINDOW* win, int bf) { return scrollok(win, bf); } #undef scrollok #else #ifndef hpux extern "C" int scrollok(WINDOW*, int); #else extern "C" int scrollok(WINDOW*, char); #endif #endif #ifdef standend inline int (standend)() { return standend(); } #undef standend #endif #ifdef standout inline int (standout)() { return standout(); } #undef standout #endif #ifdef wstandend inline int (wstandend)(WINDOW *win) { return wstandend(win); } #undef wstandend #endif #ifdef wstandout inline int (wstandout)(WINDOW *win) { return wstandout(win); } #undef wstandout #endif #ifdef winch inline int (winch)(WINDOW* win) { return winch(win); } #undef winch #endif #ifdef mvwaddch inline int (mvwaddch)(WINDOW *win, int y, int x, char ch) { return mvwaddch(win, y, x, ch); } #undef mvwaddch #endif #ifdef mvwaddstr inline int (mvwaddstr)(WINDOW *win, int y, int x, const char * str) { return mvwaddstr(win, y, x, (char*)str); } #undef mvwaddstr #endif #ifdef mvwdelch inline int (mvwdelch)(WINDOW *win, int y, int x) { return mvwdelch(win, y, x);} #undef mvwdelch #endif #ifdef mvwgetch inline int (mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);} #undef mvwgetch #endif #ifdef mvwgetstr inline int (mvwgetstr)(WINDOW *win, int y, int x, char *str) {return mvwgetstr(win,y,x, str);} #undef mvwgetstr #endif #ifdef mvwinch inline int (mvwinch)(WINDOW *win, int y, int x) { return mvwinch(win, y, x);} #undef mvwinch #endif #ifdef mvwinsch inline int (mvwinsch)(WINDOW *win, int y, int x, char c) { return mvwinsch(win, y, x, c); } #undef mvwinsch #endif #ifdef mvaddch inline int (mvaddch)(int y, int x, char ch) { return mvaddch(y, x, ch); } #undef mvaddch #endif #ifdef mvaddstr inline int (mvaddstr)(int y, int x, const char * str) { return mvaddstr(y, x, (char*)str); } #undef mvaddstr #endif #ifdef mvdelch inline int (mvdelch)(int y, int x) { return mvdelch(y, x);} #undef mvdelch #endif #ifdef mvgetch inline int (mvgetch)(int y, int x) { return mvgetch(y, x);} #undef mvgetch #endif #ifdef mvgetstr inline int (mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);} #undef mvgetstr #endif #ifdef mvinch inline int (mvinch)(int y, int x) { return mvinch(y, x);} #undef mvinch #endif #ifdef mvinsch inline int (mvinsch)(int y, int x, char c) { return mvinsch(y, x, c); } #undef mvinsch #endif /* * * C++ class for windows. * * */ class CursesWindow { protected: static int count; // count of all active windows: // We rely on the c++ promise that // all otherwise uninitialized // static class vars are set to 0 WINDOW * w; // the curses WINDOW int alloced; // true if we own the WINDOW CursesWindow* par; // parent, if subwindow CursesWindow* subwins; // head of subwindows list CursesWindow* sib; // next subwindow of parent void kill_subwindows(); // disable all subwindows public: CursesWindow(WINDOW* &window); // useful only for stdscr CursesWindow(int lines, // number of lines int cols, // number of columns int begin_y, // line origin int begin_x); // col origin CursesWindow(CursesWindow& par, // parent window int lines, // number of lines int cols, // number of columns int by, // absolute or relative int bx, // origins: char absrel = 'a'); // if `a', by & bx are // absolute screen pos, // else if `r', they are // relative to par origin ~CursesWindow(); // terminal status int lines(); // number of lines on terminal, *not* window int cols(); // number of cols on terminal, *not* window // window status int height(); // number of lines in this window int width(); // number of cols in this window int begx(); // smallest x coord in window int begy(); // smallest y coord in window int maxx(); // largest x coord in window int maxy(); // largest x coord in window // window positioning int move(int y, int x); // coordinate positioning void getyx(int& y, int& x); int mvcur(int sy, int ey, int sx, int ex); // input int getch(); int getstr(char * str); int scanw(const char *, ...); // input + positioning int mvgetch(int y, int x); int mvgetstr(int y, int x, char * str); int mvscanw(int, int, const char*, ...); // output int addch(const char ch); int addstr(const char * str); int printw(const char * fmt, ...); int inch(); int insch(char c); int insertln(); // output + positioning int mvaddch(int y, int x, char ch); int mvaddstr(int y, int x, const char * str); int mvprintw(int y, int x, const char * fmt, ...); int mvinch(int y, int x); int mvinsch(int y, int x, char ch); // borders int box(char vert, char hor); // erasure int erase(); int clear(); int clearok(int bf); int clrtobot(); int clrtoeol(); int delch(); int mvdelch(int y, int x); int deleteln(); // screen control int scroll(); int scrollok(int bf); int touchwin(); int refresh(); int leaveok(int bf); #ifndef _no_flushok int flushok(int bf); #endif int standout(); int standend(); // multiple window control int overlay(CursesWindow &win); int overwrite(CursesWindow &win); // traversal support CursesWindow* child(); CursesWindow* sibling(); CursesWindow* parent(); }; inline int CursesWindow::begx() { return w->_begx; } inline int CursesWindow::begy() { return w->_begy; } inline int CursesWindow::maxx() { return w->_maxx; } inline int CursesWindow::maxy() { return w->_maxy; } inline int CursesWindow::height() { return maxy() - begy() + 1; } inline int CursesWindow::width() { return maxx() - begx() + 1; } inline int CursesWindow::box(char vert, char hor) { return ::box(w, vert, hor); } inline int CursesWindow::overlay(CursesWindow &win) { return ::overlay(w, win.w); } inline int CursesWindow::overwrite(CursesWindow &win) { return ::overwrite(w, win.w); } inline int CursesWindow::scroll() { return ::scroll(w); } inline int CursesWindow::touchwin() { return ::touchwin(w); } inline int CursesWindow::addch(const char ch) { return ::waddch(w, ch); } inline int CursesWindow::addstr(const char * str) { // The (char*) cast is to hack around prototypes in curses.h that // have const missing in the parameter lists. [E.g. SVR4] return ::waddstr(w, (char*)str); } inline int CursesWindow::clear() { return ::wclear(w); } inline int CursesWindow::clrtobot() { return ::wclrtobot(w); } inline int CursesWindow::clrtoeol() { return ::wclrtoeol(w); } inline int CursesWindow::delch() { return ::wdelch(w); } inline int CursesWindow::deleteln() { return ::wdeleteln(w); } inline int CursesWindow::erase() { return ::werase(w); } inline int CursesWindow::getch() { return ::wgetch(w); } inline int CursesWindow::getstr(char * str) { return ::wgetstr(w, str); } inline int CursesWindow::inch() { return winch(w); } inline int CursesWindow::insch(char c) { return ::winsch(w, c); } inline int CursesWindow::insertln() { return ::winsertln(w); } inline int CursesWindow::move(int y, int x) { return ::wmove(w, y, x); } inline int CursesWindow::mvcur(int sy, int ey, int sx, int ex) { return ::mvcur(sy, ey, sx,ex); } inline int CursesWindow::mvaddch(int y, int x, char ch) { return (::wmove(w, y, x)==ERR) ? ERR : ::waddch(w, ch); } inline int CursesWindow::mvgetch(int y, int x) { return (::wmove(w, y, x)==ERR) ? ERR : ::wgetch(w); } inline int CursesWindow::mvaddstr(int y, int x, const char * str) { return (::wmove(w, y, x)==ERR) ? ERR : ::waddstr(w, (char*)str); } inline int CursesWindow::mvgetstr(int y, int x, char * str) { return (::wmove(w, y, x)==ERR) ? ERR : ::wgetstr(w, str); } inline int CursesWindow::mvinch(int y, int x) { return (::wmove(w, y, x)==ERR) ? ERR : ::winch(w); } inline int CursesWindow::mvdelch(int y, int x) { return (::wmove(w, y, x)==ERR) ? ERR : ::wdelch(w); } inline int CursesWindow::mvinsch(int y, int x, char ch) { return (::wmove(w, y, x)==ERR) ? ERR : ::winsch(w, ch); } inline int CursesWindow::refresh() { return ::wrefresh(w); } inline int CursesWindow::clearok(int bf) { return ::clearok(w,bf); } inline int CursesWindow::leaveok(int bf) { return ::leaveok(w,bf); } inline int CursesWindow::scrollok(int bf) { return ::scrollok(w,bf); } #ifndef _no_flushok inline int CursesWindow::flushok(int bf) { return ::flushok(w, bf); } #endif inline void CursesWindow::getyx(int& y, int& x) { ::getyx(w, y, x); } inline int CursesWindow::standout() { return ::wstandout(w); } inline int CursesWindow::standend() { return ::wstandend(w); } inline int CursesWindow::lines() { return LINES; } inline int CursesWindow::cols() { return COLS; } inline CursesWindow* CursesWindow::child() { return subwins; } inline CursesWindow* CursesWindow::parent() { return par; } inline CursesWindow* CursesWindow::sibling() { return sib; } #endif /* _G_HAVE_CURSES */ #endif ./g++-include/builtinbuf.h100644 0 1 4335 5522102226 14065 0ustar rootdaemon/* Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ #ifndef _BUILTINBUF_H #define _BUILTINBUF_H #ifdef __GNUC__ #pragma interface #endif #include // A builtinbuf a a streambuf where all the virtual operations // call the _IO_jump_t table. class builtinbuf : public streambuf { friend ios; virtual int overflow(int); virtual int underflow(); virtual streamsize xsgetn(char *, streamsize); virtual streamsize xsputn(const char *, streamsize); virtual streambuf* setbuf(char*, int); virtual int doallocate(); virtual ~builtinbuf(); virtual int sync(); virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out); virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out); virtual int pbackfail(int c); virtual streamsize sys_read(char* buf, streamsize size); virtual streampos sys_seek(streamoff, _seek_dir); virtual streamsize sys_write(const char*, streamsize); virtual int sys_stat(void*); // Actually, a (struct stat*) virtual int sys_close(); #if 0 virtual int get_column(); virtual int set_column(int); #endif friend const void *get_builtin_vtable(); static const void *vtable; private: builtinbuf() { } }; #endif _BUILTINBUF_H ./g++-include/editbuf.h100644 0 1 15257 5522102227 13372 0ustar rootdaemon/* This is part of libio/iostream, providing -*- C++ -*- input/output. Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. Written by Per Bothner (bothner@cygnus.com). */ #ifndef _EDITBUF_H #define _EDITBUF_H #ifdef __GNUG__ #pragma interface #endif #include #include typedef unsigned long mark_pointer; // At some point, it might be nice to parameterize this code // in terms of buf_char. typedef /*unsigned*/ char buf_char; // Logical pos from start of buffer (does not count gap). typedef long buf_index; // Pos from start of buffer, possibly including gap_size. typedef long buf_offset; #if 0 struct buf_cookie { FILE *file; struct edit_string *str; struct buf_cookie *next; buf_index tell(); }; #endif struct edit_buffer; struct edit_mark; // A edit_string is defined as the region between the 'start' and 'end' marks. // Normally (always?) 'start->insert_before()' should be false, // and 'end->insert_before()' should be true. struct edit_string { struct edit_buffer *buffer; // buffer that 'start' and 'end' belong to struct edit_mark *start, *end; int length() const; // count of buf_chars currently in string edit_string(struct edit_buffer *b, struct edit_mark *ms, struct edit_mark *me) { buffer = b; start = ms; end = me; } /* Make a fresh, contiguous copy of the data in STR. Assign length of STR to *LENP. (Output has extra NUL at out[*LENP].) */ buf_char *copy_bytes(int *lenp) const; // FILE *open_file(char *mode); void assign(struct edit_string *src); // copy bytes from src to this }; struct edit_streambuf : public streambuf { friend edit_buffer; edit_string *str; edit_streambuf* next; // Chain of edit_streambuf's for a edit_buffer. short _mode; edit_streambuf(edit_string* bstr, int mode); ~edit_streambuf(); virtual int underflow(); virtual int overflow(int c = EOF); virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out); void flush_to_buffer(); void flush_to_buffer(edit_buffer* buffer); int _inserting; int inserting() { return _inserting; } void inserting(int i) { _inserting = i; } // int delete_chars(int count, char* cut_buf); Not implemented. int truncate(); int is_reading() { return gptr() != NULL; } buf_char* current() { return is_reading() ? gptr() : pptr(); } void set_current(char *p, int is_reading); protected: void disconnect_gap_from_file(edit_buffer* buffer); }; // A 'edit_mark' indicates a position in a buffer. // It is "attached" the text (rather than the offset). // There are two kinds of mark, which have different behavior // when text is inserted at the mark: // If 'insert_before()' is true the mark will be adjusted to be // *after* the new text. struct edit_mark { struct edit_mark *chain; mark_pointer _pos; inline int insert_before() { return _pos & 1; } inline unsigned long index_in_buffer(struct edit_buffer *buffer) { return _pos >> 1; } inline buf_char *ptr(struct edit_buffer *buf); buf_index tell(); edit_mark() { } edit_mark(struct edit_string *str, long delta); edit_buffer *buffer(); ~edit_mark(); }; // A 'edit_buffer' consists of a sequence of buf_chars (the data), // a list of edit_marks pointing into the data, and a list of FILEs // also pointing into the data. // A 'edit_buffer' coerced to a edit_string is the string of // all the buf_chars in the buffer. // This implementation uses a conventional buffer gap (as in Emacs). // The gap start is defined by de-referencing a (buf_char**). // This is because sometimes a FILE is inserting into the buffer, // so rather than having each putc adjust the gap, we use indirection // to have the gap be defined as the write pointer of the FILE. // (This assumes that putc adjusts a pointer (as in GNU's libc), not an index.) struct edit_buffer { buf_char *data; /* == emacs buffer_text.p1+1 */ buf_char *_gap_start; edit_streambuf* _writer; // If non-NULL, currently writing stream inline buf_char *gap_start() { return _writer ? _writer->pptr() : _gap_start; } buf_offset __gap_end_pos; // size of part 1 + size of gap /* int gap; implicit: buf_size - size1 - size2 */ int buf_size; struct edit_streambuf *files; struct edit_mark start_mark; struct edit_mark end_mark; edit_buffer(); inline buf_offset gap_end_pos() { return __gap_end_pos; } inline struct edit_mark *start_marker() { return &start_mark; } inline struct edit_mark *end_marker() { return &end_mark; } /* these should be protected, ultimately */ buf_index tell(edit_mark*); buf_index tell(buf_char*); inline buf_char *gap_end() { return data + gap_end_pos(); } inline int gap_size() { return gap_end() - gap_start(); } inline int size1() { return gap_start() - data; } inline int size2() { return buf_size - gap_end_pos(); } inline struct edit_mark * mark_list() { return &start_mark; } void make_gap (buf_offset); void move_gap (buf_offset pos); void move_gap (buf_char *pos) { move_gap(pos - data); } void gap_left (int pos); void gap_right (int pos); void adjust_markers(mark_pointer low, mark_pointer high, int amount, buf_char *old_data); void delete_range(buf_index from, buf_index to); void delete_range(struct edit_mark *start, struct edit_mark *end); }; extern buf_char * bstr_copy(struct edit_string *str, int *lenp); // Convert a edit_mark to a (buf_char*) inline buf_char *edit_mark::ptr(struct edit_buffer *buf) { return buf->data + index_in_buffer(buf); } inline void edit_streambuf::flush_to_buffer() { edit_buffer* buffer = str->buffer; if (buffer->_writer == this) flush_to_buffer(buffer); } #endif /* !_EDITBUF_H*/ ./g++-include/fstream.h100644 0 1 6170 5522102230 13355 0ustar rootdaemon/* This is part of libio/iostream, providing -*- C++ -*- input/output. Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ #ifndef _FSTREAM_H #define _FSTREAM_H #ifdef __GNUG__ #pragma interface #endif #include class fstreambase : virtual public ios { public: fstreambase(); fstreambase(int fd); fstreambase(int fd, char *p, int l); /* Deprecated */ fstreambase(const char *name, int mode, int prot=0664); void close(); filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); } void open(const char *name, int mode, int prot=0664); int is_open() const { return rdbuf()->is_open(); } void setbuf(char *ptr, int len) { rdbuf()->setbuf(ptr, len); } #ifdef _STREAM_COMPAT int filedesc() { return rdbuf()->fd(); } fstreambase& raw() { rdbuf()->setbuf(NULL, 0); return *this; } #endif }; class ifstream : public fstreambase, public istream { public: ifstream() : fstreambase() { } ifstream(int fd) : fstreambase(fd) { } ifstream(int fd, char *p, int l) : fstreambase(fd, p, l) { } /*Deprecated*/ ifstream(const char *name, int mode=ios::in, int prot=0664) : fstreambase(name, mode, prot) { } void open(const char *name, int mode=ios::in, int prot=0664) { fstreambase::open(name, mode, prot); } }; class ofstream : public fstreambase, public ostream { public: ofstream() : fstreambase() { } ofstream(int fd) : fstreambase(fd) { } ofstream(int fd, char *p, int l) : fstreambase(fd, p, l) { } /*Deprecated*/ ofstream(const char *name, int mode=ios::out, int prot=0664) : fstreambase(name, mode, prot) { } void open(const char *name, int mode=ios::out, int prot=0664) { fstreambase::open(name, mode, prot); } }; class fstream : public fstreambase, public iostream { public: fstream() : fstreambase() { } fstream(int fd) : fstreambase(fd) { } fstream(const char *name, int mode, int prot=0664) : fstreambase(name, mode, prot) { } fstream(int fd, char *p, int l) : fstreambase(fd, p, l) { } /*Deprecated*/ void open(const char *name, int mode, int prot=0664) { fstreambase::open(name, mode, prot); } }; #endif /*!_FSTREAM_H*/ ./g++-include/indstream.h100644 0 1 5377 5522102231 13713 0ustar rootdaemon/* This is part of libio/iostream, providing -*- C++ -*- input/output. Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. Written by Per Bothner (bothner@cygnus.com). */ #ifndef _INDSTREAM_H #define _INDSTREAM_H #ifdef __GNUG__ #pragma interface #endif #include // An indirectbuf is one that forwards all of its I/O requests // to another streambuf. // All get-related requests are sent to get_stream(). // All put-related requests are sent to put_stream(). // An indirectbuf can be used to implement Common Lisp // synonym-streams and two-way-streams. // // class synonymbuf : public indirectbuf { // Symbol *sym; // synonymbuf(Symbol *s) { sym = s; } // virtual streambuf *lookup_stream(int mode) { // return coerce_to_streambuf(lookup_value(sym)); } // }; class indirectbuf : public streambuf { protected: streambuf *_get_stream; // Optional cache for get_stream(). streambuf *_put_stream; // Optional cache for put_stream(). int _delete_flags; public: streambuf *get_stream() { return _get_stream ? _get_stream : lookup_stream(ios::in); } streambuf *put_stream() { return _put_stream ? _put_stream : lookup_stream(ios::out); } virtual streambuf *lookup_stream(int/*mode*/) { return NULL; } // ERROR! indirectbuf(streambuf *get=NULL, streambuf *put=NULL, int delete_mode=0); virtual ~indirectbuf(); virtual int xsputn(const char* s, int n); virtual int xsgetn(char* s, int n); virtual int underflow(); virtual int overflow(int c = EOF); virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out); virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out); virtual int sync(); virtual int pbackfail(int c); }; #endif /* !_INDSTREAM_H */ ./g++-include/iomanip.h100644 0 1 11275 5522102233 13375 0ustar rootdaemon/* This is part of libio/iostream, providing -*- C++ -*- input/output. Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ #ifndef _IOMANIP_H // // Not specifying `pragma interface' causes the compiler to emit the // template definitions in the files, where they are used. // //#ifdef __GNUG__ //#pragma interface //#endif #define _IOMANIP_H #include //----------------------------------------------------------------------------- // Parametrized Manipulators as specified by ANSI draft //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // Stream Manipulators //----------------------------------------------------------------------------- // template class smanip; // TP = Type Param template class sapp { ios& (*_f)(ios&, TP); public: sapp(ios& (*f)(ios&, TP)) : _f(f) {} // smanip operator()(TP a) { return smanip(_f, a); } }; template class smanip { ios& (*_f)(ios&, TP); TP _a; public: smanip(ios& (*f)(ios&, TP), TP a) : _f(f), _a(a) {} // friend istream& operator>>(istream& i, const smanip& m); friend ostream& operator<<(ostream& o, const smanip& m); }; template inline istream& operator>>(istream& i, const smanip& m) { (*m._f)(i, m._a); return i; } template inline ostream& operator<<(ostream& o, const smanip& m) { (*m._f)(o, m._a); return o;} //----------------------------------------------------------------------------- // Input-Stream Manipulators //----------------------------------------------------------------------------- // template class imanip; template class iapp { istream& (*_f)(istream&, TP); public: iapp(istream& (*f)(istream&,TP)) : _f(f) {} // imanip operator()(TP a) { return imanip(_f, a); } }; template class imanip { istream& (*_f)(istream&, TP); TP _a; public: imanip(istream& (*f)(istream&, TP), TP a) : _f(f), _a(a) {} // friend istream& operator>>(istream& i, const imanip& m) { return (*m._f)( i, m._a); } }; //----------------------------------------------------------------------------- // Output-Stream Manipulators //----------------------------------------------------------------------------- // template class omanip; template class oapp { ostream& (*_f)(ostream&, TP); public: oapp(ostream& (*f)(ostream&,TP)) : _f(f) {} // omanip operator()(TP a) { return omanip(_f, a); } }; template class omanip { ostream& (*_f)(ostream&, TP); TP _a; public: omanip(ostream& (*f)(ostream&, TP), TP a) : _f(f), _a(a) {} // friend ostream& operator<<(ostream& o, omanip& m) { return (*m._f)(o, m._a); } }; //----------------------------------------------------------------------------- // Available Manipulators //----------------------------------------------------------------------------- // // Macro to define an iomanip function, with one argument // The underlying function is `__iomanip_' // #define __DEFINE_IOMANIP_FN1(type,param,function) \ extern ios& __iomanip_##function (ios&, param); \ inline type function (param n) \ { return type (__iomanip_##function, n); } __DEFINE_IOMANIP_FN1( smanip, int, setbase) __DEFINE_IOMANIP_FN1( smanip, int, setfill) __DEFINE_IOMANIP_FN1( smanip, int, setprecision) __DEFINE_IOMANIP_FN1( smanip, int, setw) __DEFINE_IOMANIP_FN1( smanip, ios::fmtflags, resetiosflags) __DEFINE_IOMANIP_FN1( smanip, ios::fmtflags, setiosflags) #endif /*!_IOMANIP_H*/ ./g++-include/iostream.h100644 0 1 20017 5522102234 13557 0ustar rootdaemon/* This is part of libio/iostream, providing -*- C++ -*- input/output. Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ #ifndef _IOSTREAM_H #ifdef __GNUG__ #pragma interface #endif #define _IOSTREAM_H #include class istream; class ostream; typedef ios& (*__manip)(ios&); typedef istream& (*__imanip)(istream&); typedef ostream& (*__omanip)(ostream&); extern istream& ws(istream& ins); extern ostream& flush(ostream& outs); extern ostream& endl(ostream& outs); extern ostream& ends(ostream& outs); class ostream : virtual public ios { // NOTE: If fields are changed, you must fix _fake_ostream in stdstreams.C! void do_osfx(); public: ostream() { } ostream(streambuf* sb, ostream* tied=NULL); int opfx() { if (!good()) return 0; else { if (_tie) _tie->flush(); return 1;} } void osfx() { if (flags() & (ios::unitbuf|ios::stdio)) do_osfx(); } ostream& flush(); ostream& put(char c) { _strbuf->sputc(c); return *this; } ostream& put(unsigned char c) { return put((char)c); } ostream& write(const char *s, int n); ostream& write(const unsigned char *s, int n) { return write((const char*)s, n);} ostream& put(signed char c) { return put((char)c); } ostream& write(const signed char *s, int n) { return write((const char*)s, n);} ostream& write(const void *s, int n) { return write((const char*)s, n);} ostream& seekp(streampos); ostream& seekp(streamoff, _seek_dir); streampos tellp(); ostream& form(const char *format ...); ostream& vform(const char *format, _IO_va_list args); ostream& operator<<(char c); ostream& operator<<(unsigned char c) { return (*this) << (char)c; } ostream& operator<<(signed char c) { return (*this) << (char)c; } ostream& operator<<(const char *s); ostream& operator<<(const unsigned char *s) { return (*this) << (const char*)s; } ostream& operator<<(const signed char *s) { return (*this) << (const char*)s; } ostream& operator<<(const void *p); ostream& operator<<(int n); ostream& operator<<(unsigned int n); ostream& operator<<(long n); ostream& operator<<(unsigned long n); #if defined(__GNUC__) && !defined(__STRICT_ANSI__) ostream& operator<<(long long n); ostream& operator<<(unsigned long long n); #endif ostream& operator<<(short n) {return operator<<((int)n);} ostream& operator<<(unsigned short n) {return operator<<((unsigned int)n);} ostream& operator<<(double n); ostream& operator<<(float n) { return operator<<((double)n); } ostream& operator<<(__omanip func) { return (*func)(*this); } ostream& operator<<(__manip func) {(*func)(*this); return *this;} ostream& operator<<(streambuf*); #ifdef _STREAM_COMPAT streambuf* ostreambuf() const { return _strbuf; } #endif }; class istream : virtual public ios { // NOTE: If fields are changed, you must fix _fake_istream in stdstreams.C! _IO_size_t _gcount; int _skip_ws(); public: istream() { _gcount = 0; } istream(streambuf* sb, ostream*tied=NULL); istream& get(char* ptr, int len, char delim = '\n'); istream& get(unsigned char* ptr, int len, char delim = '\n') { return get((char*)ptr, len, delim); } istream& get(char& c); istream& get(unsigned char& c) { return get((char&)c); } istream& getline(char* ptr, int len, char delim = '\n'); istream& getline(unsigned char* ptr, int len, char delim = '\n') { return getline((char*)ptr, len, delim); } istream& get(signed char& c) { return get((char&)c); } istream& get(signed char* ptr, int len, char delim = '\n') { return get((char*)ptr, len, delim); } istream& getline(signed char* ptr, int len, char delim = '\n') { return getline((char*)ptr, len, delim); } istream& read(char *ptr, int n); istream& read(unsigned char *ptr, int n) { return read((char*)ptr, n); } istream& read(signed char *ptr, int n) { return read((char*)ptr, n); } istream& read(void *ptr, int n) { return read((char*)ptr, n); } istream& get(streambuf& sb, char delim = '\n'); istream& gets(char **s, char delim = '\n'); int ipfx(int need) { if (!good()) { set(ios::failbit); return 0; } else { if (_tie && (need == 0 || rdbuf()->in_avail() < need)) _tie->flush(); if (!need && (flags() & ios::skipws)) return _skip_ws(); else return 1; } } int ipfx0() { // Optimized version of ipfx(0). if (!good()) { set(ios::failbit); return 0; } else { if (_tie) _tie->flush(); if (flags() & ios::skipws) return _skip_ws(); else return 1; } } int ipfx1() { // Optimized version of ipfx(1). if (!good()) { set(ios::failbit); return 0; } else { if (_tie && rdbuf()->in_avail() == 0) _tie->flush(); return 1; } } void isfx() { } int get() { if (!ipfx1()) return EOF; else { int ch = _strbuf->sbumpc(); if (ch == EOF) set(ios::eofbit); return ch; } } int peek(); _IO_size_t gcount() { return _gcount; } istream& ignore(int n=1, int delim = EOF); istream& seekg(streampos); istream& seekg(streamoff, _seek_dir); streampos tellg(); istream& putback(char ch) { if (good() && _strbuf->sputbackc(ch) == EOF) clear(ios::badbit); return *this;} istream& unget() { if (good() && _strbuf->sungetc() == EOF) clear(ios::badbit); return *this;} istream& scan(const char *format ...); istream& vscan(const char *format, _IO_va_list args); #ifdef _STREAM_COMPAT istream& unget(char ch) { return putback(ch); } int skip(int i); streambuf* istreambuf() const { return _strbuf; } #endif istream& operator>>(char*); istream& operator>>(unsigned char* p) { return operator>>((char*)p); } istream& operator>>(signed char*p) { return operator>>((char*)p); } istream& operator>>(char& c); istream& operator>>(unsigned char& c) {return operator>>((char&)c);} istream& operator>>(signed char& c) {return operator>>((char&)c);} istream& operator>>(int&); istream& operator>>(long&); #if defined(__GNUC__) && !defined(__STRICT_ANSI__) istream& operator>>(long long&); istream& operator>>(unsigned long long&); #endif istream& operator>>(short&); istream& operator>>(unsigned int&); istream& operator>>(unsigned long&); istream& operator>>(unsigned short&); istream& operator>>(float&); istream& operator>>(double&); istream& operator>>( __manip func) {(*func)(*this); return *this;} istream& operator>>(__imanip func) { return (*func)(*this); } istream& operator>>(streambuf*); }; class iostream : public istream, public ostream { _IO_size_t _gcount; public: iostream() { _gcount = 0; } iostream(streambuf* sb, ostream*tied=NULL); }; extern istream cin; extern ostream cout, cerr, clog; // clog->rdbuf() == cerr->rdbuf() struct Iostream_init { } ; // Compatibility hack for AT&T library. inline ios& dec(ios& i) { i.setf(ios::dec, ios::dec|ios::hex|ios::oct); return i; } inline ios& hex(ios& i) { i.setf(ios::hex, ios::dec|ios::hex|ios::oct); return i; } inline ios& oct(ios& i) { i.setf(ios::oct, ios::dec|ios::hex|ios::oct); return i; } #endif /*!_IOSTREAM_H*/ ./g++-include/iostreamP.h100644 0 1 2515 5522102235 13663 0ustar rootdaemon/* Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ #include "streambuf.h" #include "libioP.h" inline _IO_seekflags convert_to_seekflags(int dir, int mode) { return (_IO_seekflags)((int)dir | (mode & ios::in ? _IO_seek_set : _IO_seek_not_in) | (mode & ios::out ? _IO_seek_set : _IO_seek_not_out)); } ./g++-include/istream.h100644 0 1 2136 5522102236 13364 0ustar rootdaemon/* Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ #include ./g++-include/ostream.h100644 0 1 2136 5522102241 13366 0ustar rootdaemon/* Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ #include ./g++-include/parsestream.h100644 0 1 12376 5522102241 14271 0ustar rootdaemon/* This is part of libio/iostream, providing -*- C++ -*- input/output. Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. Written by Per Bothner (bothner@cygnus.com). */ #ifndef PARSESTREAM_H #define PARSESTREAM_H #ifdef __GNUG__ #pragma interface #endif #include "streambuf.h" // A parsebuf is a streambuf optimized for scanning text files. // It keeps track of line and column numbers. // It is guaranteed to remember the entire current line, // as well the '\n'-s on either side of it (if they exist). // You can arbitrarily seek (or unget) within this extended line. // Other backward seeks are not supported. // Normal read semantics are supported (and hence istream operators like >>). class parsebuf : public streambuf { protected: _IO_fpos_t pos_at_line_start; long _line_length; unsigned long __line_number; char *buf_start; char *buf_end; public: parsebuf *chain; // Return column number (raw - don't handle tabs etc). // Retult can be -1, meaning: at '\n' before current line. virtual int tell_in_line(); // seek to (raw) column I in current line. // Result is new (raw) column position - differs from I if unable to seek. // Seek to -1 tries to seek to before previous LF. virtual int seek_in_line(int i); // Note: there is no "current line" initially, until something is read. // Current line number, starting with 0. // If tell_in_line()==-1, then line number of next line. int line_number() { return __line_number; } // Length of current line, not counting either '\n'. int line_length() { return _line_length; } // Current line - not a copy, so file ops may trash it. virtual char* current_line(); virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out); virtual streambuf* setbuf(char* p, int len); protected: parsebuf() { chain= NULL; __line_number = 0; pos_at_line_start = 0; _line_length = -1; } virtual int pbackfail(int c); }; // A string_parsebuf is a parsebuf whose source is a fixed string. class string_parsebuf : public parsebuf { public: int do_delete; string_parsebuf(char *str, int len, int delete_at_close=0); virtual int underflow(); virtual char* current_line(); virtual int seek_in_line(int i); virtual int tell_in_line(); char *left() const { return base(); } char *right() const { return ebuf(); } // streampos seekoff(streamoff, _seek_dir, int); }; // A func_parsebuf calls a given function to get new input. // Each call returns an entire NUL-terminated line (without the '\n'). // That line has been allocated with malloc(), not new. // The interface is tailored to the GNU readline library. // Example: // char* DoReadLine(void* arg) // { // char *line = readline((char*)arg); /* 'arg' is used as prompt. */ // if line == NULL) { putc('\n', stderr); return NULL; } // if (line[0] != '\0') add_history(line); // return line; // } // char PromptBuffer[100] = "> "; // func_parsebuf my_stream(DoReadLine, PromptBuffer); typedef char *(*CharReader)(void *arg); class istream; class func_parsebuf : public parsebuf { public: void *arg; CharReader read_func; int backed_up_to_newline; func_parsebuf(CharReader func, void *argm = NULL); int underflow(); virtual int tell_in_line(); virtual int seek_in_line(int i); virtual char* current_line(); }; // A general_parsebuf is a parsebuf which gets its input from some // other streambuf. It explicitly buffers up an entire line. class general_parsebuf : public parsebuf { public: streambuf *sbuf; int delete_buf; // Delete sbuf when destroying this. general_parsebuf(streambuf *buf, int delete_arg_buf = 0); int underflow(); virtual int tell_in_line(); virtual int seek_in_line(int i); ~general_parsebuf(); virtual char* current_line(); }; #if 0 class parsestream : public istream { streammarker marks[2]; short _first; // of the two marks; either 0 or 1 int _lineno; int first() { return _first; } int second() { return 1-_first; } int line_length() { marks[second].delta(marks[first]); } int line_length() { marks[second].delta(marks[first]); } int seek_in_line(int i); int tell_in_line(); int line_number(); }; #endif #endif /*!defined(PARSESTREAM_H)*/ ./g++-include/pfstream.h100644 0 1 4272 5522102242 13541 0ustar rootdaemon/* This is part of libio/iostream, providing -*- C++ -*- input/output. Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ /* Written by Per Bothner (bothner@cygnus.com). */ #ifndef _PFSTREAM_H #define _PFSTREAM_H #ifdef __GNUG__ #pragma interface #endif #include // ipfstream foo("NAME") is like: ifstream foo("NAME"). However, // if NAME starts *or ends* with a '|', the remainder of NAME is // evaluated as a shell command (using a procbuf), and all input // read from foo is whatever that shell writes to its standard output. // E.g. ipfstream foo("|zcat foo.Z") or ipfstream foo("zcat foo.Z|") // (These two forms are equivalent.) class ipfstream : public ifstream { public: ipfstream(const char *name, int mode=ios::in, int prot=0664); }; // opfstream foo("NAME") is like: ofstream foo("NAME"). // However, if NAME starts with a '|', the remainder of NAME is // evaluated as a shell command (using a procbuf), and all output // written to foo is piped to the standard input of that shell. // E.g. opfstream foo("|more"); class opfstream : public ofstream { public: opfstream(const char *name, int mode=ios::out, int prot=0664); }; #endif /*!_PFSTREAM_H*/ ./g++-include/procbuf.h100644 0 1 3145 5522102243 13357 0ustar rootdaemon/* This is part of libio/iostream, providing -*- C++ -*- input/output. Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ /* Written by Per Bothner (bothner@cygnus.com). */ #include class procbuf : public filebuf { /* Following fields must match those in struct _IO_proc_file */ _IO_pid_t _pid; struct _IO_proc_file *_next; public: procbuf() : filebuf() { } procbuf(const char *command, int mode); procbuf* open(const char *command, int mode); procbuf *close() { return (procbuf*)filebuf::close(); } virtual int sys_close(); ~procbuf(); }; ./g++-include/stdiostream.h100644 0 1 3461 5522102244 14257 0ustar rootdaemon/* This is part of libio/iostream, providing -*- C++ -*- input/output. Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ /* Written by Per Bothner (bothner@cygnus.com). */ #ifndef _STDIOSTREAM_H #define _STDIOSTREAM_H #ifdef __GNUG__ #pragma interface #endif #include #include class stdiobuf : public filebuf { protected: FILE *_file; public: FILE* stdiofile() const { return _file; } stdiobuf(FILE *f); virtual _IO_ssize_t sys_read(char* buf, _IO_size_t size); virtual _IO_fpos_t sys_seek(_IO_fpos_t, _seek_dir); virtual _IO_ssize_t sys_write(const void*, _IO_size_t); virtual int sys_close(); virtual int sync(); virtual int overflow(int c = EOF); virtual int xsputn(const char* s, int n); }; #endif /* !_STDIOSTREAM_H */ ./g++-include/stream.h100644 0 1 3514 5522102245 13214 0ustar rootdaemon/* Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ #ifndef _COMPAT_STREAM_H #define _COMPAT_STREAM_H // Compatibility with old library. #define _STREAM_COMPAT #include extern char* form(const char*, ...); extern char* dec(long, int=0); extern char* dec(int, int=0); extern char* dec(unsigned long, int=0); extern char* dec(unsigned int, int=0); extern char* hex(long, int=0); extern char* hex(int, int=0); extern char* hex(unsigned long, int=0); extern char* hex(unsigned int, int=0); extern char* oct(long, int=0); extern char* oct(int, int=0); extern char* oct(unsigned long, int=0); extern char* oct(unsigned int, int=0); char* chr(char ch, int width = 0); char* str(const char* s, int width = 0); inline istream& WS(istream& str) { return ws(str); } #endif /* !_COMPAT_STREAM_H */ ./g++-include/streambuf.h100644 0 1 37550 5522102245 13740 0ustar rootdaemon/* This is part of libio/iostream, providing -*- C++ -*- input/output. Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ #ifndef _STREAMBUF_H #define _STREAMBUF_H #ifdef __GNUG__ #pragma interface #endif /* #define _G_IO_THROW */ /* Not implemented: ios::failure */ extern "C" { #include } //#include <_G_config.h> #ifdef _IO_NEED_STDARG_H #include #endif #ifndef _IO_va_list #define _IO_va_list char * #endif #ifndef EOF #define EOF (-1) #endif #ifndef NULL #ifdef __GNUC__ #define NULL ((void*)0) #else #define NULL (0) #endif #endif #ifndef _IO_wchar_t #define _IO_wchar_t short #endif class istream; /* Work-around for a g++ name mangling bug. */ class ostream; class streambuf; // In case some header files defines these as macros. #undef open #undef close extern "C" int __underflow(struct _IO_FILE*); extern "C" int __overflow(struct _IO_FILE*, int); typedef _IO_off_t streamoff; typedef _IO_fpos_t streampos; typedef _IO_ssize_t streamsize; typedef unsigned long __fmtflags; typedef unsigned char __iostate; struct _ios_fields { // The data members of an ios. // Directly using _strbuf is dangerous, because the vtable // pointer can be NULL. Use rdbuf() when in doubt. streambuf *_strbuf; ostream* _tie; int _width; __fmtflags _flags; _IO_wchar_t _fill; __iostate _state; __iostate _exceptions; int _precision; void *_arrays; /* Support for ios::iword and ios::pword. */ }; #define _IOS_GOOD 0 #define _IOS_EOF 1 #define _IOS_FAIL 2 #define _IOS_BAD 4 #define _IO_INPUT 1 #define _IO_OUTPUT 2 #define _IO_ATEND 4 #define _IO_APPEND 8 #define _IO_TRUNC 16 #define _IO_NOCREATE 32 #define _IO_NOREPLACE 64 #define _IO_BIN 128 #ifdef _STREAM_COMPAT enum state_value { _good = _IOS_GOOD, _eof = _IOS_EOF, _fail = _IOS_FAIL, _bad = _IOS_BAD }; enum open_mode { input = _IO_INPUT, output = _IO_OUTPUT, atend = _IO_ATEND, append = _IO_APPEND }; #endif class ios : public _ios_fields { public: typedef __fmtflags fmtflags; typedef int iostate; typedef int openmode; typedef int streamsize; enum io_state { goodbit = _IOS_GOOD, eofbit = _IOS_EOF, failbit = _IOS_FAIL, badbit = _IOS_BAD }; enum open_mode { in = _IO_INPUT, out = _IO_OUTPUT, ate = _IO_ATEND, app = _IO_APPEND, trunc = _IO_TRUNC, nocreate = _IO_NOCREATE, noreplace = _IO_NOREPLACE, bin = _IOS_BIN }; enum seek_dir { beg, cur, end}; // ANSI: typedef enum seek_dir seekdir; etc // NOTE: If adding flags here, before to update ios::bitalloc(). enum { skipws=_IO_SKIPWS, left=_IO_LEFT, right=_IO_RIGHT, internal=_IO_INTERNAL, dec=_IO_DEC, oct=_IO_OCT, hex=_IO_HEX, showbase=_IO_SHOWBASE, showpoint=_IO_SHOWPOINT, uppercase=_IO_UPPERCASE, showpos=_IO_SHOWPOS, scientific=_IO_SCIENTIFIC, fixed=_IO_FIXED, unitbuf=_IO_UNITBUF, stdio=_IO_STDIO, dont_close=_IO_DONT_CLOSE // Don't delete streambuf on stream destruction }; enum { // Masks. basefield=dec+oct+hex, floatfield = scientific+fixed, adjustfield = left+right+internal }; #ifdef _IO_THROW class failure : public xmsg { ios* _stream; public: failure(ios* stream) { _stream = stream; } failure(string cause, ios* stream) { _stream = stream; } ios* rdios() const { return _stream; } }; #endif ostream* tie() const { return _tie; } ostream* tie(ostream* val) { ostream* save=_tie; _tie=val; return save; } // Methods to change the format state. _IO_wchar_t fill() const { return (_IO_wchar_t)_fill; } _IO_wchar_t fill(_IO_wchar_t newf) {_IO_wchar_t oldf = (_IO_wchar_t)_fill; _fill = (char)newf; return oldf;} fmtflags flags() const { return _flags; } fmtflags flags(fmtflags new_val) { fmtflags old_val = _flags; _flags = new_val; return old_val; } int precision() const { return _precision; } int precision(int newp) { unsigned short oldp = _precision; _precision = (unsigned short)newp; return oldp; } fmtflags setf(fmtflags val) { fmtflags oldbits = _flags; _flags |= val; return oldbits; } fmtflags setf(fmtflags val, fmtflags mask) { fmtflags oldbits = _flags; _flags = (_flags & ~mask) | (val & mask); return oldbits; } fmtflags unsetf(fmtflags mask) { fmtflags oldbits = _flags; _flags &= ~mask; return oldbits; } int width() const { return _width; } int width(int val) { int save = _width; _width = val; return save; } #ifdef _IO_THROW void _throw_failure() const { throw new ios::failure(this); } #else void _throw_failure() const { } #endif void _IO_fix_vtable(); /* TEMPORARY - for binary compatibility */ void _IO_fix_vtable() const; streambuf* rdbuf() const; #if 0 streambuf* rdbuf(streambuf *_s) { streambuf *_old = _strbuf; _strbuf = _s; return _old; } #endif void clear(iostate state = 0) { _state = _strbuf ? state : state|badbit; if (_state & _exceptions) _throw_failure(); } void set(iostate flag) { _state |= flag; if (_state & _exceptions) _throw_failure(); } void setstate(iostate flag) { _state |= flag; // ANSI if (_state & _exceptions) _throw_failure(); } int good() const { return _state == 0; } int eof() const { return _state & ios::eofbit; } int fail() const { return _state & (ios::badbit|ios::failbit); } int bad() const { return _state & ios::badbit; } iostate rdstate() const { return _state; } operator void*() const { return fail() ? (void*)0 : (void*)(-1); } int operator!() const { return fail(); } iostate exceptions() const { return _exceptions; } void exceptions(iostate enable) { _exceptions = enable; if (_state & _exceptions) _throw_failure(); } static int sync_with_stdio(int on); static void sync_with_stdio() { sync_with_stdio(1); } static fmtflags bitalloc(); static int xalloc(); void*& pword(int); void* pword(int) const; long& iword(int); long iword(int) const; #ifdef _STREAM_COMPAT void unset(state_value flag) { _state &= ~flag; } void close(); int is_open(); int readable(); int writable(); #endif // Used to initialize standard streams. Not needed in this implementation. class Init { public: Init () { } }; protected: ios(streambuf* sb = 0, ostream* tie = 0); virtual ~ios(); void init(streambuf* sb) { _state=0; _strbuf=sb; } }; #if __GNUG__==1 typedef int _seek_dir; #else typedef ios::seek_dir _seek_dir; #endif // Magic numbers and bits for the _flags field. // The magic numbers use the high-order bits of _flags; // the remaining bits are abailable for variable flags. // Note: The magic numbers must all be negative if stdio // emulation is desired. // A streammarker remembers a position in a buffer. // You are guaranteed to be able to seek back to it if it is saving(). class streammarker : private _IO_marker { friend class streambuf; void set_offset(int offset) { _pos = offset; } public: streammarker(streambuf *sb); ~streammarker(); int saving() { return 1; } int delta(streammarker&); int delta(); }; extern unsigned __adjust_column(unsigned start, const char *line, int count); struct streambuf : public _IO_FILE { // protected?? friend class ios; friend class istream; friend class ostream; friend class streammarker; const void *&_vtable() { return ((struct _IO_FILE_plus*)this)->_vtable; } protected: static streambuf* _list_all; /* List of open streambufs. */ _IO_FILE*& xchain() { return _chain; } void _un_link(); void _link_in(); char* gptr() const { return _IO_file_flags & _IO_IN_BACKUP ? _IO_save_base : _IO_read_ptr; } char* pptr() const { return _IO_write_ptr; } char* egptr() const { return _IO_file_flags & _IO_IN_BACKUP ? _IO_save_end : _IO_read_end; } char* epptr() const { return _IO_write_end; } char* pbase() const { return _IO_write_base; } char* eback() const { return _IO_file_flags & _IO_IN_BACKUP ? _IO_save_base : _IO_read_base;} char* base() const { return _IO_buf_base; } char* ebuf() const { return _IO_buf_end; } int blen() const { return _IO_buf_end - _IO_buf_base; } void xput_char(char c) { *_IO_write_ptr++ = c; } int xflags() { return _IO_file_flags; } int xflags(int f) {int fl = _IO_file_flags; _IO_file_flags = f; return fl;} void xsetflags(int f) { _IO_file_flags |= f; } void xsetflags(int f, int mask) { _IO_file_flags = (_IO_file_flags & ~mask) | (f & mask); } void gbump(int n) { _IO_file_flags & _IO_IN_BACKUP ? (_IO_save_base+=n):(_IO_read_ptr+=n);} void pbump(int n) { _IO_write_ptr += n; } void setb(char* b, char* eb, int a=0); void setp(char* p, char* ep) { _IO_write_base=_IO_write_ptr=p; _IO_write_end=ep; } void setg(char* eb, char* g, char *eg) { if (_IO_file_flags & _IO_IN_BACKUP) _IO_free_backup_area(this); _IO_read_base = eb; _IO_read_ptr = g; _IO_read_end = eg; } char *shortbuf() { return _shortbuf; } int in_backup() { return _flags & _IO_IN_BACKUP; } // The start of the main get area: FIXME: wrong for write-mode filebuf? char *Gbase() { return in_backup() ? _other_gbase : _IO_read_base; } // The end of the main get area: char *eGptr() { return in_backup() ? _other_egptr : _IO_read_end; } // The start of the backup area: char *Bbase() { return in_backup() ? _IO_read_base : _other_gbase; } char *Bptr() { return _aux_limit; } // The end of the backup area: char *eBptr() { return in_backup() ? _IO_read_end : _other_egptr; } char *Nbase() { return _other_gbase; } char *eNptr() { return _other_egptr; } int have_backup() { return _other_gbase != NULL; } int have_markers() { return _markers != NULL; } void free_backup_area(); void unsave_markers(); // Make all streammarkers !saving(). int put_mode() { return _flags & _IO_CURRENTLY_PUTTING; } int switch_to_get_mode(); streambuf(int flags=0); public: static int flush_all(); static void flush_all_linebuffered(); // Flush all line buffered files. virtual int underflow(); // Leave public for now virtual int overflow(int c = EOF); // Leave public for now virtual int doallocate(); streampos sseekoff(streamoff, _seek_dir, int mode=ios::in|ios::out); streampos sseekpos(streampos pos, int mode = ios::in|ios::out); virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out); virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out); int seekmark(streammarker& mark, int delta = 0); int sputbackc(char c); int sungetc(); virtual ~streambuf(); int unbuffered() { return _flags & _IO_UNBUFFERED ? 1 : 0; } int linebuffered() { return _flags & _IO_LINE_BUF ? 1 : 0; } void unbuffered(int i) { if (i) _flags |= _IO_UNBUFFERED; else _flags &= ~_IO_UNBUFFERED; } void linebuffered(int i) { if (i) _flags |= _IO_LINE_BUF; else _flags &= ~_IO_LINE_BUF; } int allocate() { // For AT&T compatibility if (base() || unbuffered()) return 0; else return doallocate(); } // Allocate a buffer if needed; use _shortbuf if appropriate. void allocbuf() { if (base() == NULL) doallocbuf(); } void doallocbuf(); virtual int sync(); virtual int pbackfail(int c); virtual streambuf* setbuf(char* p, int len); int in_avail() { return _IO_read_end - _IO_read_ptr; } int out_waiting() { return _IO_write_ptr - _IO_write_base; } virtual streamsize xsputn(const char* s, streamsize n); streamsize sputn(const char* s, streamsize n) { return xsputn(s, n); } streamsize padn(char pad, streamsize n) { return _IO_padn(this, pad, n); } virtual streamsize xsgetn(char* s, streamsize n); streamsize sgetn(char* s, streamsize n) { return _IO_sgetn(this, s, n); } int ignore(int); virtual int get_column(); virtual int set_column(int); long sgetline(char* buf, _IO_size_t n, char delim, int putback_delim); int sputc(int c) { return _IO_putc(c, this); } int sbumpc() { return _IO_getc(this); } int sgetc() { return _IO_peekc(this); } int snextc() { if (_IO_read_ptr >= _IO_read_end && __underflow(this) == EOF) return EOF; else return _IO_read_ptr++, sgetc(); } void stossc() { if (_IO_read_ptr < _IO_read_end) _IO_read_ptr++; } int vscan(char const *fmt0, _IO_va_list ap, ios* stream = NULL); int scan(char const *fmt0 ...); int vform(char const *fmt0, _IO_va_list ap); int form(char const *fmt0 ...); #if 0 /* Work in progress */ int column(); // Current column number (of put pointer). -1 is unknown. void column(int c); // Set column number of put pointer to c. #endif virtual streamsize sys_read(char* buf, streamsize size); virtual streampos sys_seek(streamoff, _seek_dir); virtual streamsize sys_write(const char*, streamsize); virtual int sys_stat(void*); // Actually, a (struct stat*) virtual int sys_close(); }; // A backupbuf is a streambuf with full backup and savepoints on reading. // All standard streambufs in the GNU iostream library are backupbufs. class filebuf : public streambuf { protected: void init(); public: static const int openprot; // Non-ANSI AT&T-ism: Default open protection. filebuf(); filebuf(int fd); filebuf(int fd, char* p, int len); static filebuf *__new(); ~filebuf(); filebuf* attach(int fd); filebuf* open(const char *filename, const char *mode); filebuf* open(const char *filename, ios::openmode mode, int prot = 0664); virtual int underflow(); virtual int overflow(int c = EOF); int is_open() const { return _fileno >= 0; } int fd() const { return is_open() ? _fileno : EOF; } filebuf* close(); virtual int doallocate(); virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out); virtual streambuf* setbuf(char* p, int len); streamsize xsputn(const char* s, streamsize n); streamsize xsgetn(char* s, streamsize n); virtual int sync(); protected: // See documentation in filebuf.C. // virtual int pbackfail(int c); int is_reading() { return eback() != egptr(); } char* cur_ptr() { return is_reading() ? gptr() : pptr(); } /* System's idea of pointer */ char* file_ptr() { return eGptr(); } int do_write(const char *data, int to_do); // Low-level operations (Usually invoke system calls.) virtual streamsize sys_read(char* buf, streamsize size); virtual streampos sys_seek(streamoff, _seek_dir); virtual streamsize sys_write(const char*, streamsize); virtual int sys_stat(void*); // Actually, a (struct stat*) virtual int sys_close(); }; inline ios::ios(streambuf* sb /* = 0 */, ostream* tie_to /* = 0 */) { _state = sb ? ios::goodbit : ios::badbit; _exceptions=0; _strbuf=sb; _tie = tie_to; _width=0; _fill=' '; _flags=ios::skipws|ios::dec; _precision=6; _arrays = 0; } inline streambuf* ios::rdbuf() const { if (_strbuf && _strbuf->_vtable() == 0) _IO_fix_vtable(); return _strbuf; } inline ios::~ios() { if (!(_flags & (unsigned int)ios::dont_close)) delete rdbuf(); } #endif /* _STREAMBUF_H */ ./g++-include/strfile.h100644 0 1 3002 5522102246 13362 0ustar rootdaemon/* Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ #include #ifdef TODO Merge into libio.h ? #endif typedef void *(*_IO_alloc_type) __P((_IO_size_t)); typedef void (*_IO_free_type) __P((void*)); struct _IO_str_fields { /* The current length is max(_len, _IO_write_ptr-_IO_write_base). */ _IO_size_t _len; _IO_alloc_type _allocate_buffer; _IO_free_type _free_buffer; }; typedef struct _IO_strfile_ { struct _IO_FILE_plus _f; struct _IO_str_fields _s; } _IO_strfile; ./g++-include/strstream.h100644 0 1 10311 5522102247 13760 0ustar rootdaemon/* This is part of libio/iostream, providing -*- C++ -*- input/output. Copyright (C) 1993 Free Software Foundation This file is part of the GNU IO Library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, if you link this library with files compiled with a GNU compiler to produce an executable, this does not cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ /* Written by Per Bothner (bothner@cygnus.com). */ #ifndef __STRSTREAM_H #define __STRSTREAM_H #ifdef __GNUG__ #pragma interface #endif #include #include class strstreambuf : public streambuf { struct _IO_str_fields _s; void init_dynamic(_IO_alloc_type alloc, _IO_free_type free, int initial_size = 128); void init_static(char *ptr, int size, char *pstart); void init_readonly(const char *ptr, int size); protected: int is_static() const { return _s._allocate_buffer == (_IO_alloc_type)0; } virtual int overflow(int = EOF); virtual int underflow(); virtual int pbackfail(int c); public: virtual ~strstreambuf(); strstreambuf() { init_dynamic(0, 0); } strstreambuf(int initial_size) { init_dynamic(0, 0, initial_size); } strstreambuf(void *(*alloc)(_IO_size_t), void (*free)(void*)) { init_dynamic(alloc, free); } strstreambuf(char *ptr, int size, char *pstart = NULL) { init_static(ptr, size, pstart); } strstreambuf(unsigned char *ptr, int size, unsigned char *pstart = NULL) { init_static((char*)ptr, size, (char*)pstart); } strstreambuf(const char *ptr, int size) { init_readonly(ptr, size); } strstreambuf(const unsigned char *ptr, int size) { init_readonly((const char*)ptr, size); } strstreambuf(signed char *ptr, int size, signed char *pstart = NULL) { init_static((char*)ptr, size, (char*)pstart); } strstreambuf(const signed char *ptr, int size) { init_readonly((const char*)ptr, size); } // Note: frozen() is always true if is_static(). int frozen() { return _flags & _IO_USER_BUF ? 1 : 0; } void freeze(int n=1) { if (!is_static()) { if (n) _flags |= _IO_USER_BUF; else _flags &= ~_IO_USER_BUF; } } _IO_ssize_t pcount(); char *str(); virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out); }; class strstreambase : virtual public ios { public: strstreambuf* rdbuf() { return (strstreambuf*)ios::rdbuf(); } protected: strstreambase() { } strstreambase(char *cp, int n, int mode=ios::out); }; class istrstream : public strstreambase, public istream { public: istrstream(const char*, int=0); }; class ostrstream : public strstreambase, public ostream { public: ostrstream(); ostrstream(char *cp, int n, int mode=ios::out) :strstreambase(cp,n,mode){} _IO_ssize_t pcount() { return ((strstreambuf*)_strbuf)->pcount(); } char *str() { return ((strstreambuf*)_strbuf)->str(); } void freeze(int n = 1) { ((strstreambuf*)_strbuf)->freeze(n); } int frozen() { return ((strstreambuf*)_strbuf)->frozen(); } }; class strstream : public strstreambase, public iostream { public: strstream() : strstreambase() { init(new strstreambuf()); } strstream(char *cp, int n, int mode=ios::out) :strstreambase(cp,n,mode){} _IO_ssize_t pcount() { return ((strstreambuf*)_strbuf)->pcount(); } char *str() { return ((strstreambuf*)_strbuf)->str(); } void freeze(int n = 1) { ((strstreambuf*)_strbuf)->freeze(n); } int frozen() { return ((strstreambuf*)_strbuf)->frozen(); } }; #endif /*!__STRSTREAM_H*/ ./g++-include/ACG.h100644 0 1 4202 5522102260 12303 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef _ACG_h #define _ACG_h 1 #include #include #ifdef __GNUG__ #pragma interface #endif // // Additive number generator. This method is presented in Volume II // of The Art of Computer Programming by Knuth. I've coded the algorithm // and have added the extensions by Andres Nowatzyk of CMU to randomize // the result of algorithm M a bit by using an LCG & a spatial // permutation table. // // The version presented uses the same constants for the LCG that Andres // uses (chosen by trial & error). The spatial permutation table is // the same size (it's based on word size). This is for 32-bit words. // // The ``auxillary table'' used by the LCG table varies in size, and // is chosen to be the the smallest power of two which is larger than // twice the size of the state table. // class ACG : public RNG { unsigned long initialSeed; // used to reset generator int initialTableEntry; unsigned long *state; unsigned long *auxState; short stateSize; short auxSize; unsigned long lcgRecurr; short j; short k; protected: public: ACG(unsigned long seed = 0, int size = 55); virtual ~ACG(); // // Return a long-words word of random bits // virtual unsigned long asLong(); virtual void reset(); }; #endif ./g++-include/AllocRing.h100644 0 1 3217 5522102261 13571 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1989 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) 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. */ #ifndef _AllocRing_h #ifdef __GNUG__ #pragma interface #endif #define _AllocRing_h 1 /* An AllocRing holds the last n malloc'ed strings, reallocating/reusing one only when the queue wraps around. It thus guarantees that the last n allocations are intact. It is useful for things like I/O formatting where reasonable restrictions may be made about the number of allowable live allocations before auto-deletion. */ class AllocRing { struct AllocQNode { void* ptr; int sz; }; AllocQNode* nodes; int n; int current; int find(void* p); public: AllocRing(int max); ~AllocRing(); void* alloc(int size); int contains(void* ptr); void clear(); void free(void* p); }; #endif ./g++-include/Binomial.h100644 0 1 3012 5522102262 13443 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef _Binomial_h #ifdef __GNUG__ #pragma interface #endif #define _Binomial_h 1 #include class Binomial: public Random { protected: int pN; double pU; public: Binomial(int n, double u, RNG *gen); int n(); int n(int xn); double u(); double u(int xu); virtual double operator()(); }; inline Binomial::Binomial(int n, double u, RNG *gen) : Random(gen){ pN = n; pU = u; } inline int Binomial::n() { return pN; } inline int Binomial::n(int xn) { int tmp = pN; pN = xn; return tmp; } inline double Binomial::u() { return pU; } inline double Binomial::u(int xu) { double tmp = pU; pU = xu; return tmp; } #endif ./g++-include/BitSet.h100644 0 1 21504 5522102262 13131 0ustar rootdaemon// 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) 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. */ #ifndef _BitSet_h #ifdef __GNUG__ #pragma interface #endif #define _BitSet_h 1 #include #include #define BITSETBITS (sizeof(short) * CHAR_BIT) struct BitSetRep { unsigned short len; // number of shorts in s unsigned short sz; // allocated slots unsigned short virt; // virtual 0 or 1 unsigned short s[1]; // bits start here }; extern BitSetRep* BitSetalloc(BitSetRep*, const unsigned short*, int, int, int); extern BitSetRep* BitSetcopy(BitSetRep*, const BitSetRep*); extern BitSetRep* BitSetresize(BitSetRep*, int); extern BitSetRep* BitSetop(const BitSetRep*, const BitSetRep*, BitSetRep*, char); extern BitSetRep* BitSetcmpl(const BitSetRep*, BitSetRep*); extern BitSetRep _nilBitSetRep; class BitSet; class BitSetBit { protected: BitSet* src; unsigned long pos; public: BitSetBit(BitSet* v, int p); BitSetBit(const BitSetBit& b); ~BitSetBit(); operator int() const; int operator = (int b); int operator = (const BitSetBit& b); }; class BitSet { protected: BitSetRep* rep; public: // constructors BitSet(); BitSet(const BitSet&); ~BitSet(); void operator = (const BitSet& y); // equality & subset tests friend int operator == (const BitSet& x, const BitSet& y); friend int operator != (const BitSet& x, const BitSet& y); friend int operator < (const BitSet& x, const BitSet& y); friend int operator <= (const BitSet& x, const BitSet& y); friend int operator > (const BitSet& x, const BitSet& y); friend int operator >= (const BitSet& x, const BitSet& y); // operations on self void operator |= (const BitSet& y); void operator &= (const BitSet& y); void operator -= (const BitSet& y); void operator ^= (const BitSet& y); void complement(); // individual bit manipulation void set(int pos); void set(int from, int to); void set(); // set all void clear(int pos); void clear(int from, int to); void clear(); // clear all void invert(int pos); void invert(int from, int to); int test(int pos) const; int test(int from, int to) const; BitSetBit operator [] (int i); // iterators int first(int b = 1) const; int last(int b = 1) const; int next(int pos, int b = 1) const; int prev(int pos, int b = 1) const; int previous(int pos, int b = 1) const /* Obsolete synonym */ { return prev(pos, b); } // status int empty() const; int virtual_bit() const; int count(int b = 1) const; // convertors & IO friend BitSet atoBitSet(const char* s, char f='0', char t='1', char star='*'); // BitSettoa is deprecated; do not use in new programs. friend const char* BitSettoa(const BitSet& x, char f='0', char t='1', char star='*'); friend BitSet shorttoBitSet(unsigned short w); friend BitSet longtoBitSet(unsigned long w); friend ostream& operator << (ostream& s, const BitSet& x); void printon(ostream& s, char f='0', char t='1', char star='*') const; // procedural versions of operators friend void and(const BitSet& x, const BitSet& y, BitSet& r); friend void or(const BitSet& x, const BitSet& y, BitSet& r); friend void xor(const BitSet& x, const BitSet& y, BitSet& r); friend void diff(const BitSet& x, const BitSet& y, BitSet& r); friend void complement(const BitSet& x, BitSet& r); // misc void error(const char* msg) const; int OK() const; }; typedef BitSet BitSetTmp; BitSet operator | (const BitSet& x, const BitSet& y); BitSet operator & (const BitSet& x, const BitSet& y); BitSet operator - (const BitSet& x, const BitSet& y); BitSet operator ^ (const BitSet& x, const BitSet& y); BitSet operator ~ (const BitSet& x); // These are inlined regardless of optimization inline int BitSet_index(int l) { return (unsigned)(l) / BITSETBITS; } inline int BitSet_pos(int l) { return l & (BITSETBITS - 1); } inline BitSet::BitSet() : rep(&_nilBitSetRep) {} inline BitSet::BitSet(const BitSet& x) :rep(BitSetcopy(0, x.rep)) {} inline BitSet::~BitSet() { if (rep != &_nilBitSetRep) delete rep; } inline void BitSet::operator = (const BitSet& y) { rep = BitSetcopy(rep, y.rep); } inline int operator != (const BitSet& x, const BitSet& y) { return !(x == y); } inline int operator > (const BitSet& x, const BitSet& y) { return y < x; } inline int operator >= (const BitSet& x, const BitSet& y) { return y <= x; } inline void and(const BitSet& x, const BitSet& y, BitSet& r) { r.rep = BitSetop(x.rep, y.rep, r.rep, '&'); } inline void or(const BitSet& x, const BitSet& y, BitSet& r) { r.rep = BitSetop(x.rep, y.rep, r.rep, '|'); } inline void xor(const BitSet& x, const BitSet& y, BitSet& r) { r.rep = BitSetop(x.rep, y.rep, r.rep, '^'); } inline void diff(const BitSet& x, const BitSet& y, BitSet& r) { r.rep = BitSetop(x.rep, y.rep, r.rep, '-'); } inline void complement(const BitSet& x, BitSet& r) { r.rep = BitSetcmpl(x.rep, r.rep); } #if defined(__GNUG__) && !defined(NO_NRV) inline BitSet operator & (const BitSet& x, const BitSet& y) return r { and(x, y, r); } inline BitSet operator | (const BitSet& x, const BitSet& y) return r { or(x, y, r); } inline BitSet operator ^ (const BitSet& x, const BitSet& y) return r { xor(x, y, r); } inline BitSet operator - (const BitSet& x, const BitSet& y) return r { diff(x, y, r); } inline BitSet operator ~ (const BitSet& x) return r { ::complement(x, r); } #else /* NO_NRV */ inline BitSet operator & (const BitSet& x, const BitSet& y) { BitSet r; and(x, y, r); return r; } inline BitSet operator | (const BitSet& x, const BitSet& y) { BitSet r; or(x, y, r); return r; } inline BitSet operator ^ (const BitSet& x, const BitSet& y) { BitSet r; xor(x, y, r); return r; } inline BitSet operator - (const BitSet& x, const BitSet& y) { BitSet r; diff(x, y, r); return r; } inline BitSet operator ~ (const BitSet& x) { BitSet r; ::complement(x, r); return r; } #endif inline void BitSet::operator &= (const BitSet& y) { and(*this, y, *this); } inline void BitSet::operator |= (const BitSet& y) { or(*this, y, *this); } inline void BitSet::operator ^= (const BitSet& y) { xor(*this, y, *this); } inline void BitSet::operator -= (const BitSet& y) { diff(*this, y, *this); } inline void BitSet::complement() { ::complement(*this, *this); } inline int BitSet::virtual_bit() const { return rep->virt; } inline int BitSet::first(int b) const { return next(-1, b); } inline int BitSet::test(int p) const { if (p < 0) error("Illegal bit index"); int index = BitSet_index(p); return (index >= rep->len)? rep->virt : ((rep->s[index] & (1 << BitSet_pos(p))) != 0); } inline void BitSet::set() { rep = BitSetalloc(rep, 0, 0, 1, 0); } inline BitSetBit::BitSetBit(const BitSetBit& b) :src(b.src), pos(b.pos) {} inline BitSetBit::BitSetBit(BitSet* v, int p) { src = v; pos = p; } inline BitSetBit::~BitSetBit() {} inline BitSetBit::operator int() const { return src->test(pos); } inline int BitSetBit::operator = (int b) { if (b) src->set(pos); else src->clear(pos); return b; } inline int BitSetBit::operator = (const BitSetBit& b) { int i = (int)b; *this = i; return i; } inline BitSetBit BitSet::operator [] (int i) { if (i < 0) error("illegal bit index"); return BitSetBit(this, i); } #endif ./g++-include/BitString.h100644 0 1 47411 5522102263 13652 0ustar rootdaemon// 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) 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. */ #ifndef _BitString_h #ifdef __GNUG__ #pragma interface #endif #define _BitString_h 1 #include #include #define BITSTRBITS (sizeof(short) * CHAR_BIT) struct BitStrRep { unsigned int len; // length in bits unsigned short sz; // allocated slots unsigned short s[1]; // bits start here }; extern BitStrRep* BStr_alloc(BitStrRep*, const unsigned short*, int, int,int); extern BitStrRep* BStr_resize(BitStrRep*, int); extern BitStrRep* BStr_copy(BitStrRep*, const BitStrRep*); extern BitStrRep* cmpl(const BitStrRep*, BitStrRep*); extern BitStrRep* and(const BitStrRep*, const BitStrRep*, BitStrRep*); extern BitStrRep* or(const BitStrRep*, const BitStrRep*, BitStrRep*); extern BitStrRep* xor(const BitStrRep*, const BitStrRep*, BitStrRep*); extern BitStrRep* diff(const BitStrRep*, const BitStrRep*, BitStrRep*); extern BitStrRep* cat(const BitStrRep*, const BitStrRep*, BitStrRep*); extern BitStrRep* cat(const BitStrRep*, unsigned int, BitStrRep*); extern BitStrRep* lshift(const BitStrRep*, int, BitStrRep*); class BitString; class BitPattern; class BitStrBit { protected: BitString& src; unsigned int pos; public: BitStrBit(BitString& v, int p); BitStrBit(const BitStrBit& b); ~BitStrBit(); operator unsigned int() const; int operator = (unsigned int b); }; class BitSubString { friend class BitString; friend class BitPattern; protected: BitString& S; unsigned int pos; unsigned int len; BitSubString(BitString& x, int p, int l); BitSubString(const BitSubString& x); public: ~BitSubString(); void operator = (const BitString&); void operator = (const BitSubString&); int length() const; int empty() const; int OK() const; }; class BitString { friend class BitSubString; friend class BitPattern; protected: BitStrRep* rep; int search(int, int, const unsigned short*, int, int) const; int match(int, int, int, const unsigned short*,int,int) const; BitSubString _substr(int first, int l); public: // constructors BitString(); BitString(const BitString&); BitString(const BitSubString& y); ~BitString(); void operator = (unsigned int bit); void operator = (const BitString& y); void operator = (const BitSubString& y); // equality & subset tests friend int operator == (const BitString&, const BitString&); friend int operator != (const BitString&, const BitString&); friend int operator < (const BitString&, const BitString&); friend int operator <= (const BitString&, const BitString&); friend int operator > (const BitString&, const BitString&); friend int operator >= (const BitString&, const BitString&); // procedural versions of operators friend void and(const BitString&, const BitString&, BitString&); friend void or(const BitString&, const BitString&, BitString&); friend void xor(const BitString&, const BitString&, BitString&); friend void diff(const BitString&, const BitString&, BitString&); friend void cat(const BitString&, const BitString&, BitString&); friend void cat(const BitString&, unsigned int, BitString&); friend void lshift(const BitString&, int, BitString&); friend void rshift(const BitString&, int, BitString&); friend void complement(const BitString&, BitString&); friend int lcompare(const BitString&, const BitString&); // assignment-based operators // (constuctive versions decalred inline below void operator |= (const BitString&); void operator &= (const BitString&); void operator -= (const BitString&); void operator ^= (const BitString&); void operator += (const BitString&); void operator += (unsigned int b); void operator <<=(int s); void operator >>=(int s); void complement(); // individual bit manipulation void set(int pos); void set(int from, int to); void set(); void clear(int pos); void clear(int from, int to); void clear(); void invert(int pos); void invert(int from, int to); int test(int pos) const; int test(int from, int to) const; void assign(int p, unsigned int bit); // indexing BitStrBit operator [] (int pos); // iterators int first(unsigned int bit = 1) const; int last(unsigned int b = 1) const; int next(int pos, unsigned int b = 1) const; int prev(int pos, unsigned int b = 1) const; int previous(int pos, unsigned int b = 1) const { return prev(pos, b); } /* Obsolete synonym */ // searching & matching int index(unsigned int bit, int startpos = 0) const ; int index(const BitString&, int startpos = 0) const; int index(const BitSubString&, int startpos = 0) const; int index(const BitPattern&, int startpos = 0) const; int contains(const BitString&) const; int contains(const BitSubString&) const; int contains(const BitPattern&) const; int contains(const BitString&, int pos) const; int contains(const BitSubString&, int pos) const; int contains(const BitPattern&, int pos) const; int matches(const BitString&, int pos = 0) const; int matches(const BitSubString&, int pos = 0) const; int matches(const BitPattern&, int pos = 0) const; // BitSubString extraction BitSubString at(int pos, int len); BitSubString at(const BitString&, int startpos = 0); BitSubString at(const BitSubString&, int startpos = 0); BitSubString at(const BitPattern&, int startpos = 0); BitSubString before(int pos); BitSubString before(const BitString&, int startpos = 0); BitSubString before(const BitSubString&, int startpos = 0); BitSubString before(const BitPattern&, int startpos = 0); BitSubString after(int pos); BitSubString after(const BitString&, int startpos = 0); BitSubString after(const BitSubString&, int startpos = 0); BitSubString after(const BitPattern&, int startpos = 0); // other friends & utilities friend BitString common_prefix(const BitString&, const BitString&, int pos = 0); friend BitString common_suffix(const BitString&, const BitString&, int pos = -1); friend BitString reverse(const BitString&); void right_trim(unsigned int bit); void left_trim(unsigned int bit); // status int empty() const ; int count(unsigned int bit = 1) const; int length() const; // convertors & IO friend BitString atoBitString(const char* s, char f='0', char t='1'); // BitStringtoa is deprecated; do not use in new programs! friend const char* BitStringtoa(const BitString&, char f='0', char t='1'); void printon(ostream&, char f='0', char t='1') const; friend BitString shorttoBitString(unsigned short); friend BitString longtoBitString(unsigned long); friend ostream& operator << (ostream& s, const BitString&); // misc void error(const char* msg) const; // indirect friends friend BitPattern atoBitPattern(const char* s, char f='0',char t='1',char x='X'); friend const char* BitPatterntoa(const BitPattern& p, char f='0',char t='1',char x='X'); int OK() const; }; class BitPattern { public: BitString pattern; BitString mask; BitPattern(); BitPattern(const BitPattern&); BitPattern(const BitString& p, const BitString& m); ~BitPattern(); friend const char* BitPatterntoa(const BitPattern& p, char f/*='0'*/,char t/*='1'*/,char x/*='X'*/); void printon(ostream&, char f='0',char t='1',char x='X') const; friend BitPattern atoBitPattern(const char* s, char f,char t, char x); friend ostream& operator << (ostream& s, const BitPattern&); int search(const unsigned short*, int, int) const; int match(const unsigned short* xs, int, int, int) const; int OK() const; }; BitString operator & (const BitString& x, const BitString& y); BitString operator | (const BitString& x, const BitString& y); BitString operator ^ (const BitString& x, const BitString& y); BitString operator << (const BitString& x, int y); BitString operator >> (const BitString& x, int y); BitString operator - (const BitString& x, const BitString& y); BitString operator + (const BitString& x, const BitString& y); BitString operator + (const BitString& x, unsigned int y); BitString operator ~ (const BitString& x); int operator != (const BitString& x, const BitString& y); int operator>(const BitString& x, const BitString& y); int operator>=(const BitString& x, const BitString& y); extern BitStrRep _nilBitStrRep; extern BitString _nil_BitString; // primitive bit extraction // These must be inlined regardless of optimization. inline int BitStr_index(int l) { return (unsigned)(l) / BITSTRBITS; } inline int BitStr_pos(int l) { return l & (BITSTRBITS - 1); } // constructors & assignment inline BitString::BitString() :rep(&_nilBitStrRep) {} inline BitString::BitString(const BitString& x) :rep(BStr_copy(0, x.rep)) {} inline BitString::BitString(const BitSubString& y) :rep (BStr_alloc(0, y.S.rep->s, y.pos, y.pos+y.len, y.len)) {} inline BitString::~BitString() { if (rep != &_nilBitStrRep) delete rep; } #if defined(__GNUG__) && !defined(NO_NRV) inline BitString shorttoBitString(unsigned short w) return r { r.rep = BStr_alloc(0, &w, 0, BITSTRBITS, BITSTRBITS); } inline BitString longtoBitString(unsigned long w) return r { unsigned short u[2]; u[0] = w & ((unsigned short)(~(0))); u[1] = w >> BITSTRBITS; r.rep = BStr_alloc(0, &u[0], 0, 2*BITSTRBITS, 2*BITSTRBITS); } #else inline BitString shorttoBitString(unsigned short w) { BitString r; r.rep = BStr_alloc(0, &w, 0, BITSTRBITS, BITSTRBITS); return r; } inline BitString longtoBitString(unsigned long w) { BitString r; unsigned short u[2]; u[0] = w & ((unsigned short)(~(0))); u[1] = w >> BITSTRBITS; r.rep = BStr_alloc(0, &u[0], 0, 2*BITSTRBITS, 2*BITSTRBITS); return r; } #endif inline void BitString::operator = (const BitString& y) { rep = BStr_copy(rep, y.rep); } inline void BitString::operator = (unsigned int b) { unsigned short bit = b; rep = BStr_alloc(rep, &bit, 0, 1, 1); } inline void BitString::operator=(const BitSubString& y) { rep = BStr_alloc(rep, y.S.rep->s, y.pos, y.pos+y.len, y.len); } inline BitSubString::BitSubString(const BitSubString& x) :S(x.S), pos(x.pos), len(x.len) {} inline BitSubString::BitSubString(BitString& x, int p, int l) : S(x), pos(p), len(l) {} inline BitSubString::~BitSubString() {} inline BitPattern::BitPattern(const BitString& p, const BitString& m) :pattern(p), mask(m) {} inline BitPattern::BitPattern(const BitPattern& b) :pattern(b.pattern), mask(b.mask) {} inline BitPattern::BitPattern() {} inline BitPattern::~BitPattern() {} // procedural versions of operators inline void and(const BitString& x, const BitString& y, BitString& r) { r.rep = and(x.rep, y.rep, r.rep); } inline void or(const BitString& x, const BitString& y, BitString& r) { r.rep = or(x.rep, y.rep, r.rep); } inline void xor(const BitString& x, const BitString& y, BitString& r) { r.rep = xor(x.rep, y.rep, r.rep); } inline void diff(const BitString& x, const BitString& y, BitString& r) { r.rep = diff(x.rep, y.rep, r.rep); } inline void cat(const BitString& x, const BitString& y, BitString& r) { r.rep = cat(x.rep, y.rep, r.rep); } inline void cat(const BitString& x, unsigned int y, BitString& r) { r.rep = cat(x.rep, y, r.rep); } inline void rshift(const BitString& x, int y, BitString& r) { r.rep = lshift(x.rep, -y, r.rep); } inline void lshift(const BitString& x, int y, BitString& r) { r.rep = lshift(x.rep, y, r.rep); } inline void complement(const BitString& x, BitString& r) { r.rep = cmpl(x.rep, r.rep); } // operators inline void BitString::operator &= (const BitString& y) { and(*this, y, *this); } inline void BitString::operator |= (const BitString& y) { or(*this, y, *this); } inline void BitString::operator ^= (const BitString& y) { xor(*this, y, *this); } inline void BitString::operator <<= (int y) { lshift(*this, y, *this); } inline void BitString::operator >>= (int y) { rshift(*this, y, *this); } inline void BitString::operator -= (const BitString& y) { diff(*this, y, *this); } inline void BitString::operator += (const BitString& y) { cat(*this, y, *this); } inline void BitString::operator += (unsigned int y) { cat(*this, y, *this); } inline void BitString::complement() { ::complement(*this, *this); } #if defined(__GNUG__) && !defined(NO_NRV) inline BitString operator & (const BitString& x, const BitString& y) return r { and(x, y, r); } inline BitString operator | (const BitString& x, const BitString& y) return r { or(x, y, r); } inline BitString operator ^ (const BitString& x, const BitString& y) return r { xor(x, y, r); } inline BitString operator << (const BitString& x, int y) return r { lshift(x, y, r); } inline BitString operator >> (const BitString& x, int y) return r { rshift(x, y, r); } inline BitString operator - (const BitString& x, const BitString& y) return r { diff(x, y, r); } inline BitString operator + (const BitString& x, const BitString& y) return r { cat(x, y, r); } inline BitString operator + (const BitString& x, unsigned int y) return r { cat(x, y, r); } inline BitString operator ~ (const BitString& x) return r { complement(x, r); } #else /* NO_NRV */ inline BitString operator & (const BitString& x, const BitString& y) { BitString r; and(x, y, r); return r; } inline BitString operator | (const BitString& x, const BitString& y) { BitString r; or(x, y, r); return r; } inline BitString operator ^ (const BitString& x, const BitString& y) { BitString r; xor(x, y, r); return r; } inline BitString operator << (const BitString& x, int y) { BitString r; lshift(x, y, r); return r; } inline BitString operator >> (const BitString& x, int y) { BitString r; rshift(x, y, r); return r; } inline BitString operator - (const BitString& x, const BitString& y) { BitString r; diff(x, y, r); return r; } inline BitString operator + (const BitString& x, const BitString& y) { BitString r; cat(x, y, r); return r; } inline BitString operator + (const BitString& x, unsigned int y) { BitString r; cat(x, y, r); return r; } inline BitString operator ~ (const BitString& x) { BitString r; complement(x, r); return r; } #endif // status, matching inline int BitString::length() const { return rep->len; } inline int BitString::empty() const { return rep->len == 0; } inline int BitString::index(const BitString& y, int startpos) const { return search(startpos, rep->len, y.rep->s, 0, y.rep->len); } inline int BitString::index(const BitSubString& y, int startpos) const { return search(startpos, rep->len, y.S.rep->s, y.pos, y.pos+y.len); } inline int BitString::contains(const BitString& y) const { return search(0, rep->len, y.rep->s, 0, y.rep->len) >= 0; } inline int BitString::contains(const BitSubString& y) const { return search(0, rep->len, y.S.rep->s, y.pos, y.pos+y.len) >= 0; } inline int BitString::contains(const BitString& y, int p) const { return match(p, rep->len, 0, y.rep->s, 0, y.rep->len); } inline int BitString::matches(const BitString& y, int p) const { return match(p, rep->len, 1, y.rep->s, 0, y.rep->len); } inline int BitString::contains(const BitSubString& y, int p) const { return match(p, rep->len, 0, y.S.rep->s, y.pos, y.pos+y.len); } inline int BitString::matches(const BitSubString& y, int p) const { return match(p, rep->len, 1, y.S.rep->s, y.pos, y.pos+y.len); } inline int BitString::contains(const BitPattern& r) const { return r.search(rep->s, 0, rep->len) >= 0; } inline int BitString::contains(const BitPattern& r, int p) const { return r.match(rep->s, p, rep->len, 0); } inline int BitString::matches(const BitPattern& r, int p) const { return r.match(rep->s, p, rep->len, 1); } inline int BitString::index(const BitPattern& r, int startpos) const { return r.search(rep->s, startpos, rep->len); } inline int BitSubString::length() const { return len; } inline int BitSubString::empty() const { return len == 0; } inline int operator != (const BitString& x, const BitString& y) { return !(x == y); } inline int operator>(const BitString& x, const BitString& y) { return y < x; } inline int operator>=(const BitString& x, const BitString& y) { return y <= x; } inline int BitString::first(unsigned int b) const { return next(-1, b); } inline int BitString::last(unsigned int b) const { return prev(rep->len, b); } inline int BitString::index(unsigned int bit, int startpos) const { if (startpos >= 0) return next(startpos - 1, bit); else return prev(rep->len + startpos + 1, bit); } inline void BitString::right_trim(unsigned int b) { int nb = (b == 0)? 1 : 0; rep = BStr_resize(rep, prev(rep->len, nb) + 1); } inline void BitString::left_trim(unsigned int b) { int nb = (b == 0)? 1 : 0; int p = next(-1, nb); rep = BStr_alloc(rep, rep->s, p, rep->len, rep->len - p); } inline int BitString::test(int i) const { return ((unsigned)(i) >= rep->len)? 0 : ((rep->s[BitStr_index(i)] & (1 << (BitStr_pos(i)))) != 0); } // subscripting inline BitStrBit::BitStrBit(const BitStrBit& b) :src(b.src), pos(b.pos) {} inline BitStrBit::BitStrBit(BitString& v, int p) :src(v), pos(p) {} inline BitStrBit::~BitStrBit() {} inline BitStrBit::operator unsigned int() const { return src.test(pos); } inline int BitStrBit::operator = (unsigned int b) { src.assign(pos, b); return b; } inline BitStrBit BitString::operator [] (int i) { if ((unsigned)(i) >= rep->len) error("illegal bit index"); return BitStrBit(*this, i); } inline BitSubString BitString::_substr(int first, int l) { if (first < 0 || l <= 0 || (unsigned)(first + l) > rep->len) return BitSubString(_nil_BitString, 0, 0) ; else return BitSubString(*this, first, l); } #endif ./g++-include/Complex.h100644 0 1 15170 5522102264 13352 0ustar rootdaemon// 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) 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. */ #ifndef _Complex_h #ifdef __GNUG__ #pragma interface #endif #define _Complex_h 1 #include #include class Complex { #ifdef __ATT_complex__ public: #else protected: #endif double re; double im; public: double real() const; double imag() const; Complex(); Complex(const Complex& y); Complex(double r, double i=0); ~Complex(); Complex& operator = (const Complex& y); Complex& operator += (const Complex& y); Complex& operator += (double y); Complex& operator -= (const Complex& y); Complex& operator -= (double y); Complex& operator *= (const Complex& y); Complex& operator *= (double y); Complex& operator /= (const Complex& y); Complex& operator /= (double y); void error(const char* msg) const; }; // non-inline functions Complex operator / (const Complex& x, const Complex& y); Complex operator / (const Complex& x, double y); Complex operator / (double x, const Complex& y); Complex cos(const Complex& x); Complex sin(const Complex& x); Complex cosh(const Complex& x); Complex sinh(const Complex& x); Complex exp(const Complex& x); Complex log(const Complex& x); Complex pow(const Complex& x, int p); Complex pow(const Complex& x, const Complex& p); Complex pow(const Complex& x, double y); Complex sqrt(const Complex& x); istream& operator >> (istream& s, Complex& x); ostream& operator << (ostream& s, const Complex& x); // other functions defined as inlines int operator == (const Complex& x, const Complex& y); int operator == (const Complex& x, double y); int operator != (const Complex& x, const Complex& y); int operator != (const Complex& x, double y); Complex operator - (const Complex& x); Complex conj(const Complex& x); Complex operator + (const Complex& x, const Complex& y); Complex operator + (const Complex& x, double y); Complex operator + (double x, const Complex& y); Complex operator - (const Complex& x, const Complex& y); Complex operator - (const Complex& x, double y); Complex operator - (double x, const Complex& y); Complex operator * (const Complex& x, const Complex& y); Complex operator * (const Complex& x, double y); Complex operator * (double x, const Complex& y); double real(const Complex& x); double imag(const Complex& x); double abs(const Complex& x); double norm(const Complex& x); double arg(const Complex& x); Complex polar(double r, double t = 0.0); // inline members inline double Complex::real() const { return re; } inline double Complex::imag() const { return im; } inline Complex::Complex() {} inline Complex::Complex(const Complex& y) :re(y.real()), im(y.imag()) {} inline Complex::Complex(double r, double i) :re(r), im(i) {} inline Complex::~Complex() {} inline Complex& Complex::operator = (const Complex& y) { re = y.real(); im = y.imag(); return *this; } inline Complex& Complex::operator += (const Complex& y) { re += y.real(); im += y.imag(); return *this; } inline Complex& Complex::operator += (double y) { re += y; return *this; } inline Complex& Complex::operator -= (const Complex& y) { re -= y.real(); im -= y.imag(); return *this; } inline Complex& Complex::operator -= (double y) { re -= y; return *this; } inline Complex& Complex::operator *= (const Complex& y) { double r = re * y.real() - im * y.imag(); im = re * y.imag() + im * y.real(); re = r; return *this; } inline Complex& Complex::operator *= (double y) { re *= y; im *= y; return *this; } // functions inline int operator == (const Complex& x, const Complex& y) { return x.real() == y.real() && x.imag() == y.imag(); } inline int operator == (const Complex& x, double y) { return x.imag() == 0.0 && x.real() == y; } inline int operator != (const Complex& x, const Complex& y) { return x.real() != y.real() || x.imag() != y.imag(); } inline int operator != (const Complex& x, double y) { return x.imag() != 0.0 || x.real() != y; } inline Complex operator - (const Complex& x) { return Complex(-x.real(), -x.imag()); } inline Complex conj(const Complex& x) { return Complex(x.real(), -x.imag()); } inline Complex operator + (const Complex& x, const Complex& y) { return Complex(x.real() + y.real(), x.imag() + y.imag()); } inline Complex operator + (const Complex& x, double y) { return Complex(x.real() + y, x.imag()); } inline Complex operator + (double x, const Complex& y) { return Complex(x + y.real(), y.imag()); } inline Complex operator - (const Complex& x, const Complex& y) { return Complex(x.real() - y.real(), x.imag() - y.imag()); } inline Complex operator - (const Complex& x, double y) { return Complex(x.real() - y, x.imag()); } inline Complex operator - (double x, const Complex& y) { return Complex(x - y.real(), -y.imag()); } inline Complex operator * (const Complex& x, const Complex& y) { return Complex(x.real() * y.real() - x.imag() * y.imag(), x.real() * y.imag() + x.imag() * y.real()); } inline Complex operator * (const Complex& x, double y) { return Complex(x.real() * y, x.imag() * y); } inline Complex operator * (double x, const Complex& y) { return Complex(x * y.real(), x * y.imag()); } inline double real(const Complex& x) { return x.real(); } inline double imag(const Complex& x) { return x.imag(); } inline double abs(const Complex& x) { return hypot(x.real(), x.imag()); } inline double norm(const Complex& x) { return (x.real() * x.real() + x.imag() * x.imag()); } inline double arg(const Complex& x) { return atan2(x.imag(), x.real()); } inline Complex polar(double r, double t) { return Complex(r * cos(t), r * sin(t)); } #endif ./g++-include/DLList.h100644 0 1 7750 5522102266 13065 0ustar rootdaemon// 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) 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. */ #ifndef _DLList_h #ifdef __GNUG__ //#pragma interface #endif #define _DLList_h 1 #include struct BaseDLNode { BaseDLNode *bk; BaseDLNode *fd; void *item() {return (void*)(this+1);} //Return ((DLNode*)this)->hd }; template class DLNode : public BaseDLNode { public: T hd; DLNode() { } DLNode(const T& h, DLNode* p = 0, DLNode* n = 0) : hd(h) { bk = p; fd = n; } ~DLNode() { } }; class BaseDLList { protected: BaseDLNode *h; BaseDLList() { h = 0; } void copy(const BaseDLList&); BaseDLList& operator= (const BaseDLList& a); virtual void delete_node(BaseDLNode*node) = 0; virtual BaseDLNode* copy_node(void* datum) = 0; virtual void copy_item(void *dst, void *src) = 0; virtual ~BaseDLList() { } Pix prepend(void*); Pix append(void*); Pix ins_after(Pix p, void *datum); Pix ins_before(Pix p, void *datum); void remove_front(void *dst); void remove_rear(void *dst); void join(BaseDLList&); public: int empty() { return h == 0; } int length(); void clear(); void error(const char* msg); int owns(Pix p); int OK(); void del(Pix& p, int dir = 1); void del_after(Pix& p); void del_front(); void del_rear(); }; template class DLList : public BaseDLList { //friend class DLListTrav; virtual void delete_node(BaseDLNode *node) { delete (DLNode*)node; } virtual BaseDLNode* copy_node(void *datum) { return new DLNode(*(T*)datum); } virtual void copy_item(void *dst, void *src) { *(T*)dst = *(T*)src; } public: DLList() : BaseDLList() { } DLList(const DLList& a) : BaseDLList() { copy(a); } DLList& operator = (const DLList& a) { BaseDLList::operator=((const BaseDLList&) a); return *this; } virtual ~DLList() { clear(); } Pix prepend(T& item) {return BaseDLList::prepend(&item);} Pix append(T& item) {return BaseDLList::append(&item);} void join(DLList& a) { BaseDLList::join(a); } T& front() { if (h == 0) error("front: empty list"); return ((DLNode*)h)->hd; } T& rear() { if (h == 0) error("rear: empty list"); return ((DLNode*)h->bk)->hd; } T remove_front() { T dst; BaseDLList::remove_front(&dst); return dst; } T remove_rear() { T dst; BaseDLList::remove_rear(&dst); return dst; } T& operator () (Pix p) { if (p == 0) error("null Pix"); return ((DLNode*)p)->hd; } Pix first() { return Pix(h); } Pix last() { return (h == 0)? 0 : Pix(h->bk); } void next(Pix& p) { p = (p == 0 || p == h->bk)? 0 : Pix(((DLNode*)p)->fd); } void prev(Pix& p) { p = (p == 0 || p == h)? 0 : Pix(((DLNode*)p)->bk); } Pix ins_after(Pix p, T& item) {return BaseDLList::ins_after(p, &item); } Pix ins_before(Pix p, T& item) {return BaseDLList::ins_before(p, &item);} }; #endif ./g++-include/DiscUnif.h100644 0 1 3504 5522102266 13427 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef _DiscreteUniform_h #ifdef __GNUG__ #pragma interface #endif #define _DiscreteUniform_h 1 #include // // The interval [lo..hi) // class DiscreteUniform: public Random { long pLow; long pHigh; double delta; public: DiscreteUniform(long low, long high, RNG *gen); long low(); long low(long x); long high(); long high(long x); virtual double operator()(); }; inline DiscreteUniform::DiscreteUniform(long low, long high, RNG *gen) : Random(gen) { pLow = (low < high) ? low : high; pHigh = (low < high) ? high : low; delta = (pHigh - pLow) + 1; } inline long DiscreteUniform::low() { return pLow; } inline long DiscreteUniform::low(long x) { long tmp = pLow; pLow = x; delta = (pHigh - pLow) + 1; return tmp; } inline long DiscreteUniform::high() { return pHigh; } inline long DiscreteUniform::high(long x) { long tmp = pHigh; pHigh = x; delta = (pHigh - pLow) + 1; return tmp; } #endif ./g++-include/Erlang.h100644 0 1 3543 5522102267 13137 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef _Erlang_h #ifdef __GNUG__ #pragma interface #endif #define _Erlang_h 1 #include class Erlang: public Random { protected: double pMean; double pVariance; int k; double a; void setState(); public: Erlang(double mean, double variance, RNG *gen); double mean(); double mean(double x); double variance(); double variance(double x); virtual double operator()(); }; inline void Erlang::setState() { k = int( (pMean * pMean ) / pVariance + 0.5 ); k = (k > 0) ? k : 1; a = k / pMean; } inline Erlang::Erlang(double mean, double variance, RNG *gen) : Random(gen) { pMean = mean; pVariance = variance; setState(); } inline double Erlang::mean() { return pMean; } inline double Erlang::mean(double x) { double tmp = pMean; pMean = x; setState(); return tmp; }; inline double Erlang::variance() { return pVariance; } inline double Erlang::variance(double x) { double tmp = pVariance; pVariance = x; setState(); return tmp; } #endif ./g++-include/Fix.h100644 0 1 23445 5522102270 12472 0ustar rootdaemon// // Fix.h : variable length fixed point data type // #ifndef _Fix_h #ifdef __GNUG__ #pragma interface #endif #define _Fix_h 1 #include #include #include #include #include typedef unsigned short uint16; typedef short int16; typedef unsigned long uint32; typedef long int32; #define _Fix_min_length 1 #define _Fix_max_length 65535 #define _Fix_min_value -1.0 #define _Fix_max_value 1.0 extern uint16 Fix_default_length; extern int Fix_default_print_width; struct _Frep // internal Fix representation { uint16 len; // length in bits uint16 siz; // allocated storage int16 ref; // reference count uint16 s[1]; // start of ushort array represention }; typedef _Frep* _Fix; extern _Frep _Frep_0; extern _Frep _Frep_m1; extern _Frep _Frep_quotient_bump; class Fix { _Fix rep; Fix(_Fix); void unique(); public: Fix(); Fix(Fix&); Fix(double); Fix(int); Fix(int, const Fix&); Fix(int, double); Fix(int, const _Fix); ~Fix(); Fix operator = (Fix&); Fix operator = (double); friend int operator == (const Fix&, const Fix& ); friend int operator != (const Fix&, const Fix&); friend int operator < (const Fix&, const Fix&); friend int operator <= (const Fix&, const Fix&); friend int operator > (const Fix&, const Fix&); friend int operator >= (const Fix&, const Fix&); Fix& operator + (); Fix operator - (); friend Fix operator + (Fix&, Fix&); friend Fix operator - (Fix&, Fix&); friend Fix operator * (Fix&, Fix&); friend Fix operator / (Fix&, Fix&); friend Fix operator * (Fix&, int); friend Fix operator * (int, Fix&); friend Fix operator % (Fix&, int); friend Fix operator << (Fix&, int); friend Fix operator >> (Fix&, int); #ifdef __GNUG__ friend Fix operator ? (Fix&, Fix&); // max #endif Fix operator += (Fix&); Fix operator -= (Fix&); Fix operator *= (Fix&); Fix operator /= (Fix&); Fix operator *= (int); Fix operator %= (int); Fix operator <<=(int); Fix operator >>=(int); friend char* Ftoa(Fix&, int width = Fix_default_print_width); void printon(ostream&, int width = Fix_default_print_width) const; friend Fix atoF(const char*, int len = Fix_default_length); friend istream& operator >> (istream&, Fix&); friend ostream& operator << (ostream&, const Fix&); // built-in functions friend Fix abs(Fix); // absolute value friend int sgn(Fix&); // -1, 0, +1 friend Integer mantissa(Fix&); // integer representation friend double value(const Fix&); // double value friend int length(const Fix&); // field length friend void show(Fix&); // show contents // error handlers void error(const char* msg); // error handler void range_error(const char* msg); // range error handler // internal class functions friend void mask(_Fix); friend int compare(const _Fix, const _Fix = &_Frep_0); friend _Fix new_Fix(uint16); friend _Fix new_Fix(uint16, const _Fix); friend _Fix new_Fix(uint16, double); friend _Fix copy(const _Fix, _Fix); friend _Fix negate(_Fix, _Fix = NULL); friend _Fix add(_Fix, _Fix, _Fix = NULL); friend _Fix subtract(_Fix, _Fix, _Fix = NULL); friend _Fix multiply(_Fix, _Fix, _Fix = NULL); friend _Fix multiply(_Fix, int, _Fix = NULL); friend _Fix divide(_Fix, _Fix, _Fix = NULL, _Fix = NULL); friend _Fix shift(_Fix, int, _Fix = NULL); // non-operator versions for user friend void negate(Fix& x, Fix& r); friend void add(Fix& x, Fix& y, Fix& r); friend void subtract(Fix& x, Fix& y, Fix& r); friend void multiply(Fix& x, Fix& y, Fix& r); friend void divide(Fix& x, Fix& y, Fix& q, Fix& r); friend void shift(Fix& x, int y, Fix& r); }; // error handlers extern void default_Fix_error_handler(const char*), default_Fix_range_error_handler(const char*); extern one_arg_error_handler_t Fix_error_handler, Fix_range_error_handler; extern one_arg_error_handler_t set_Fix_error_handler(one_arg_error_handler_t f), set_Fix_range_error_handler(one_arg_error_handler_t f); typedef void (*Fix_peh)(_Fix&); extern Fix_peh Fix_overflow_handler; extern void Fix_overflow_saturate(_Fix&), Fix_overflow_wrap(_Fix&), Fix_overflow_warning_saturate(_Fix&), Fix_overflow_warning(_Fix&), Fix_overflow_error(_Fix&); extern Fix_peh set_overflow_handler(Fix_peh); extern int Fix_set_default_length(int); // function definitions inline void Fix::unique() { if ( rep->ref > 1 ) { rep->ref--; rep = new_Fix(rep->len,rep); } } inline void mask (_Fix x) { int n = x->len & 0x0f; if ( n ) x->s[x->siz - 1] &= 0xffff0000 >> n; } inline _Fix copy(const _Fix from, _Fix to) { uint16 *ts = to->s, *fs = from->s; int ilim = to->siz < from->siz ? to->siz : from->siz; for ( int i=0; i < ilim; i++ ) *ts++ = *fs++; for ( ; i < to->siz; i++ ) *ts++ = 0; mask(to); return to; } inline Fix::Fix(_Fix f) { rep = f; } inline Fix::Fix() { rep = new_Fix(Fix_default_length); } inline Fix::Fix(int len) { if ( len < _Fix_min_length || len > _Fix_max_length ) error("illegal length in declaration"); rep = new_Fix((uint16 )len); } inline Fix::Fix(double d) { rep = new_Fix(Fix_default_length,d); } inline Fix::Fix(Fix& y) { rep = y.rep; rep->ref++; } inline Fix::Fix(int len, const Fix& y) { if ( len < _Fix_min_length || len > _Fix_max_length ) error("illegal length in declaration"); rep = new_Fix((uint16 )len,y.rep); } inline Fix::Fix(int len, const _Fix fr) { if ( len < 1 || len > 65535 ) error("illegal length in declaration"); rep = new_Fix((uint16 )len,fr); } inline Fix::Fix(int len, double d) { if ( len < _Fix_min_length || len > _Fix_max_length ) error("illegal length in declaration"); rep = new_Fix((uint16 )len,d); } inline Fix::~Fix() { if ( --rep->ref <= 0 ) delete rep; } inline Fix Fix::operator = (Fix& y) { if ( rep->len == y.rep->len ) { ++y.rep->ref; if ( --rep->ref <= 0 ) delete rep; rep = y.rep; } else { unique(); copy(y.rep,rep); } return *this; } inline Fix Fix::operator = (double d) { int oldlen = rep->len; if ( --rep->ref <= 0 ) delete rep; rep = new_Fix(oldlen,d); return *this; } inline int operator == (const Fix& x, const Fix& y) { return compare(x.rep, y.rep) == 0; } inline int operator != (const Fix& x, const Fix& y) { return compare(x.rep, y.rep) != 0; } inline int operator < (const Fix& x, const Fix& y) { return compare(x.rep, y.rep) < 0; } inline int operator <= (const Fix& x, const Fix& y) { return compare(x.rep, y.rep) <= 0; } inline int operator > (const Fix& x, const Fix& y) { return compare(x.rep, y.rep) > 0; } inline int operator >= (const Fix& x, const Fix& y) { return compare(x.rep, y.rep) >= 0; } inline Fix& Fix::operator + () { return *this; } inline Fix Fix::operator - () { _Fix r = negate(rep); return r; } inline Fix operator + (Fix& x, Fix& y) { _Fix r = add(x.rep, y.rep); return r; } inline Fix operator - (Fix& x, Fix& y) { _Fix r = subtract(x.rep, y.rep); return r; } inline Fix operator * (Fix& x, Fix& y) { _Fix r = multiply(x.rep, y.rep); return r; } inline Fix operator * (Fix& x, int y) { _Fix r = multiply(x.rep, y); return r; } inline Fix operator * (int y, Fix& x) { _Fix r = multiply(x.rep, y); return r; } inline Fix operator / (Fix& x, Fix& y) { _Fix r = divide(x.rep, y.rep); return r; } inline Fix Fix::operator += (Fix& y) { unique(); add(rep, y.rep, rep); return *this; } inline Fix Fix::operator -= (Fix& y) { unique(); subtract(rep, y.rep, rep); return *this; } inline Fix Fix::operator *= (Fix& y) { unique(); multiply(rep, y.rep, rep); return *this; } inline Fix Fix::operator *= (int y) { unique(); multiply(rep, y, rep); return *this; } inline Fix Fix::operator /= (Fix& y) { unique(); divide(rep, y.rep, rep); return *this; } inline Fix operator % (Fix& x, int y) { Fix r((int )x.rep->len + y, x); return r; } inline Fix operator << (Fix& x, int y) { _Fix rep = shift(x.rep, y); return rep; } inline Fix operator >> (Fix& x, int y) { _Fix rep = shift(x.rep, -y); return rep; } inline Fix Fix::operator <<= (int y) { unique(); shift(rep, y, rep); return *this; } inline Fix Fix::operator >>= (int y) { unique(); shift(rep, -y, rep); return *this; } #ifdef __GNUG__ inline Fix operator ? (Fix& x, Fix& y) { if ( compare(x.rep, y.rep) >= 0 ) return x; else return y; } #endif inline Fix abs(Fix x) { _Fix r = (compare(x.rep) >= 0 ? new_Fix(x.rep->len,x.rep) : negate(x.rep)); return r; } inline int sgn(Fix& x) { int a = compare(x.rep); return a == 0 ? 0 : (a > 0 ? 1 : -1); } inline int length(const Fix& x) { return x.rep->len; } inline ostream& operator << (ostream& s, const Fix& y) { if (s.opfx()) y.printon(s); return s; } inline void negate (Fix& x, Fix& r) { negate(x.rep, r.rep); } inline void add (Fix& x, Fix& y, Fix& r) { add(x.rep, y.rep, r.rep); } inline void subtract (Fix& x, Fix& y, Fix& r) { subtract(x.rep, y.rep, r.rep); } inline void multiply (Fix& x, Fix& y, Fix& r) { multiply(x.rep, y.rep, r.rep); } inline void divide (Fix& x, Fix& y, Fix& q, Fix& r) { divide(x.rep, y.rep, q.rep, r.rep); } inline void shift (Fix& x, int y, Fix& r) { shift(x.rep, y, r.rep); } #endif ./g++-include/Fix16.h100644 0 1 33045 5522102271 12637 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Kurt Baudendistel (gt-eedsp!baud@gatech.edu) adapted for libg++ by Doug Lea (dl@rocky.oswego.edu) 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. */ #ifndef _Fix16_h #ifdef __GNUG__ #pragma interface #endif #define _Fix16_h 1 #include #include // constant definitions #define Fix16_fs ((double)((unsigned)(1 << 15))) #define Fix16_msb (1 << 15) #define Fix16_m_max ((1 << 15) - 1) #define Fix16_m_min ((short)(1 << 15)) #define Fix16_mult Fix16_fs #define Fix16_div (1./Fix16_fs) #define Fix16_max (1. - .5/Fix16_fs) #define Fix16_min (-1.) #define Fix32_fs ((double)((unsigned long)(1 << 31))) #define Fix32_msb ((unsigned long)(1 << 31)) #define Fix32_m_max ((long)((1 << 31) - 1)) #define Fix32_m_min ((long)(1 << 31)) #define Fix32_mult Fix32_fs #define Fix32_div (1./Fix32_fs) #define Fix32_max (1. - .5/Fix32_fs) #define Fix32_min (-1.) // // Fix16 class: 16-bit Fixed point data type // // consists of a 16-bit mantissa (sign bit & 15 data bits). // class Fix16 { friend class Fix32; short m; short round(double d); short assign(double d); Fix16(short i); Fix16(int i); operator double() const; public: Fix16(); Fix16(const Fix16& f); Fix16(double d); Fix16(const Fix32& f); ~Fix16(); Fix16& operator=(const Fix16& f); Fix16& operator=(double d); Fix16& operator=(const Fix32& f); friend short& mantissa(Fix16& f); friend const short& mantissa(const Fix16& f); friend double value(const Fix16& f); Fix16 operator + () const; Fix16 operator - () const; friend Fix16 operator + (const Fix16& f, const Fix16& g); friend Fix16 operator - (const Fix16& f, const Fix16& g); friend Fix32 operator * (const Fix16& f, const Fix16& g); friend Fix16 operator / (const Fix16& f, const Fix16& g); friend Fix16 operator << (const Fix16& f, int b); friend Fix16 operator >> (const Fix16& f, int b); Fix16& operator += (const Fix16& f); Fix16& operator -= (const Fix16& f); Fix16& operator *= (const Fix16& ); Fix16& operator /= (const Fix16& f); Fix16& operator <<=(int b); Fix16& operator >>=(int b); friend int operator == (const Fix16& f, const Fix16& g); friend int operator != (const Fix16& f, const Fix16& g); friend int operator >= (const Fix16& f, const Fix16& g); friend int operator <= (const Fix16& f, const Fix16& g); friend int operator > (const Fix16& f, const Fix16& g); friend int operator < (const Fix16& f, const Fix16& g); friend istream& operator >> (istream& s, Fix16& f); friend ostream& operator << (ostream& s, const Fix16& f); void overflow(short&) const; void range_error(short&) const; friend Fix16 operator * (const Fix16& f, int g); friend Fix16 operator * (int g, const Fix16& f); Fix16& operator *= (int g); }; // // Fix32 class: 32-bit Fixed point data type // // consists of a 32-bit mantissa (sign bit & 31 data bits). // class Fix32 { friend class Fix16; long m; long round(double d); long assign(double d); Fix32(long i); operator double() const; public: Fix32(); Fix32(const Fix32& f); Fix32(const Fix16& f); Fix32(double d); ~Fix32(); Fix32& operator = (const Fix32& f); Fix32& operator = (const Fix16& f); Fix32& operator = (double d); friend long& mantissa(Fix32& f); friend const long& mantissa(const Fix32& f); friend double value(const Fix32& f); Fix32 operator + () const; Fix32 operator - () const; friend Fix32 operator + (const Fix32& f, const Fix32& g); friend Fix32 operator - (const Fix32& f, const Fix32& g); friend Fix32 operator * (const Fix32& f, const Fix32& g); friend Fix32 operator / (const Fix32& f, const Fix32& g); friend Fix32 operator << (const Fix32& f, int b); friend Fix32 operator >> (const Fix32& f, int b); friend Fix32 operator * (const Fix16& f, const Fix16& g); Fix32& operator += (const Fix32& f); Fix32& operator -= (const Fix32& f); Fix32& operator *= (const Fix32& f); Fix32& operator /= (const Fix32& f); Fix32& operator <<=(int b); Fix32& operator >>=(int b); friend int operator == (const Fix32& f, const Fix32& g); friend int operator != (const Fix32& f, const Fix32& g); friend int operator >= (const Fix32& f, const Fix32& g); friend int operator <= (const Fix32& f, const Fix32& g); friend int operator > (const Fix32& f, const Fix32& g); friend int operator < (const Fix32& f, const Fix32& g); friend istream& operator >> (istream& s, Fix32& f); friend ostream& operator << (ostream& s, const Fix32& f); void overflow(long& i) const; void range_error(long& i) const; friend Fix32 operator * (const Fix32& f, int g); friend Fix32 operator * (int g, const Fix32& f); Fix32& operator *= (int g); }; // active error handler declarations typedef void (*Fix16_peh)(short&); typedef void (*Fix32_peh)(long&); extern Fix16_peh Fix16_overflow_handler; extern Fix32_peh Fix32_overflow_handler; extern Fix16_peh Fix16_range_error_handler; extern Fix32_peh Fix32_range_error_handler; #if defined(SHORT_NAMES) || defined(VMS) #define set_overflow_handler sohndl #define set_range_error_handler srnghdl #endif // error handler declarations extern Fix16_peh set_Fix16_overflow_handler(Fix16_peh); extern Fix32_peh set_Fix32_overflow_handler(Fix32_peh); extern void set_overflow_handler(Fix16_peh, Fix32_peh); extern Fix16_peh set_Fix16_range_error_handler(Fix16_peh); extern Fix32_peh set_Fix32_range_error_handler(Fix32_peh); extern void set_range_error_handler(Fix16_peh, Fix32_peh); extern void Fix16_ignore(short&), Fix16_overflow_saturate(short&), Fix16_overflow_warning_saturate(short&), Fix16_warning(short&), Fix16_abort(short&); extern void Fix32_ignore(long&), Fix32_overflow_saturate(long&), Fix32_overflow_warning_saturate(long&), Fix32_warning(long&), Fix32_abort(long&); inline Fix16::~Fix16() {} inline short Fix16::round(double d) { return short( (d >= 0)? d + 0.5 : d - 0.5); } inline Fix16::Fix16(short i) { m = i; } inline Fix16::Fix16(int i) { m = i; } inline Fix16::operator double() const { return Fix16_div * m; } inline Fix16::Fix16() { m = 0; } inline Fix16::Fix16(const Fix16& f) { m = f.m; } inline Fix16::Fix16(double d) { m = assign(d); } inline Fix16& Fix16::operator=(const Fix16& f) { m = f.m; return *this; } inline Fix16& Fix16::operator=(double d) { m = assign(d); return *this; } inline Fix32::Fix32() { m = 0; } inline Fix32::Fix32(long i) { m = i; } inline Fix32:: operator double() const { return Fix32_div * m; } inline Fix32::Fix32(const Fix32& f) { m = f.m; } inline Fix32::Fix32(const Fix16& f) { m = long(f.m) << 16; } inline Fix32::Fix32(double d) { m = assign(d); } inline Fix16::Fix16(const Fix32& f) { m = f.m >> 16; } inline Fix16& Fix16::operator=(const Fix32& f) { m = f.m >> 16; return *this; } inline Fix32& Fix32::operator=(const Fix32& f) { m = f.m; return *this; } inline Fix32& Fix32::operator=(const Fix16& f) { m = long(f.m) << 16; return *this; } inline Fix32& Fix32::operator=(double d) { m = assign(d); return *this; } inline short& mantissa(Fix16& f) { return f.m; } inline const short& mantissa(const Fix16& f) { return f.m; } inline double value(const Fix16& f) { return double(f); } inline Fix16 Fix16::operator+() const { return m; } inline Fix16 Fix16::operator-() const { return -m; } inline Fix16 operator+(const Fix16& f, const Fix16& g) { short sum = f.m + g.m; if ( (f.m ^ sum) & (g.m ^ sum) & Fix16_msb ) f.overflow(sum); return sum; } inline Fix16 operator-(const Fix16& f, const Fix16& g) { short sum = f.m - g.m; if ( (f.m ^ sum) & (-g.m ^ sum) & Fix16_msb ) f.overflow(sum); return sum; } inline Fix32 operator*(const Fix16& f, const Fix16& g) { return Fix32( long( long(f.m) * long(g.m) << 1)); } inline Fix16 operator<<(const Fix16& a, int b) { return a.m << b; } inline Fix16 operator>>(const Fix16& a, int b) { return a.m >> b; } inline Fix16& Fix16:: operator+=(const Fix16& f) { return *this = *this + f; } inline Fix16& Fix16:: operator-=(const Fix16& f) { return *this = *this - f; } inline Fix16& Fix16::operator*=(const Fix16& f) { return *this = *this * f; } inline Fix16& Fix16:: operator/=(const Fix16& f) { return *this = *this / f; } inline Fix16& Fix16:: operator<<=(int b) { return *this = *this << b; } inline Fix16& Fix16:: operator>>=(int b) { return *this = *this >> b; } inline int operator==(const Fix16& f, const Fix16& g) { return f.m == g.m; } inline int operator!=(const Fix16& f, const Fix16& g) { return f.m != g.m; } inline int operator>=(const Fix16& f, const Fix16& g) { return f.m >= g.m; } inline int operator<=(const Fix16& f, const Fix16& g) { return f.m <= g.m; } inline int operator>(const Fix16& f, const Fix16& g) { return f.m > g.m; } inline int operator<(const Fix16& f, const Fix16& g) { return f.m < g.m; } inline istream& operator>>(istream& s, Fix16& f) { double d; s >> d; f = d; return s; } inline ostream& operator<<(ostream& s, const Fix16& f) { return s << double(f); } inline Fix16 operator*(const Fix16& f, int g) { return Fix16(short(f.m * g)); } inline Fix16 operator*(int g, const Fix16& f) { return f * g; } inline Fix16& Fix16::operator*=(int g) { return *this = *this * g; } inline Fix32::~Fix32() {} inline long Fix32::round(double d) { return long( (d >= 0)? d + 0.5 : d - 0.5); } inline long& mantissa(Fix32& f) { return f.m; } inline const long& mantissa(const Fix32& f) { return f.m; } inline double value(const Fix32& f) { return double(f); } inline Fix32 Fix32::operator+() const { return m; } inline Fix32 Fix32::operator-() const { return -m; } inline Fix32 operator+(const Fix32& f, const Fix32& g) { long sum = f.m + g.m; if ( (f.m ^ sum) & (g.m ^ sum) & Fix32_msb ) f.overflow(sum); return sum; } inline Fix32 operator-(const Fix32& f, const Fix32& g) { long sum = f.m - g.m; if ( (f.m ^ sum) & (-g.m ^ sum) & Fix32_msb ) f.overflow(sum); return sum; } inline Fix32 operator<<(const Fix32& a, int b) { return a.m << b; } inline Fix32 operator>>(const Fix32& a, int b) { return a.m >> b; } inline Fix32& Fix32::operator+=(const Fix32& f) { return *this = *this + f; } inline Fix32& Fix32::operator-=(const Fix32& f) { return *this = *this - f; } inline Fix32& Fix32::operator*=(const Fix32& f) { return *this = *this * f; } inline Fix32& Fix32::operator/=(const Fix32& f) { return *this = *this / f; } inline Fix32& Fix32::operator<<=(int b) { return *this = *this << b; } inline Fix32& Fix32::operator>>=(int b) { return *this = *this >> b; } inline int operator==(const Fix32& f, const Fix32& g) { return f.m == g.m; } inline int operator!=(const Fix32& f, const Fix32& g) { return f.m != g.m; } inline int operator>=(const Fix32& f, const Fix32& g) { return f.m >= g.m; } inline int operator<=(const Fix32& f, const Fix32& g) { return f.m <= g.m; } inline int operator>(const Fix32& f, const Fix32& g) { return f.m > g.m; } inline int operator<(const Fix32& f, const Fix32& g) { return f.m < g.m; } inline istream& operator>>(istream& s, Fix32& f) { double d; s >> d; f = d; return s; } inline ostream& operator<<(ostream& s, const Fix32& f) { return s << double(f); } inline Fix32 operator*(const Fix32& f, int g) { return Fix32(long(f.m * g)); } inline Fix32 operator*(int g, const Fix32& f) { return f * g; } inline Fix32& Fix32::operator*=(int g) { return *this = *this * g; } #endif ./g++-include/Fix24.h100644 0 1 32033 5522102271 12632 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Kurt Baudendistel (gt-eedsp!baud@gatech.edu) adapted for libg++ by Doug Lea (dl@rocky.oswego.edu) 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. */ #ifndef _Fix24_h #ifdef __GNUG__ #pragma interface #endif #define _Fix24_h 1 #include #include // extra type definitions typedef struct { long u; unsigned long l; } twolongs; // constant definitions static const int Fix24_shift = 31; static const double Fix24_fs = 2147483648., // 2^Fix24_shift Fix24_mult = Fix24_fs, Fix24_div = 1./Fix24_fs, Fix24_max = 1. - .5/Fix24_fs, Fix24_min = -1.; static const unsigned long Fix24_msb = 0x80000000L, Fix24_lsb = 0x00000100L, Fix24_m_max = 0x7fffff00L, Fix24_m_min = 0x80000000L; static const double Fix48_fs = 36028797018963968., // 2^(24+Fix24_shift) Fix48_max = 1. - .5/Fix48_fs, Fix48_min = -1., Fix48_div_u = 1./Fix24_fs, Fix48_div_l = 1./Fix48_fs; static const twolongs Fix48_msb = { 0x80000000L, 0L }, Fix48_lsb = { 0L, 0x00000100L }, Fix48_m_max = { 0x7fffff00L, 0xffffff00L }, Fix48_m_min = { 0x80000000L, 0L }; // // Fix24 class: 24-bit Fixed point data type // // consists of a 24-bit mantissa (sign bit & 23 data bits). // class Fix24 { friend class Fix48; long m; long assign(double d); operator double() const; Fix24(long i); Fix24(int i); public: Fix24(); Fix24(const Fix24& f); Fix24(double d); Fix24(const Fix48& f); ~Fix24(); Fix24& operator=(const Fix24& f); Fix24& operator=(double d); Fix24& operator=(const Fix48& f); friend long& mantissa(Fix24& f); friend const long& mantissa(const Fix24& f); friend double value(const Fix24& f); Fix24 operator + () const; Fix24 operator - () const; friend Fix24 operator + (const Fix24& f, const Fix24& g); friend Fix24 operator - (const Fix24& f, const Fix24& g); friend Fix48 operator * (const Fix24& f, const Fix24& g); friend Fix24 operator * (const Fix24& f, int g); friend Fix24 operator * (int g, const Fix24& f); friend Fix24 operator / (const Fix24& f, const Fix24& g); friend Fix24 operator << (const Fix24& f, int b); friend Fix24 operator >> (const Fix24& f, int b); Fix24& operator += (const Fix24& f); Fix24& operator -= (const Fix24& f); Fix24& operator *= (const Fix24& f); Fix24& operator *= (int b); Fix24& operator /= (const Fix24& f); Fix24& operator <<=(int b); Fix24& operator >>=(int b); friend int operator == (const Fix24& f, const Fix24& g); friend int operator != (const Fix24& f, const Fix24& g); friend int operator >= (const Fix24& f, const Fix24& g); friend int operator <= (const Fix24& f, const Fix24& g); friend int operator > (const Fix24& f, const Fix24& g); friend int operator < (const Fix24& f, const Fix24& g); friend istream& operator >> (istream& s, Fix24& f); friend ostream& operator << (ostream& s, const Fix24& f); void overflow(long&) const; void range_error(long&) const; }; // // Fix48 class: 48-bit Fixed point data type // // consists of a 48-bit mantissa (sign bit & 47 data bits). // class Fix48 { friend class Fix24; twolongs m; twolongs assign(double d); operator double() const; Fix48(twolongs i); public: Fix48(); Fix48(const Fix48& f); Fix48(const Fix24& f); Fix48(double d); ~Fix48(); Fix48& operator = (const Fix48& f); Fix48& operator = (const Fix24& f); Fix48& operator = (double d); friend twolongs& mantissa(Fix48& f); friend const twolongs& mantissa(const Fix48& f); friend double value(const Fix48& f); Fix48 operator + () const; Fix48 operator - () const; friend Fix48 operator + (const Fix48& f, const Fix48& g); friend Fix48 operator - (const Fix48& f, const Fix48& g); friend Fix48 operator * (const Fix48& f, int g); friend Fix48 operator * (int g, const Fix48& f); friend Fix48 operator << (const Fix48& f, int b); friend Fix48 operator >> (const Fix48& f, int b); friend Fix48 operator * (const Fix24& f, const Fix24& g); Fix48& operator += (const Fix48& f); Fix48& operator -= (const Fix48& f); Fix48& operator *= (int b); Fix48& operator <<=(int b); Fix48& operator >>=(int b); friend int operator == (const Fix48& f, const Fix48& g); friend int operator != (const Fix48& f, const Fix48& g); friend int operator >= (const Fix48& f, const Fix48& g); friend int operator <= (const Fix48& f, const Fix48& g); friend int operator > (const Fix48& f, const Fix48& g); friend int operator < (const Fix48& f, const Fix48& g); friend istream& operator >> (istream& s, Fix48& f); friend ostream& operator << (ostream& s, const Fix48& f); void overflow(twolongs& i) const; void range_error(twolongs& i) const; }; // active error handler declarations typedef void (*Fix24_peh)(long&); typedef void (*Fix48_peh)(twolongs&); extern Fix24_peh Fix24_overflow_handler; extern Fix48_peh Fix48_overflow_handler; extern Fix24_peh Fix24_range_error_handler; extern Fix48_peh Fix48_range_error_handler; // error handler declarations #if defined(SHORT_NAMES) || defined(VMS) #define set_overflow_handler sohndl #define set_range_error_handler srnghdl #endif extern Fix24_peh set_Fix24_overflow_handler(Fix24_peh); extern Fix48_peh set_Fix48_overflow_handler(Fix48_peh); extern void set_overflow_handler(Fix24_peh, Fix48_peh); extern Fix24_peh set_Fix24_range_error_handler(Fix24_peh); extern Fix48_peh set_Fix48_range_error_handler(Fix48_peh); extern void set_range_error_handler(Fix24_peh, Fix48_peh); extern void Fix24_ignore(long&), Fix24_overflow_saturate(long&), Fix24_overflow_warning_saturate(long&), Fix24_warning(long&), Fix24_abort(long&); extern void Fix48_ignore(twolongs&), Fix48_overflow_saturate(twolongs&), Fix48_overflow_warning_saturate(twolongs&), Fix48_warning(twolongs&), Fix48_abort(twolongs&); inline Fix24::~Fix24() {} inline Fix24::Fix24(long i) { m = i; } inline Fix24::Fix24(int i) { m = i; } inline Fix24::operator double() const { return Fix24_div * m; } inline Fix24::Fix24() { m = 0; } inline Fix24::Fix24(const Fix24& f) { m = f.m; } inline Fix24::Fix24(double d) { m = assign(d); } inline Fix24::Fix24(const Fix48& f) { m = f.m.u; } inline Fix24& Fix24::operator=(const Fix24& f) { m = f.m; return *this; } inline Fix24& Fix24::operator=(double d) { m = assign(d); return *this; } inline Fix24& Fix24::operator=(const Fix48& f) { m = f.m.u; return *this; } inline long& mantissa(Fix24& f) { return f.m; } inline const long& mantissa(const Fix24& f) { return f.m; } inline double value(const Fix24& f) { return double(f); } inline Fix24 Fix24::operator+() const { return m; } inline Fix24 Fix24::operator-() const { return -m; } inline Fix24 operator+(const Fix24& f, const Fix24& g) { long sum = f.m + g.m; if ( (f.m ^ sum) & (g.m ^ sum) & Fix24_msb ) f.overflow(sum); return sum; } inline Fix24 operator-(const Fix24& f, const Fix24& g) { long sum = f.m - g.m; if ( (f.m ^ sum) & (-g.m ^ sum) & Fix24_msb ) f.overflow(sum); return sum; } inline Fix24 operator*(const Fix24& a, int b) { return a.m * b; } inline Fix24 operator*(int b, const Fix24& a) { return a * b; } inline Fix24 operator<<(const Fix24& a, int b) { return a.m << b; } inline Fix24 operator>>(const Fix24& a, int b) { return (a.m >> b) & 0xffffff00L; } inline Fix24& Fix24:: operator+=(const Fix24& f) { return *this = *this + f; } inline Fix24& Fix24:: operator-=(const Fix24& f) { return *this = *this - f; } inline Fix24& Fix24::operator*=(const Fix24& f) { return *this = *this * f; } inline Fix24& Fix24:: operator/=(const Fix24& f) { return *this = *this / f; } inline Fix24& Fix24:: operator<<=(int b) { return *this = *this << b; } inline Fix24& Fix24:: operator>>=(int b) { return *this = *this >> b; } inline Fix24& Fix24::operator*=(int b) { return *this = *this * b; } inline int operator==(const Fix24& f, const Fix24& g) { return f.m == g.m; } inline int operator!=(const Fix24& f, const Fix24& g) { return f.m != g.m; } inline int operator>=(const Fix24& f, const Fix24& g) { return f.m >= g.m; } inline int operator<=(const Fix24& f, const Fix24& g) { return f.m <= g.m; } inline int operator>(const Fix24& f, const Fix24& g) { return f.m > g.m; } inline int operator<(const Fix24& f, const Fix24& g) { return f.m < g.m; } inline istream& operator>>(istream& s, Fix24& f) { double d; s >> d; f = d; return s; } inline ostream& operator<<(ostream& s, const Fix24& f) { return s << double(f); } inline Fix48::~Fix48() {} inline Fix48::Fix48(twolongs i) { m = i; } inline Fix48:: operator double() const { /* * Note: can't simply do Fix48_div_u * m.u + Fix48_div_l * m.l, because * m.u is signed and m.l is unsigned. */ return (m.u >= 0)? Fix48_div_u * m.u + Fix48_div_l * m.l : (Fix48_div_u * ((unsigned long)(m.u & 0xffffff00)) + Fix48_div_l * m.l) - 2; } inline Fix48::Fix48() { m.u = 0; m.l = 0; } inline Fix48::Fix48(const Fix48& f) { m = f.m; } inline Fix48::Fix48(const Fix24& f) { m.u = f.m; m.l = 0; } inline Fix48::Fix48(double d) { m = assign(d); } inline Fix48& Fix48::operator=(const Fix48& f) { m = f.m; return *this; } inline Fix48& Fix48::operator=(const Fix24& f) { m.u = f.m; m.l = 0; return *this; } inline Fix48& Fix48::operator=(double d) { m = assign(d); return *this; } inline twolongs& mantissa(Fix48& f) { return f.m; } inline const twolongs& mantissa(const Fix48& f) { return f.m; } inline double value(const Fix48& f) { return double(f); } inline Fix48 Fix48::operator+() const { return m; } inline Fix48 Fix48::operator-() const { twolongs n; n.l = -m.l; n.u = ~m.u + ((n.l ^ m.l) & Fix24_msb ? 0 : Fix24_lsb); return Fix48(n); } inline Fix48 operator*(int b, const Fix48& a) { return a * b; } inline Fix48& Fix48::operator+=(const Fix48& f) { return *this = *this + f; } inline Fix48& Fix48::operator-=(const Fix48& f) { return *this = *this - f; } inline Fix48& Fix48::operator*=(int b) { return *this = *this * b; } inline Fix48& Fix48::operator<<=(int b) { return *this = *this << b; } inline Fix48& Fix48::operator>>=(int b) { return *this = *this >> b; } inline int operator==(const Fix48& f, const Fix48& g) { return f.m.u == g.m.u && f.m.l == g.m.l; } inline int operator!=(const Fix48& f, const Fix48& g) { return f.m.u != g.m.u || f.m.l != g.m.l; } inline int operator>=(const Fix48& f, const Fix48& g) { return f.m.u >= g.m.u || (f.m.u == g.m.u && f.m.l >= g.m.l); } inline int operator<=(const Fix48& f, const Fix48& g) { return f.m.u <= g.m.u || (f.m.u == g.m.u && f.m.l <= g.m.l); } inline int operator>(const Fix48& f, const Fix48& g) { return f.m.u > g.m.u || (f.m.u == g.m.u && f.m.l > g.m.l); } inline int operator<(const Fix48& f, const Fix48& g) { return f.m.u < g.m.u || (f.m.u == g.m.u && f.m.l < g.m.l); } inline istream& operator>>(istream& s, Fix48& f) { double d; s >> d; f = d; return s; } inline ostream& operator<<(ostream& s, const Fix48& f) { return s << double(f); } #endif ./g++-include/Geom.h100644 0 1 2613 5522102272 12607 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef _Geometric_h #ifdef __GNUG__ #pragma interface #endif #define _Geometric_h #include class Geometric: public Random { protected: double pMean; public: Geometric(double mean, RNG *gen); double mean(); double mean(double x); virtual double operator()(); }; inline Geometric::Geometric(double mean, RNG *gen) : Random(gen) { pMean = mean; } inline double Geometric::mean() { return pMean; } inline double Geometric::mean(double x) { double tmp = pMean; pMean = x; return tmp; } #endif ./g++-include/GetOpt.h100644 0 1 11410 5522102273 13136 0ustar rootdaemon/* Getopt for GNU. Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc. (Modified by Douglas C. Schmidt for use with GNU G++.) 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. */ /* This version of `getopt' appears to the caller like standard Unix `getopt' but it behaves differently for the user, since it allows the user to intersperse the options with the other arguments. As `getopt' works, it permutes the elements of `argv' so that, when it is done, all the options precede everything else. Thus all application programs are extended to handle flexible argument order. Setting the environment variable _POSIX_OPTION_ORDER disables permutation. Then the behavior is completely standard. GNU application programs can use a third alternative mode in which they can distinguish the relative order of options and other arguments. */ #ifndef GetOpt_h #ifdef __GNUG__ #pragma interface #endif #define GetOpt_h 1 #include #include class GetOpt { private: /* The next char to be scanned in the option-element in which the last option character we returned was found. This allows us to pick up the scan where we left off. If this is zero, or a null string, it means resume the scan by advancing to the next ARGV-element. */ static char *nextchar; /* Describe how to deal with options that follow non-option ARGV-elements. UNSPECIFIED means the caller did not specify anything; the default is then REQUIRE_ORDER if the environment variable _OPTIONS_FIRST is defined, PERMUTE otherwise. REQUIRE_ORDER means don't recognize them as options. Stop option processing when the first non-option is seen. This is what Unix does. PERMUTE is the default. We permute the contents of `argv' as we scan, so that eventually all the options are at the end. This allows options to be given in any order, even with programs that were not written to expect this. RETURN_IN_ORDER is an option available to programs that were written to expect options and other ARGV-elements in any order and that care about the ordering of the two. We describe each non-option ARGV-element as if it were the argument of an option with character code zero. Using `-' as the first character of the list of option characters requests this mode of operation. The special argument `--' forces an end of option-scanning regardless of the value of `ordering'. In the case of RETURN_IN_ORDER, only `--' can cause `getopt' to return EOF with `optind' != ARGC. */ enum OrderingEnum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER }; OrderingEnum ordering; /* Handle permutation of arguments. */ /* Describe the part of ARGV that contains non-options that have been skipped. `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is the index after the last of them. */ static int first_nonopt; static int last_nonopt; void exchange (char **argv); public: /* For communication from `getopt' to the caller. When `getopt' finds an option that takes an argument, the argument value is returned here. Also, when `ordering' is RETURN_IN_ORDER, each non-option ARGV-element is returned here. */ char *optarg; /* Index in ARGV of the next element to be scanned. This is used for communication to and from the caller and for communication between successive calls to `getopt'. On entry to `getopt', zero means this is the first call; initialize. When `getopt' returns EOF, this is the index of the first of the non-option elements that the caller should itself scan. Otherwise, `optind' communicates from one call to the next how much of ARGV has been scanned so far. */ int optind; /* Callers store zero here to inhibit the error message for unrecognized options. */ int opterr; int nargc; char **nargv; const char *noptstring; GetOpt (int argc, char **argv, const char *optstring); int operator () (void); }; #endif ./g++-include/HypGeom.h100644 0 1 3662 5522102274 13277 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef _HyperGeometric_h #ifdef __GNUG__ #pragma interface #endif #define _HyperGeometric_h #include class HyperGeometric: public Random { protected: double pMean; double pVariance; double pP; void setState(); public: HyperGeometric(double mean, double variance, RNG *gen); double mean(); double mean(double x); double variance(); double variance(double x); virtual double operator()(); }; inline void HyperGeometric::setState() { double z = pVariance / (pMean * pMean); pP = 0.5 * (1.0 - sqrt((z - 1.0) / ( z + 1.0 ))); } inline HyperGeometric::HyperGeometric(double mean, double variance, RNG *gen) : Random(gen) { pMean = mean; pVariance = variance; setState(); } inline double HyperGeometric::mean() { return pMean; }; inline double HyperGeometric::mean(double x) { double t = pMean; pMean = x; setState(); return t; } inline double HyperGeometric::variance() { return pVariance; } inline double HyperGeometric::variance(double x) { double t = pVariance; pVariance = x; setState(); return t; } #endif ./g++-include/Incremental.h100644 0 1 564 5522102275 14147 0ustar rootdaemon#ifndef Incremental_h #ifdef __GNUG__ #pragma interface #endif #define Incremental_h #define DECLARE_INIT_FUNCTION(USER_INIT_FUNCTION) \ static void USER_INIT_FUNCTION (); extern void (*_initfn)(); \ static struct xyzzy { xyzzy () {_initfn = USER_INIT_FUNCTION;}; \ ~xyzzy () {};} __2xyzzy; #else #error Incremental.h was not the first file included in this module #endif ./g++-include/Integer.h100644 0 1 64444 5522102275 13352 0ustar rootdaemon// 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) 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. */ #ifndef _Integer_h #ifdef __GNUG__ #pragma interface #endif #define _Integer_h 1 #include struct IntRep // internal Integer representations { unsigned short len; // current length unsigned short sz; // allocated space (0 means static). short sgn; // 1 means >= 0; 0 means < 0 unsigned short s[1]; // represented as ushort array starting here }; // True if REP is staticly (or manually) allocated, // and should not be deleted by an Integer destructor. #define STATIC_IntRep(rep) ((rep)->sz==0) extern IntRep* Ialloc(IntRep*, const unsigned short *, int, int, int); extern IntRep* Icalloc(IntRep*, int); extern IntRep* Icopy_ulong(IntRep*, unsigned long); extern IntRep* Icopy_long(IntRep*, long); extern IntRep* Icopy(IntRep*, const IntRep*); extern IntRep* Iresize(IntRep*, int); extern IntRep* add(const IntRep*, int, const IntRep*, int, IntRep*); extern IntRep* add(const IntRep*, int, long, IntRep*); extern IntRep* multiply(const IntRep*, const IntRep*, IntRep*); extern IntRep* multiply(const IntRep*, long, IntRep*); extern IntRep* lshift(const IntRep*, long, IntRep*); extern IntRep* lshift(const IntRep*, const IntRep*, int, IntRep*); extern IntRep* bitop(const IntRep*, const IntRep*, IntRep*, char); extern IntRep* bitop(const IntRep*, long, IntRep*, char); extern IntRep* power(const IntRep*, long, IntRep*); extern IntRep* div(const IntRep*, const IntRep*, IntRep*); extern IntRep* mod(const IntRep*, const IntRep*, IntRep*); extern IntRep* div(const IntRep*, long, IntRep*); extern IntRep* mod(const IntRep*, long, IntRep*); extern IntRep* compl(const IntRep*, IntRep*); extern IntRep* abs(const IntRep*, IntRep*); extern IntRep* negate(const IntRep*, IntRep*); extern IntRep* pow(const IntRep*, long); extern IntRep* gcd(const IntRep*, const IntRep* y); extern int compare(const IntRep*, const IntRep*); extern int compare(const IntRep*, long); extern int ucompare(const IntRep*, const IntRep*); extern int ucompare(const IntRep*, long); extern char* Itoa(const IntRep* x, int base = 10, int width = 0); extern char* cvtItoa(const IntRep* x, char* fmt, int& fmtlen, int base, int showbase, int width, int align_right, char fillchar, char Xcase, int showpos); extern IntRep* atoIntRep(const char* s, int base = 10); extern long Itolong(const IntRep*); extern int Iislong(const IntRep*); extern long lg(const IntRep*); extern IntRep _ZeroRep, _OneRep, _MinusOneRep; class Integer { protected: IntRep* rep; public: Integer(); Integer(int); Integer(long); Integer(unsigned long); Integer(IntRep*); Integer(const Integer&); ~Integer(); void operator = (const Integer&); void operator = (long); // unary operations to self void operator ++ (); void operator -- (); void negate(); // negate in-place void abs(); // absolute-value in-place void complement(); // bitwise complement in-place // assignment-based operations void operator += (const Integer&); void operator -= (const Integer&); void operator *= (const Integer&); void operator /= (const Integer&); void operator %= (const Integer&); void operator <<=(const Integer&); void operator >>=(const Integer&); void operator &= (const Integer&); void operator |= (const Integer&); void operator ^= (const Integer&); void operator += (long); void operator -= (long); void operator *= (long); void operator /= (long); void operator %= (long); void operator <<=(long); void operator >>=(long); void operator &= (long); void operator |= (long); void operator ^= (long); // (constructive binary operations are inlined below) #ifdef __GNUG__ friend Integer operator ? (const Integer& x, const Integer& y); // max #endif // builtin Integer functions that must be friends friend long lg (const Integer&); // floor log base 2 of abs(x) friend double ratio(const Integer& x, const Integer& y); // return x/y as a double friend Integer gcd(const Integer&, const Integer&); friend int even(const Integer&); // true if even friend int odd(const Integer&); // true if odd friend int sign(const Integer&); // returns -1, 0, +1 friend void (setbit)(Integer& x, long b); // set b'th bit of x friend void clearbit(Integer& x, long b); // clear b'th bit friend int testbit(const Integer& x, long b); // return b'th bit // procedural versions of operators friend void abs(const Integer& x, Integer& dest); friend void negate(const Integer& x, Integer& dest); friend void complement(const Integer& x, Integer& dest); friend int compare(const Integer&, const Integer&); friend int ucompare(const Integer&, const Integer&); friend void add(const Integer& x, const Integer& y, Integer& dest); friend void sub(const Integer& x, const Integer& y, Integer& dest); friend void mul(const Integer& x, const Integer& y, Integer& dest); friend void div(const Integer& x, const Integer& y, Integer& dest); friend void mod(const Integer& x, const Integer& y, Integer& dest); friend void divide(const Integer& x, const Integer& y, Integer& q, Integer& r); friend void and(const Integer& x, const Integer& y, Integer& dest); friend void or(const Integer& x, const Integer& y, Integer& dest); friend void xor(const Integer& x, const Integer& y, Integer& dest); friend void lshift(const Integer& x, const Integer& y, Integer& dest); friend void rshift(const Integer& x, const Integer& y, Integer& dest); friend void pow(const Integer& x, const Integer& y, Integer& dest); friend int compare(const Integer&, long); friend int ucompare(const Integer&, long); friend void add(const Integer& x, long y, Integer& dest); friend void sub(const Integer& x, long y, Integer& dest); friend void mul(const Integer& x, long y, Integer& dest); friend void div(const Integer& x, long y, Integer& dest); friend void mod(const Integer& x, long y, Integer& dest); friend void divide(const Integer& x, long y, Integer& q, long& r); friend void and(const Integer& x, long y, Integer& dest); friend void or(const Integer& x, long y, Integer& dest); friend void xor(const Integer& x, long y, Integer& dest); friend void lshift(const Integer& x, long y, Integer& dest); friend void rshift(const Integer& x, long y, Integer& dest); friend void pow(const Integer& x, long y, Integer& dest); friend int compare(long, const Integer&); friend int ucompare(long, const Integer&); friend void add(long x, const Integer& y, Integer& dest); friend void sub(long x, const Integer& y, Integer& dest); friend void mul(long x, const Integer& y, Integer& dest); friend void and(long x, const Integer& y, Integer& dest); friend void or(long x, const Integer& y, Integer& dest); friend void xor(long x, const Integer& y, Integer& dest); // coercion & conversion int fits_in_long() const { return Iislong(rep); } int fits_in_double() const; long as_long() const { return Itolong(rep); } double as_double() const; friend char* Itoa(const Integer& x, int base = 10, int width = 0); friend Integer atoI(const char* s, int base = 10); void printon(ostream& s, int base = 10, int width = 0) const; friend istream& operator >> (istream& s, Integer& y); friend ostream& operator << (ostream& s, const Integer& y); // error detection int initialized() const; void error(const char* msg) const; int OK() const; }; // (These are declared inline) int operator == (const Integer&, const Integer&); int operator == (const Integer&, long); int operator != (const Integer&, const Integer&); int operator != (const Integer&, long); int operator < (const Integer&, const Integer&); int operator < (const Integer&, long); int operator <= (const Integer&, const Integer&); int operator <= (const Integer&, long); int operator > (const Integer&, const Integer&); int operator > (const Integer&, long); int operator >= (const Integer&, const Integer&); int operator >= (const Integer&, long); Integer operator - (const Integer&); Integer operator ~ (const Integer&); Integer operator + (const Integer&, const Integer&); Integer operator + (const Integer&, long); Integer operator + (long, const Integer&); Integer operator - (const Integer&, const Integer&); Integer operator - (const Integer&, long); Integer operator - (long, const Integer&); Integer operator * (const Integer&, const Integer&); Integer operator * (const Integer&, long); Integer operator * (long, const Integer&); Integer operator / (const Integer&, const Integer&); Integer operator / (const Integer&, long); Integer operator % (const Integer&, const Integer&); Integer operator % (const Integer&, long); Integer operator << (const Integer&, const Integer&); Integer operator << (const Integer&, long); Integer operator >> (const Integer&, const Integer&); Integer operator >> (const Integer&, long); Integer operator & (const Integer&, const Integer&); Integer operator & (const Integer&, long); Integer operator & (long, const Integer&); Integer operator | (const Integer&, const Integer&); Integer operator | (const Integer&, long); Integer operator | (long, const Integer&); Integer operator ^ (const Integer&, const Integer&); Integer operator ^ (const Integer&, long); Integer operator ^ (long, const Integer&); Integer abs(const Integer&); // absolute value Integer sqr(const Integer&); // square Integer pow(const Integer& x, const Integer& y); Integer pow(const Integer& x, long y); Integer Ipow(long x, long y); // x to the y as Integer extern char* dec(const Integer& x, int width = 0); extern char* oct(const Integer& x, int width = 0); extern char* hex(const Integer& x, int width = 0); extern Integer sqrt(const Integer&); // floor of square root extern Integer lcm(const Integer& x, const Integer& y); // least common mult typedef Integer IntTmp; // for backward compatibility inline Integer::Integer() :rep(&_ZeroRep) {} inline Integer::Integer(IntRep* r) :rep(r) {} inline Integer::Integer(int y) :rep(Icopy_long(0, (long)y)) {} inline Integer::Integer(long y) :rep(Icopy_long(0, y)) {} inline Integer::Integer(unsigned long y) :rep(Icopy_ulong(0, y)) {} inline Integer::Integer(const Integer& y) :rep(Icopy(0, y.rep)) {} inline Integer::~Integer() { if (rep && !STATIC_IntRep(rep)) delete rep; } inline void Integer::operator = (const Integer& y) { rep = Icopy(rep, y.rep); } inline void Integer::operator = (long y) { rep = Icopy_long(rep, y); } inline int Integer::initialized() const { return rep != 0; } // procedural versions inline int compare(const Integer& x, const Integer& y) { return compare(x.rep, y.rep); } inline int ucompare(const Integer& x, const Integer& y) { return ucompare(x.rep, y.rep); } inline int compare(const Integer& x, long y) { return compare(x.rep, y); } inline int ucompare(const Integer& x, long y) { return ucompare(x.rep, y); } inline int compare(long x, const Integer& y) { return -compare(y.rep, x); } inline int ucompare(long x, const Integer& y) { return -ucompare(y.rep, x); } inline void add(const Integer& x, const Integer& y, Integer& dest) { dest.rep = add(x.rep, 0, y.rep, 0, dest.rep); } inline void sub(const Integer& x, const Integer& y, Integer& dest) { dest.rep = add(x.rep, 0, y.rep, 1, dest.rep); } inline void mul(const Integer& x, const Integer& y, Integer& dest) { dest.rep = multiply(x.rep, y.rep, dest.rep); } inline void div(const Integer& x, const Integer& y, Integer& dest) { dest.rep = div(x.rep, y.rep, dest.rep); } inline void mod(const Integer& x, const Integer& y, Integer& dest) { dest.rep = mod(x.rep, y.rep, dest.rep); } inline void and(const Integer& x, const Integer& y, Integer& dest) { dest.rep = bitop(x.rep, y.rep, dest.rep, '&'); } inline void or(const Integer& x, const Integer& y, Integer& dest) { dest.rep = bitop(x.rep, y.rep, dest.rep, '|'); } inline void xor(const Integer& x, const Integer& y, Integer& dest) { dest.rep = bitop(x.rep, y.rep, dest.rep, '^'); } inline void lshift(const Integer& x, const Integer& y, Integer& dest) { dest.rep = lshift(x.rep, y.rep, 0, dest.rep); } inline void rshift(const Integer& x, const Integer& y, Integer& dest) { dest.rep = lshift(x.rep, y.rep, 1, dest.rep); } inline void pow(const Integer& x, const Integer& y, Integer& dest) { dest.rep = power(x.rep, Itolong(y.rep), dest.rep); // not incorrect } inline void add(const Integer& x, long y, Integer& dest) { dest.rep = add(x.rep, 0, y, dest.rep); } inline void sub(const Integer& x, long y, Integer& dest) { dest.rep = add(x.rep, 0, -y, dest.rep); } inline void mul(const Integer& x, long y, Integer& dest) { dest.rep = multiply(x.rep, y, dest.rep); } inline void div(const Integer& x, long y, Integer& dest) { dest.rep = div(x.rep, y, dest.rep); } inline void mod(const Integer& x, long y, Integer& dest) { dest.rep = mod(x.rep, y, dest.rep); } inline void and(const Integer& x, long y, Integer& dest) { dest.rep = bitop(x.rep, y, dest.rep, '&'); } inline void or(const Integer& x, long y, Integer& dest) { dest.rep = bitop(x.rep, y, dest.rep, '|'); } inline void xor(const Integer& x, long y, Integer& dest) { dest.rep = bitop(x.rep, y, dest.rep, '^'); } inline void lshift(const Integer& x, long y, Integer& dest) { dest.rep = lshift(x.rep, y, dest.rep); } inline void rshift(const Integer& x, long y, Integer& dest) { dest.rep = lshift(x.rep, -y, dest.rep); } inline void pow(const Integer& x, long y, Integer& dest) { dest.rep = power(x.rep, y, dest.rep); } inline void abs(const Integer& x, Integer& dest) { dest.rep = abs(x.rep, dest.rep); } inline void negate(const Integer& x, Integer& dest) { dest.rep = negate(x.rep, dest.rep); } inline void complement(const Integer& x, Integer& dest) { dest.rep = compl(x.rep, dest.rep); } inline void add(long x, const Integer& y, Integer& dest) { dest.rep = add(y.rep, 0, x, dest.rep); } inline void sub(long x, const Integer& y, Integer& dest) { dest.rep = add(y.rep, 1, x, dest.rep); } inline void mul(long x, const Integer& y, Integer& dest) { dest.rep = multiply(y.rep, x, dest.rep); } inline void and(long x, const Integer& y, Integer& dest) { dest.rep = bitop(y.rep, x, dest.rep, '&'); } inline void or(long x, const Integer& y, Integer& dest) { dest.rep = bitop(y.rep, x, dest.rep, '|'); } inline void xor(long x, const Integer& y, Integer& dest) { dest.rep = bitop(y.rep, x, dest.rep, '^'); } // operator versions inline int operator == (const Integer& x, const Integer& y) { return compare(x, y) == 0; } inline int operator == (const Integer& x, long y) { return compare(x, y) == 0; } inline int operator != (const Integer& x, const Integer& y) { return compare(x, y) != 0; } inline int operator != (const Integer& x, long y) { return compare(x, y) != 0; } inline int operator < (const Integer& x, const Integer& y) { return compare(x, y) < 0; } inline int operator < (const Integer& x, long y) { return compare(x, y) < 0; } inline int operator <= (const Integer& x, const Integer& y) { return compare(x, y) <= 0; } inline int operator <= (const Integer& x, long y) { return compare(x, y) <= 0; } inline int operator > (const Integer& x, const Integer& y) { return compare(x, y) > 0; } inline int operator > (const Integer& x, long y) { return compare(x, y) > 0; } inline int operator >= (const Integer& x, const Integer& y) { return compare(x, y) >= 0; } inline int operator >= (const Integer& x, long y) { return compare(x, y) >= 0; } inline void Integer::operator += (const Integer& y) { add(*this, y, *this); } inline void Integer::operator += (long y) { add(*this, y, *this); } inline void Integer::operator ++ () { add(*this, 1, *this); } inline void Integer::operator -= (const Integer& y) { sub(*this, y, *this); } inline void Integer::operator -= (long y) { sub(*this, y, *this); } inline void Integer::operator -- () { add(*this, -1, *this); } inline void Integer::operator *= (const Integer& y) { mul(*this, y, *this); } inline void Integer::operator *= (long y) { mul(*this, y, *this); } inline void Integer::operator &= (const Integer& y) { and(*this, y, *this); } inline void Integer::operator &= (long y) { and(*this, y, *this); } inline void Integer::operator |= (const Integer& y) { or(*this, y, *this); } inline void Integer::operator |= (long y) { or(*this, y, *this); } inline void Integer::operator ^= (const Integer& y) { xor(*this, y, *this); } inline void Integer::operator ^= (long y) { xor(*this, y, *this); } inline void Integer::operator /= (const Integer& y) { div(*this, y, *this); } inline void Integer::operator /= (long y) { div(*this, y, *this); } inline void Integer::operator <<= (const Integer& y) { lshift(*this, y, *this); } inline void Integer::operator <<= (long y) { lshift(*this, y, *this); } inline void Integer::operator >>= (const Integer& y) { rshift(*this, y, *this); } inline void Integer::operator >>= (long y) { rshift(*this, y, *this); } #ifdef __GNUG__ inline Integer operator ? (const Integer& x, const Integer& y) { return (compare(x.rep, y.rep) >= 0)? x : y; } #endif inline void Integer::abs() { ::abs(*this, *this); } inline void Integer::negate() { ::negate(*this, *this); } inline void Integer::complement() { ::complement(*this, *this); } inline int sign(const Integer& x) { return (x.rep->len == 0) ? 0 : ( (x.rep->sgn == 1) ? 1 : -1 ); } inline int even(const Integer& y) { return y.rep->len == 0 || !(y.rep->s[0] & 1); } inline int odd(const Integer& y) { return y.rep->len > 0 && (y.rep->s[0] & 1); } inline char* Itoa(const Integer& y, int base, int width) { return Itoa(y.rep, base, width); } inline long lg(const Integer& x) { return lg(x.rep); } // constructive operations #if defined(__GNUG__) && !defined(NO_NRV) inline Integer operator + (const Integer& x, const Integer& y) return r { add(x, y, r); } inline Integer operator + (const Integer& x, long y) return r { add(x, y, r); } inline Integer operator + (long x, const Integer& y) return r { add(x, y, r); } inline Integer operator - (const Integer& x, const Integer& y) return r { sub(x, y, r); } inline Integer operator - (const Integer& x, long y) return r { sub(x, y, r); } inline Integer operator - (long x, const Integer& y) return r { sub(x, y, r); } inline Integer operator * (const Integer& x, const Integer& y) return r { mul(x, y, r); } inline Integer operator * (const Integer& x, long y) return r { mul(x, y, r); } inline Integer operator * (long x, const Integer& y) return r { mul(x, y, r); } inline Integer sqr(const Integer& x) return r { mul(x, x, r); } inline Integer operator & (const Integer& x, const Integer& y) return r { and(x, y, r); } inline Integer operator & (const Integer& x, long y) return r { and(x, y, r); } inline Integer operator & (long x, const Integer& y) return r { and(x, y, r); } inline Integer operator | (const Integer& x, const Integer& y) return r { or(x, y, r); } inline Integer operator | (const Integer& x, long y) return r { or(x, y, r); } inline Integer operator | (long x, const Integer& y) return r { or(x, y, r); } inline Integer operator ^ (const Integer& x, const Integer& y) return r { xor(x, y, r); } inline Integer operator ^ (const Integer& x, long y) return r { xor(x, y, r); } inline Integer operator ^ (long x, const Integer& y) return r { xor(x, y, r); } inline Integer operator / (const Integer& x, const Integer& y) return r { div(x, y, r); } inline Integer operator / (const Integer& x, long y) return r { div(x, y, r); } inline Integer operator % (const Integer& x, const Integer& y) return r { mod(x, y, r); } inline Integer operator % (const Integer& x, long y) return r { mod(x, y, r); } inline Integer operator << (const Integer& x, const Integer& y) return r { lshift(x, y, r); } inline Integer operator << (const Integer& x, long y) return r { lshift(x, y, r); } inline Integer operator >> (const Integer& x, const Integer& y) return r; { rshift(x, y, r); } inline Integer operator >> (const Integer& x, long y) return r { rshift(x, y, r); } inline Integer pow(const Integer& x, long y) return r { pow(x, y, r); } inline Integer Ipow(long x, long y) return r(x) { pow(r, y, r); } inline Integer pow(const Integer& x, const Integer& y) return r { pow(x, y, r); } inline Integer abs(const Integer& x) return r { abs(x, r); } inline Integer operator - (const Integer& x) return r { negate(x, r); } inline Integer operator ~ (const Integer& x) return r { complement(x, r); } inline Integer atoI(const char* s, int base) return r { r.rep = atoIntRep(s, base); } inline Integer gcd(const Integer& x, const Integer& y) return r { r.rep = gcd(x.rep, y.rep); } #else /* NO_NRV */ inline Integer operator + (const Integer& x, const Integer& y) { Integer r; add(x, y, r); return r; } inline Integer operator + (const Integer& x, long y) { Integer r; add(x, y, r); return r; } inline Integer operator + (long x, const Integer& y) { Integer r; add(x, y, r); return r; } inline Integer operator - (const Integer& x, const Integer& y) { Integer r; sub(x, y, r); return r; } inline Integer operator - (const Integer& x, long y) { Integer r; sub(x, y, r); return r; } inline Integer operator - (long x, const Integer& y) { Integer r; sub(x, y, r); return r; } inline Integer operator * (const Integer& x, const Integer& y) { Integer r; mul(x, y, r); return r; } inline Integer operator * (const Integer& x, long y) { Integer r; mul(x, y, r); return r; } inline Integer operator * (long x, const Integer& y) { Integer r; mul(x, y, r); return r; } inline Integer sqr(const Integer& x) { Integer r; mul(x, x, r); return r; } inline Integer operator & (const Integer& x, const Integer& y) { Integer r; and(x, y, r); return r; } inline Integer operator & (const Integer& x, long y) { Integer r; and(x, y, r); return r; } inline Integer operator & (long x, const Integer& y) { Integer r; and(x, y, r); return r; } inline Integer operator | (const Integer& x, const Integer& y) { Integer r; or(x, y, r); return r; } inline Integer operator | (const Integer& x, long y) { Integer r; or(x, y, r); return r; } inline Integer operator | (long x, const Integer& y) { Integer r; or(x, y, r); return r; } inline Integer operator ^ (const Integer& x, const Integer& y) { Integer r; xor(x, y, r); return r; } inline Integer operator ^ (const Integer& x, long y) { Integer r; xor(x, y, r); return r; } inline Integer operator ^ (long x, const Integer& y) { Integer r; xor(x, y, r); return r; } inline Integer operator / (const Integer& x, const Integer& y) { Integer r; div(x, y, r); return r; } inline Integer operator / (const Integer& x, long y) { Integer r; div(x, y, r); return r; } inline Integer operator % (const Integer& x, const Integer& y) { Integer r; mod(x, y, r); return r; } inline Integer operator % (const Integer& x, long y) { Integer r; mod(x, y, r); return r; } inline Integer operator << (const Integer& x, const Integer& y) { Integer r; lshift(x, y, r); return r; } inline Integer operator << (const Integer& x, long y) { Integer r; lshift(x, y, r); return r; } inline Integer operator >> (const Integer& x, const Integer& y) { Integer r; rshift(x, y, r); return r; } inline Integer operator >> (const Integer& x, long y) { Integer r; rshift(x, y, r); return r; } inline Integer pow(const Integer& x, long y) { Integer r; pow(x, y, r); return r; } inline Integer Ipow(long x, long y) { Integer r(x); pow(r, y, r); return r; } inline Integer pow(const Integer& x, const Integer& y) { Integer r; pow(x, y, r); return r; } inline Integer abs(const Integer& x) { Integer r; abs(x, r); return r; } inline Integer operator - (const Integer& x) { Integer r; negate(x, r); return r; } inline Integer operator ~ (const Integer& x) { Integer r; complement(x, r); return r; } inline Integer atoI(const char* s, int base) { Integer r; r.rep = atoIntRep(s, base); return r; } inline Integer gcd(const Integer& x, const Integer& y) { Integer r; r.rep = gcd(x.rep, y.rep); return r; } #endif /* NO_NRV */ inline void Integer::operator %= (const Integer& y) { *this = *this % y; // mod(*this, y, *this) doesn't work. } inline void Integer::operator %= (long y) { *this = *this % y; // mod(*this, y, *this) doesn't work. } #endif /* !_Integer_h */ ./g++-include/LogNorm.h100644 0 1 4062 5522102276 13301 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef _LogNormal_h #ifdef __GNUG__ #pragma interface #endif #define _LogNormal_h #include class LogNormal: public Normal { protected: double logMean; double logVariance; void setState(); public: LogNormal(double mean, double variance, RNG *gen); double mean(); double mean(double x); double variance(); double variance(double x); virtual double operator()(); }; inline void LogNormal::setState() { double m2 = logMean * logMean; pMean = log(m2 / sqrt(logVariance + m2) ); // from ch@heike.informatik.uni-dortmund.de: // (was pVariance = log((sqrt(logVariance + m2)/m2 )); ) pStdDev = sqrt(log((logVariance + m2)/m2 )); } inline LogNormal::LogNormal(double mean, double variance, RNG *gen) : Normal(mean, variance, gen) { logMean = mean; logVariance = variance; setState(); } inline double LogNormal::mean() { return logMean; } inline double LogNormal::mean(double x) { double t=logMean; logMean = x; setState(); return t; } inline double LogNormal::variance() { return logVariance; } inline double LogNormal::variance(double x) { double t=logVariance; logVariance = x; setState(); return t; } #endif ./g++-include/MLCG.h100644 0 1 3447 5522102277 12455 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef _MLCG_h #define _MLCG_h 1 #ifdef __GNUG__ #pragma interface #endif #include #include // // Multiplicative Linear Conguential Generator // class MLCG : public RNG { long initialSeedOne; long initialSeedTwo; long seedOne; long seedTwo; protected: public: MLCG(long seed1 = 0, long seed2 = 1); // // Return a long-words word of random bits // virtual unsigned long asLong(); virtual void reset(); long seed1(); void seed1(long); long seed2(); void seed2(long); void reseed(long, long); }; inline long MLCG::seed1() { return(seedOne); } inline void MLCG::seed1(long s) { initialSeedOne = s; reset(); } inline long MLCG::seed2() { return(seedTwo); } inline void MLCG::seed2(long s) { initialSeedTwo = s; reset(); } inline void MLCG::reseed(long s1, long s2) { initialSeedOne = s1; initialSeedTwo = s2; reset(); } #endif ./g++-include/NegExp.h100644 0 1 2744 5522102300 13103 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef _NegativeExpntl_h #ifdef __GNUG__ #pragma interface #endif #define _NegativeExpntl_h 1 // // Negative Exponential Random Numbers // // #include class NegativeExpntl: public Random { protected: double pMean; public: NegativeExpntl(double xmean, RNG *gen); double mean(); double mean(double x); virtual double operator()(); }; inline NegativeExpntl::NegativeExpntl(double xmean, RNG *gen) : Random(gen) { pMean = xmean; } inline double NegativeExpntl::mean() { return pMean; } inline double NegativeExpntl::mean(double x) { double t = pMean; pMean = x; return t; } #endif ./g++-include/Normal.h100644 0 1 3456 5522102301 13147 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef _Normal_h #ifdef __GNUG__ #pragma interface #endif #define _Normal_h #include class Normal: public Random { char haveCachedNormal; double cachedNormal; protected: double pMean; double pVariance; double pStdDev; public: Normal(double xmean, double xvariance, RNG *gen); double mean(); double mean(double x); double variance(); double variance(double x); virtual double operator()(); }; inline Normal::Normal(double xmean, double xvariance, RNG *gen) : Random(gen) { pMean = xmean; pVariance = xvariance; pStdDev = sqrt(pVariance); haveCachedNormal = 0; } inline double Normal::mean() { return pMean; }; inline double Normal::mean(double x) { double t=pMean; pMean = x; return t; } inline double Normal::variance() { return pVariance; } inline double Normal::variance(double x) { double t=pVariance; pVariance = x; pStdDev = sqrt(pVariance); return t; }; #endif ./g++-include/Obstack.h100644 0 1 10456 5522102302 13324 0ustar rootdaemon// 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) 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. */ #ifndef _Obstack_h #ifdef __GNUG__ #pragma interface #endif #define _Obstack_h 1 #include class Obstack { struct _obstack_chunk { char* limit; _obstack_chunk* prev; char contents[4]; }; protected: long chunksize; _obstack_chunk* chunk; char* objectbase; char* nextfree; char* chunklimit; int alignmentmask; void _free(void* obj); void newchunk(int size); public: Obstack(int size = 4080, int alignment = 4); // 4080=4096-mallocslop ~Obstack(); void* base(); void* next_free(); int alignment_mask(); int chunk_size(); int size(); int room(); int contains(void* p); // does Obstack hold pointer p? void grow(const void* data, int size); void grow(const void* data, int size, char terminator); void grow(const char* s); void grow(char c); void grow_fast(char c); void blank(int size); void blank_fast(int size); void* finish(); void* finish(char terminator); void* copy(const void* data, int size); void* copy(const void* data, int size, char terminator); void* copy(const char* s); void* copy(char c); void* alloc(int size); void free(void* obj); void shrink(int size = 1); // suggested by ken@cs.rochester.edu int OK(); // rep invariant }; inline Obstack::~Obstack() { _free(0); } inline void* Obstack::base() { return objectbase; } inline void* Obstack::next_free() { return nextfree; } inline int Obstack::alignment_mask() { return alignmentmask; } inline int Obstack::chunk_size() { return chunksize; } inline int Obstack::size() { return nextfree - objectbase; } inline int Obstack::room() { return chunklimit - nextfree; } inline void Obstack:: grow(const void* data, int size) { if (nextfree+size > chunklimit) newchunk(size); memcpy(nextfree, data, size); nextfree += size; } inline void Obstack:: grow(const void* data, int size, char terminator) { if (nextfree+size+1 > chunklimit) newchunk(size+1); memcpy(nextfree, data, size); nextfree += size; *(nextfree)++ = terminator; } inline void Obstack:: grow(const char* s) { grow((const void*)s, strlen(s), 0); } inline void Obstack:: grow(char c) { if (nextfree+1 > chunklimit) newchunk(1); *(nextfree)++ = c; } inline void Obstack:: blank(int size) { if (nextfree+size > chunklimit) newchunk(size); nextfree += size; } inline void* Obstack::finish(char terminator) { grow(terminator); return finish(); } inline void* Obstack::copy(const void* data, int size) { grow (data, size); return finish(); } inline void* Obstack::copy(const void* data, int size, char terminator) { grow(data, size, terminator); return finish(); } inline void* Obstack::copy(const char* s) { grow((const void*)s, strlen(s), 0); return finish(); } inline void* Obstack::copy(char c) { grow(c); return finish(); } inline void* Obstack::alloc(int size) { blank(size); return finish(); } inline void Obstack:: free(void* obj) { if (obj >= (void*)chunk && obj<(void*)chunklimit) nextfree = objectbase = (char *) obj; else _free(obj); } inline void Obstack:: grow_fast(char c) { *(nextfree)++ = c; } inline void Obstack:: blank_fast(int size) { nextfree += size; } inline void Obstack:: shrink(int size) // from ken@cs.rochester.edu { if (nextfree >= objectbase + size) nextfree -= size; } #endif ./g++-include/Pix.h100644 0 1 73 5522102302 12410 0ustar rootdaemon #ifndef _Pix_h #define _Pix_h 1 typedef void* Pix; #endif ./g++-include/RNG.h100644 0 1 3316 5522102304 12343 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef _RNG_h #define _RNG_h 1 #ifdef __GNUG__ #pragma interface #endif #include #include union PrivateRNGSingleType { // used to access floats as unsigneds float s; unsigned long u; }; union PrivateRNGDoubleType { // used to access doubles as unsigneds double d; unsigned long u[2]; }; // // Base class for Random Number Generators. See ACG and MLCG for instances. // class RNG { static PrivateRNGSingleType singleMantissa; // mantissa bit vector static PrivateRNGDoubleType doubleMantissa; // mantissa bit vector public: RNG(); // // Return a long-words word of random bits // virtual unsigned long asLong() = 0; virtual void reset() = 0; // // Return random bits converted to either a float or a double // float asFloat(); double asDouble(); }; #endif ./g++-include/Poisson.h100644 0 1 2570 5522102303 13347 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef _Poisson_h #ifdef __GNUG__ #pragma interface #endif #define _Poisson_h #include class Poisson: public Random { protected: double pMean; public: Poisson(double mean, RNG *gen); double mean(); double mean(double x); virtual double operator()(); }; inline Poisson::Poisson(double mean, RNG *gen) : Random(gen) { pMean = mean; } inline double Poisson::mean() { return pMean; } inline double Poisson::mean(double x) { double t = pMean; pMean = x; return t; } #endif ./g++-include/Random.h100644 0 1 2525 5522102305 13137 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef _Random_h #define _Random_h 1 #ifdef __GNUG__ #pragma interface #endif #include #include class Random { protected: RNG *pGenerator; public: Random(RNG *generator); virtual double operator()() = 0; RNG *generator(); void generator(RNG *p); }; inline Random::Random(RNG *gen) { pGenerator = gen; } inline RNG *Random::generator() { return(pGenerator); } inline void Random::generator(RNG *p) { pGenerator = p; } #endif ./g++-include/Rational.h100644 0 1 17365 5522102305 13520 0ustar rootdaemon// 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) 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. */ #ifndef _Rational_h #ifdef __GNUG__ #pragma interface #endif #define _Rational_h 1 #include #include class Rational { protected: Integer num; Integer den; void normalize(); public: Rational(); Rational(double); Rational(int n); Rational(long n); Rational(int n, int d); Rational(long n, long d); Rational(long n, unsigned long d); Rational(unsigned long n, long d); Rational(unsigned long n, unsigned long d); Rational(const Integer& n); Rational(const Integer& n, const Integer& d); Rational(const Rational&); ~Rational(); void operator = (const Rational& y); friend int operator == (const Rational& x, const Rational& y); friend int operator != (const Rational& x, const Rational& y); friend int operator < (const Rational& x, const Rational& y); friend int operator <= (const Rational& x, const Rational& y); friend int operator > (const Rational& x, const Rational& y); friend int operator >= (const Rational& x, const Rational& y); friend Rational operator + (const Rational& x, const Rational& y); friend Rational operator - (const Rational& x, const Rational& y); friend Rational operator * (const Rational& x, const Rational& y); friend Rational operator / (const Rational& x, const Rational& y); void operator += (const Rational& y); void operator -= (const Rational& y); void operator *= (const Rational& y); void operator /= (const Rational& y); #ifdef __GNUG__ friend Rational operator ? (const Rational& x, const Rational& y); // max #endif friend Rational operator - (const Rational& x); // builtin Rational functions void negate(); // x = -x void invert(); // x = 1/x friend int sign(const Rational& x); // -1, 0, or +1 friend Rational abs(const Rational& x); // absolute value friend Rational sqr(const Rational& x); // square friend Rational pow(const Rational& x, long y); friend Rational pow(const Rational& x, const Integer& y); const Integer& numerator() const; const Integer& denominator() const; // coercion & conversion operator double() const; friend Integer floor(const Rational& x); friend Integer ceil(const Rational& x); friend Integer trunc(const Rational& x); friend Integer round(const Rational& x); friend istream& operator >> (istream& s, Rational& y); friend ostream& operator << (ostream& s, const Rational& y); int fits_in_float() const; int fits_in_double() const; // procedural versions of operators friend int compare(const Rational& x, const Rational& y); friend void add(const Rational& x, const Rational& y, Rational& dest); friend void sub(const Rational& x, const Rational& y, Rational& dest); friend void mul(const Rational& x, const Rational& y, Rational& dest); friend void div(const Rational& x, const Rational& y, Rational& dest); // error detection void error(const char* msg) const; int OK() const; }; typedef Rational RatTmp; // backwards compatibility inline Rational::Rational() : num(&_ZeroRep), den(&_OneRep) {} inline Rational::~Rational() {} inline Rational::Rational(const Rational& y) :num(y.num), den(y.den) {} inline Rational::Rational(const Integer& n) :num(n), den(&_OneRep) {} inline Rational::Rational(const Integer& n, const Integer& d) :num(n),den(d) { normalize(); } inline Rational::Rational(long n) :num(n), den(&_OneRep) { } inline Rational::Rational(int n) :num(n), den(&_OneRep) { } inline Rational::Rational(long n, long d) :num(n), den(d) { normalize(); } inline Rational::Rational(int n, int d) :num(n), den(d) { normalize(); } inline Rational::Rational(long n, unsigned long d) :num(n), den(d) { normalize(); } inline Rational::Rational(unsigned long n, long d) :num(n), den(d) { normalize(); } inline Rational::Rational(unsigned long n, unsigned long d) :num(n), den(d) { normalize(); } inline void Rational::operator = (const Rational& y) { num = y.num; den = y.den; } inline int operator == (const Rational& x, const Rational& y) { return compare(x.num, y.num) == 0 && compare(x.den, y.den) == 0; } inline int operator != (const Rational& x, const Rational& y) { return compare(x.num, y.num) != 0 || compare(x.den, y.den) != 0; } inline int operator < (const Rational& x, const Rational& y) { return compare(x, y) < 0; } inline int operator <= (const Rational& x, const Rational& y) { return compare(x, y) <= 0; } inline int operator > (const Rational& x, const Rational& y) { return compare(x, y) > 0; } inline int operator >= (const Rational& x, const Rational& y) { return compare(x, y) >= 0; } inline int sign(const Rational& x) { return sign(x.num); } inline void Rational::negate() { num.negate(); } inline void Rational::operator += (const Rational& y) { add(*this, y, *this); } inline void Rational::operator -= (const Rational& y) { sub(*this, y, *this); } inline void Rational::operator *= (const Rational& y) { mul(*this, y, *this); } inline void Rational::operator /= (const Rational& y) { div(*this, y, *this); } inline const Integer& Rational::numerator() const { return num; } inline const Integer& Rational::denominator() const { return den; } inline Rational::operator double() const { return ratio(num, den); } #ifdef __GNUG__ inline Rational operator ? (const Rational& x, const Rational& y) { if (compare(x, y) >= 0) return x; else return y; } #endif #if defined(__GNUG__) && !defined(NO_NRV) inline Rational operator + (const Rational& x, const Rational& y) return r { add(x, y, r); } inline Rational operator - (const Rational& x, const Rational& y) return r { sub(x, y, r); } inline Rational operator * (const Rational& x, const Rational& y) return r { mul(x, y, r); } inline Rational operator / (const Rational& x, const Rational& y) return r { div(x, y, r); } #else /* NO_NRV */ inline Rational operator + (const Rational& x, const Rational& y) { Rational r; add(x, y, r); return r; } inline Rational operator - (const Rational& x, const Rational& y) { Rational r; sub(x, y, r); return r; } inline Rational operator * (const Rational& x, const Rational& y) { Rational r; mul(x, y, r); return r; } inline Rational operator / (const Rational& x, const Rational& y) { Rational r; div(x, y, r); return r; } #endif #endif ./g++-include/Regex.h100644 0 1 5067 5522102306 12776 0ustar rootdaemon// 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) 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. */ #ifndef _Regex_h #ifdef __GNUG__ #pragma interface #endif #define _Regex_h 1 #if defined(SHORT_NAMES) || defined(VMS) #define re_compile_pattern recmppat #define re_pattern_buffer repatbuf #define re_registers reregs #endif struct re_pattern_buffer; // defined elsewhere struct re_registers; class Regex { private: Regex(const Regex&) {} // no X(X&) void operator = (const Regex&) {} // no assignment protected: re_pattern_buffer* buf; re_registers* reg; public: Regex(const char* t, int fast = 0, int bufsize = 40, const char* transtable = 0); ~Regex(); int match(const char* s, int len, int pos = 0) const; int search(const char* s, int len, int& matchlen, int startpos = 0) const; int match_info(int& start, int& length, int nth = 0) const; int OK() const; // representation invariant }; // some built in regular expressions extern const Regex RXwhite; // = "[ \n\t\r\v\f]+" extern const Regex RXint; // = "-?[0-9]+" extern const Regex RXdouble; // = "-?\\(\\([0-9]+\\.[0-9]*\\)\\| // \\([0-9]+\\)\\|\\(\\.[0-9]+\\)\\) // \\([eE][---+]?[0-9]+\\)?" extern const Regex RXalpha; // = "[A-Za-z]+" extern const Regex RXlowercase; // = "[a-z]+" extern const Regex RXuppercase; // = "[A-Z]+" extern const Regex RXalphanum; // = "[0-9A-Za-z]+" extern const Regex RXidentifier; // = "[A-Za-z_][A-Za-z0-9_]*" #endif ./g++-include/RndInt.h100644 0 1 10604 5522102307 13134 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1990 Free Software Foundation adapted from a submission from John Reidl 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 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. */ #ifndef _RandomInteger_h #ifdef __GNUG__ #pragma interface #endif #define _RandomInteger_h 1 // RandomInteger uses a random number generator to generate an integer // in a specified range. By default the range is 0..1. Since in my // experience random numbers are often needed for a wide variety of // ranges in the same program, this generator accepts a new low or high value // as an argument to the asLong and operator() methods to temporarily // override stored values #include #include class RandomInteger { protected: RNG *pGenerator; long pLow; long pHigh; long _asLong(long, long); public: RandomInteger(long low, long high, RNG *gen); RandomInteger(long high, RNG *gen); RandomInteger(RNG *gen); // read params long low() const; long high() const; RNG* generator() const; // change params long low(long x); long high(long x); RNG* generator(RNG *gen); // get a random number long asLong(); long operator()(); // synonym for asLong int asInt(); // (possibly) truncate as int // override params for one shot long asLong(long high); long asLong(long low, long high); long operator () (long high); // synonyms long operator () (long low, long high); }; inline RandomInteger::RandomInteger(long low, long high, RNG *gen) : pLow((low < high) ? low : high), pHigh((low < high) ? high : low), pGenerator(gen) {} inline RandomInteger::RandomInteger(long high, RNG *gen) : pLow((0 < high) ? 0 : high), pHigh((0 < high) ? high : 0), pGenerator(gen) {} inline RandomInteger::RandomInteger(RNG *gen) : pLow(0), pHigh(1), pGenerator(gen) {} inline RNG* RandomInteger::generator() const { return pGenerator;} inline long RandomInteger::low() const { return pLow; } inline long RandomInteger::high() const { return pHigh; } inline RNG* RandomInteger::generator(RNG *gen) { RNG *tmp = pGenerator; pGenerator = gen; return tmp; } inline long RandomInteger::low(long x) { long tmp = pLow; pLow = x; return tmp; } inline long RandomInteger:: high(long x) { long tmp = pHigh; pHigh = x; return tmp; } inline long RandomInteger:: _asLong(long low, long high) { return (pGenerator->asLong() % (high-low+1)) + low; } inline long RandomInteger:: asLong() { return _asLong(pLow, pHigh); } inline long RandomInteger:: asLong(long high) { return _asLong(pLow, high); } inline long RandomInteger:: asLong(long low, long high) { return _asLong(low, high); } inline long RandomInteger:: operator () () { return _asLong(pLow, pHigh); } inline long RandomInteger:: operator () (long high) { return _asLong(pLow, high); } inline long RandomInteger:: operator () (long low, long high) { return _asLong(low, high); } inline int RandomInteger:: asInt() { return int(asLong()); } #endif ./g++-include/SLList.h100644 0 1 7522 5522102310 13067 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988, 1992 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) 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. */ #ifndef _SLList_h #ifdef __GNUG__ //#pragma interface #endif #define _SLList_h 1 #include struct BaseSLNode { BaseSLNode *tl; void *item() {return (void*)(this+1);} // Return ((SLNode*)this)->hd }; template class SLNode : public BaseSLNode { public: T hd; // Data part of node SLNode() { } SLNode(const T& h, SLNode* t = 0) : hd(h) { tl = t; } ~SLNode() { } }; extern int __SLListLength(BaseSLNode *ptr); class BaseSLList { protected: BaseSLNode *last; virtual void delete_node(BaseSLNode*node) = 0; virtual BaseSLNode* copy_node(void* datum) = 0; virtual void copy_item(void *dst, void *src) = 0; virtual ~BaseSLList() { } BaseSLList() { last = 0; } void copy(const BaseSLList&); BaseSLList& operator = (const BaseSLList& a); Pix ins_after(Pix p, void *datum); Pix prepend(void *datum); Pix append(void *datum); int remove_front(void *dst, int signal_error = 0); void join(BaseSLList&); public: int length(); void clear(); Pix prepend(BaseSLNode*); Pix append(BaseSLNode*); int OK(); void error(const char* msg); void del_after(Pix p); int owns(Pix p); void del_front(); }; template class SLList : public BaseSLList { private: virtual void delete_node(BaseSLNode *node) { delete (SLNode*)node; } virtual BaseSLNode* copy_node(void *datum) { return new SLNode(*(T*)datum); } virtual void copy_item(void *dst, void *src) { *(T*)dst = *(T*)src; } public: SLList() : BaseSLList() { } SLList(const SLList& a) : BaseSLList() { copy(a); } SLList& operator = (const SLList& a) { BaseSLList::operator=((const BaseSLList&) a); return *this; } virtual ~SLList() { clear(); } int empty() { return last == 0; } Pix prepend(T& item) {return BaseSLList::prepend(&item);} Pix append(T& item) {return BaseSLList::append(&item);} Pix prepend(SLNode* node) {return BaseSLList::prepend(node);} Pix append(SLNode* node) {return BaseSLList::append(node);} T& operator () (Pix p) { if (p == 0) error("null Pix"); return ((SLNode*)(p))->hd; } inline Pix first() { return (last == 0)? 0 : Pix(last->tl); } void next(Pix& p) { p = (p == 0 || p == last)? 0 : Pix(((SLNode*)(p))->tl); } Pix ins_after(Pix p, T& item) { return BaseSLList::ins_after(p, &item); } void join(SLList& a) { BaseSLList::join(a); } T& front() { if (last == 0) error("front: empty list"); return ((SLNode*)last->tl)->hd; } T& rear() { if (last == 0) error("rear: empty list"); return ((SLNode*)last)->hd; } int remove_front(T& x) { return BaseSLList::remove_front(&x); } T remove_front() { T dst; BaseSLList::remove_front(&dst, 1); return dst; } }; #endif ./g++-include/SmplHist.h100644 0 1 3657 5522102310 13465 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef SampleHistogram_h #ifdef __GNUG__ #pragma interface #endif #define SampleHistogram_h 1 #include #include extern const int SampleHistogramMinimum; extern const int SampleHistogramMaximum; class SampleHistogram : public SampleStatistic { protected: short howManyBuckets; int *bucketCount; double *bucketLimit; public: SampleHistogram(double low, double hi, double bucketWidth = -1.0); ~SampleHistogram(); virtual void reset(); virtual void operator+=(double); int similarSamples(double); int buckets(); double bucketThreshold(int i); int inBucket(int i); void printBuckets(ostream&); }; inline int SampleHistogram:: buckets() { return(howManyBuckets); }; inline double SampleHistogram:: bucketThreshold(int i) { if (i < 0 || i >= howManyBuckets) error("invalid bucket access"); return(bucketLimit[i]); } inline int SampleHistogram:: inBucket(int i) { if (i < 0 || i >= howManyBuckets) error("invalid bucket access"); return(bucketCount[i]); } #endif ./g++-include/SmplStat.h100644 0 1 3736 5522102311 13470 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef SampleStatistic_h #ifdef __GNUG__ #pragma interface #endif #define SampleStatistic_h 1 #include class SampleStatistic { protected: int n; double x; double x2; double minValue, maxValue; public : SampleStatistic(); virtual ~SampleStatistic(); virtual void reset(); virtual void operator+=(double); int samples(); double mean(); double stdDev(); double var(); double min(); double max(); double confidence(int p_percentage); double confidence(double p_value); void error(const char* msg); }; // error handlers extern void default_SampleStatistic_error_handler(const char*); extern one_arg_error_handler_t SampleStatistic_error_handler; extern one_arg_error_handler_t set_SampleStatistic_error_handler(one_arg_error_handler_t f); inline SampleStatistic:: SampleStatistic(){ reset();} inline int SampleStatistic:: samples() {return(n);} inline double SampleStatistic:: min() {return(minValue);} inline double SampleStatistic:: max() {return(maxValue);} inline SampleStatistic::~SampleStatistic() {} #endif ./g++-include/String.h100644 0 1 106544 5522102312 13231 0ustar rootdaemon// 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) 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. */ #ifndef _String_h #ifdef __GNUG__ #pragma interface #endif #define _String_h 1 #include #include struct StrRep // internal String representations { unsigned short len; // string length unsigned short sz; // allocated space char s[1]; // the string starts here // (at least 1 char for trailing null) // allocated & expanded via non-public fcts }; // primitive ops on StrReps -- nearly all String fns go through these. StrRep* Salloc(StrRep*, const char*, int, int); StrRep* Scopy(StrRep*, StrRep*); StrRep* Sresize(StrRep*, int); StrRep* Scat(StrRep*, const char*, int, const char*, int); StrRep* Scat(StrRep*, const char*, int,const char*,int, const char*,int); StrRep* Sprepend(StrRep*, const char*, int); StrRep* Sreverse(StrRep*, StrRep*); StrRep* Supcase(StrRep*, StrRep*); StrRep* Sdowncase(StrRep*, StrRep*); StrRep* Scapitalize(StrRep*, StrRep*); // These classes need to be defined in the order given class String; class SubString; class SubString { friend class String; protected: String& S; // The String I'm a substring of unsigned short pos; // starting position in S's rep unsigned short len; // length of substring void assign(StrRep*, const char*, int = -1); SubString(String& x, int p, int l); SubString(const SubString& x); public: // Note there are no public constructors. SubStrings are always // created via String operations ~SubString(); void operator = (const String& y); void operator = (const SubString& y); void operator = (const char* t); void operator = (char c); // return 1 if target appears anywhere in SubString; else 0 int contains(char c) const; int contains(const String& y) const; int contains(const SubString& y) const; int contains(const char* t) const; int contains(const Regex& r) const; // return 1 if target matches entire SubString int matches(const Regex& r) const; // IO friend ostream& operator<<(ostream& s, const SubString& x); // status unsigned int length() const; int empty() const; const char* chars() const; int OK() const; }; class String { friend class SubString; protected: StrRep* rep; // Strings are pointers to their representations // some helper functions int search(int, int, const char*, int = -1) const; int search(int, int, char) const; int match(int, int, int, const char*, int = -1) const; int _gsub(const char*, int, const char* ,int); int _gsub(const Regex&, const char*, int); SubString _substr(int, int); public: // constructors & assignment String(); String(const String& x); String(const SubString& x); String(const char* t); String(const char* t, int len); String(char c); ~String(); void operator = (const String& y); void operator = (const char* y); void operator = (char c); void operator = (const SubString& y); // concatenation void operator += (const String& y); void operator += (const SubString& y); void operator += (const char* t); void operator += (char c); void prepend(const String& y); void prepend(const SubString& y); void prepend(const char* t); void prepend(char c); // procedural versions: // concatenate first 2 args, store result in last arg friend void cat(const String&, const String&, String&); friend void cat(const String&, const SubString&, String&); friend void cat(const String&, const char*, String&); friend void cat(const String&, char, String&); friend void cat(const SubString&, const String&, String&); friend void cat(const SubString&, const SubString&, String&); friend void cat(const SubString&, const char*, String&); friend void cat(const SubString&, char, String&); friend void cat(const char*, const String&, String&); friend void cat(const char*, const SubString&, String&); friend void cat(const char*, const char*, String&); friend void cat(const char*, char, String&); // double concatenation, by request. (yes, there are too many versions, // but if one is supported, then the others should be too...) // Concatenate first 3 args, store in last arg friend void cat(const String&,const String&, const String&,String&); friend void cat(const String&,const String&,const SubString&,String&); friend void cat(const String&,const String&, const char*, String&); friend void cat(const String&,const String&, char, String&); friend void cat(const String&,const SubString&,const String&,String&); friend void cat(const String&,const SubString&,const SubString&,String&); friend void cat(const String&,const SubString&, const char*, String&); friend void cat(const String&,const SubString&, char, String&); friend void cat(const String&,const char*, const String&, String&); friend void cat(const String&,const char*, const SubString&, String&); friend void cat(const String&,const char*, const char*, String&); friend void cat(const String&,const char*, char, String&); friend void cat(const char*, const String&, const String&,String&); friend void cat(const char*,const String&,const SubString&,String&); friend void cat(const char*,const String&, const char*, String&); friend void cat(const char*,const String&, char, String&); friend void cat(const char*,const SubString&,const String&,String&); friend void cat(const char*,const SubString&,const SubString&,String&); friend void cat(const char*,const SubString&, const char*, String&); friend void cat(const char*,const SubString&, char, String&); friend void cat(const char*,const char*, const String&, String&); friend void cat(const char*,const char*, const SubString&, String&); friend void cat(const char*,const char*, const char*, String&); friend void cat(const char*,const char*, char, String&); // searching & matching // return position of target in string or -1 for failure int index(char c, int startpos = 0) const; int index(const String& y, int startpos = 0) const; int index(const SubString& y, int startpos = 0) const; int index(const char* t, int startpos = 0) const; int index(const Regex& r, int startpos = 0) const; // return 1 if target appears anyhere in String; else 0 int contains(char c) const; int contains(const String& y) const; int contains(const SubString& y) const; int contains(const char* t) const; int contains(const Regex& r) const; // return 1 if target appears anywhere after position pos // (or before, if pos is negative) in String; else 0 int contains(char c, int pos) const; int contains(const String& y, int pos) const; int contains(const SubString& y, int pos) const; int contains(const char* t, int pos) const; int contains(const Regex& r, int pos) const; // return 1 if target appears at position pos in String; else 0 int matches(char c, int pos = 0) const; int matches(const String& y, int pos = 0) const; int matches(const SubString& y, int pos = 0) const; int matches(const char* t, int pos = 0) const; int matches(const Regex& r, int pos = 0) const; // return number of occurences of target in String int freq(char c) const; int freq(const String& y) const; int freq(const SubString& y) const; int freq(const char* t) const; // SubString extraction // Note that you can't take a substring of a const String, since // this leaves open the possiblility of indirectly modifying the // String through the SubString SubString at(int pos, int len); SubString operator () (int pos, int len); // synonym for at SubString at(const String& x, int startpos = 0); SubString at(const SubString& x, int startpos = 0); SubString at(const char* t, int startpos = 0); SubString at(char c, int startpos = 0); SubString at(const Regex& r, int startpos = 0); SubString before(int pos); SubString before(const String& x, int startpos = 0); SubString before(const SubString& x, int startpos = 0); SubString before(const char* t, int startpos = 0); SubString before(char c, int startpos = 0); SubString before(const Regex& r, int startpos = 0); SubString through(int pos); SubString through(const String& x, int startpos = 0); SubString through(const SubString& x, int startpos = 0); SubString through(const char* t, int startpos = 0); SubString through(char c, int startpos = 0); SubString through(const Regex& r, int startpos = 0); SubString from(int pos); SubString from(const String& x, int startpos = 0); SubString from(const SubString& x, int startpos = 0); SubString from(const char* t, int startpos = 0); SubString from(char c, int startpos = 0); SubString from(const Regex& r, int startpos = 0); SubString after(int pos); SubString after(const String& x, int startpos = 0); SubString after(const SubString& x, int startpos = 0); SubString after(const char* t, int startpos = 0); SubString after(char c, int startpos = 0); SubString after(const Regex& r, int startpos = 0); // deletion // delete len chars starting at pos void del(int pos, int len); // delete the first occurrence of target after startpos void del(const String& y, int startpos = 0); void del(const SubString& y, int startpos = 0); void del(const char* t, int startpos = 0); void del(char c, int startpos = 0); void del(const Regex& r, int startpos = 0); // global substitution: substitute all occurrences of pat with repl int gsub(const String& pat, const String& repl); int gsub(const SubString& pat, const String& repl); int gsub(const char* pat, const String& repl); int gsub(const char* pat, const char* repl); int gsub(const Regex& pat, const String& repl); // friends & utilities // split string into array res at separators; return number of elements friend int split(const String& x, String res[], int maxn, const String& sep); friend int split(const String& x, String res[], int maxn, const Regex& sep); friend String common_prefix(const String& x, const String& y, int startpos = 0); friend String common_suffix(const String& x, const String& y, int startpos = -1); friend String replicate(char c, int n); friend String replicate(const String& y, int n); friend String join(String src[], int n, const String& sep); // simple builtin transformations friend String reverse(const String& x); friend String upcase(const String& x); friend String downcase(const String& x); friend String capitalize(const String& x); // in-place versions of above void reverse(); void upcase(); void downcase(); void capitalize(); // element extraction char& operator [] (int i); char elem(int i) const; char firstchar() const; char lastchar() const; // conversion operator const char*() const; const char* chars() const; // IO friend ostream& operator<<(ostream& s, const String& x); friend ostream& operator<<(ostream& s, const SubString& x); friend istream& operator>>(istream& s, String& x); friend int readline(istream& s, String& x, char terminator = '\n', int discard_terminator = 1); // status unsigned int length() const; int empty() const; // preallocate some space for String void alloc(int newsize); // report current allocation (not length!) int allocation() const; void error(const char* msg) const; int OK() const; }; typedef String StrTmp; // for backward compatibility // other externs int compare(const String& x, const String& y); int compare(const String& x, const SubString& y); int compare(const String& x, const char* y); int compare(const SubString& x, const String& y); int compare(const SubString& x, const SubString& y); int compare(const SubString& x, const char* y); int fcompare(const String& x, const String& y); // ignore case extern StrRep _nilStrRep; extern String _nilString; // other inlines String operator + (const String& x, const String& y); String operator + (const String& x, const SubString& y); String operator + (const String& x, const char* y); String operator + (const String& x, char y); String operator + (const SubString& x, const String& y); String operator + (const SubString& x, const SubString& y); String operator + (const SubString& x, const char* y); String operator + (const SubString& x, char y); String operator + (const char* x, const String& y); String operator + (const char* x, const SubString& y); int operator==(const String& x, const String& y); int operator!=(const String& x, const String& y); int operator> (const String& x, const String& y); int operator>=(const String& x, const String& y); int operator< (const String& x, const String& y); int operator<=(const String& x, const String& y); int operator==(const String& x, const SubString& y); int operator!=(const String& x, const SubString& y); int operator> (const String& x, const SubString& y); int operator>=(const String& x, const SubString& y); int operator< (const String& x, const SubString& y); int operator<=(const String& x, const SubString& y); int operator==(const String& x, const char* t); int operator!=(const String& x, const char* t); int operator> (const String& x, const char* t); int operator>=(const String& x, const char* t); int operator< (const String& x, const char* t); int operator<=(const String& x, const char* t); int operator==(const SubString& x, const String& y); int operator!=(const SubString& x, const String& y); int operator> (const SubString& x, const String& y); int operator>=(const SubString& x, const String& y); int operator< (const SubString& x, const String& y); int operator<=(const SubString& x, const String& y); int operator==(const SubString& x, const SubString& y); int operator!=(const SubString& x, const SubString& y); int operator> (const SubString& x, const SubString& y); int operator>=(const SubString& x, const SubString& y); int operator< (const SubString& x, const SubString& y); int operator<=(const SubString& x, const SubString& y); int operator==(const SubString& x, const char* t); int operator!=(const SubString& x, const char* t); int operator> (const SubString& x, const char* t); int operator>=(const SubString& x, const char* t); int operator< (const SubString& x, const char* t); int operator<=(const SubString& x, const char* t); // status reports, needed before defining other things inline unsigned int String::length() const { return rep->len; } inline int String::empty() const { return rep->len == 0; } inline const char* String::chars() const { return &(rep->s[0]); } inline int String::allocation() const { return rep->sz; } inline void String::alloc(int newsize) { rep = Sresize(rep, newsize); } inline unsigned int SubString::length() const { return len; } inline int SubString::empty() const { return len == 0; } inline const char* SubString::chars() const { return &(S.rep->s[pos]); } // constructors inline String::String() : rep(&_nilStrRep) {} inline String::String(const String& x) : rep(Scopy(0, x.rep)) {} inline String::String(const char* t) : rep(Salloc(0, t, -1, -1)) {} inline String::String(const char* t, int tlen) : rep(Salloc(0, t, tlen, tlen)) {} inline String::String(const SubString& y) : rep(Salloc(0, y.chars(), y.length(), y.length())) {} inline String::String(char c) : rep(Salloc(0, &c, 1, 1)) {} inline String::~String() { if (rep != &_nilStrRep) delete rep; } inline SubString::SubString(const SubString& x) :S(x.S), pos(x.pos), len(x.len) {} inline SubString::SubString(String& x, int first, int l) :S(x), pos(first), len(l) {} inline SubString::~SubString() {} // assignment inline void String::operator = (const String& y) { rep = Scopy(rep, y.rep); } inline void String::operator=(const char* t) { rep = Salloc(rep, t, -1, -1); } inline void String::operator=(const SubString& y) { rep = Salloc(rep, y.chars(), y.length(), y.length()); } inline void String::operator=(char c) { rep = Salloc(rep, &c, 1, 1); } inline void SubString::operator = (const char* ys) { assign(0, ys); } inline void SubString::operator = (char ch) { assign(0, &ch, 1); } inline void SubString::operator = (const String& y) { assign(y.rep, y.chars(), y.length()); } inline void SubString::operator = (const SubString& y) { assign(y.S.rep, y.chars(), y.length()); } // Zillions of cats... inline void cat(const String& x, const String& y, String& r) { r.rep = Scat(r.rep, x.chars(), x.length(), y.chars(), y.length()); } inline void cat(const String& x, const SubString& y, String& r) { r.rep = Scat(r.rep, x.chars(), x.length(), y.chars(), y.length()); } inline void cat(const String& x, const char* y, String& r) { r.rep = Scat(r.rep, x.chars(), x.length(), y, -1); } inline void cat(const String& x, char y, String& r) { r.rep = Scat(r.rep, x.chars(), x.length(), &y, 1); } inline void cat(const SubString& x, const String& y, String& r) { r.rep = Scat(r.rep, x.chars(), x.length(), y.chars(), y.length()); } inline void cat(const SubString& x, const SubString& y, String& r) { r.rep = Scat(r.rep, x.chars(), x.length(), y.chars(), y.length()); } inline void cat(const SubString& x, const char* y, String& r) { r.rep = Scat(r.rep, x.chars(), x.length(), y, -1); } inline void cat(const SubString& x, char y, String& r) { r.rep = Scat(r.rep, x.chars(), x.length(), &y, 1); } inline void cat(const char* x, const String& y, String& r) { r.rep = Scat(r.rep, x, -1, y.chars(), y.length()); } inline void cat(const char* x, const SubString& y, String& r) { r.rep = Scat(r.rep, x, -1, y.chars(), y.length()); } inline void cat(const char* x, const char* y, String& r) { r.rep = Scat(r.rep, x, -1, y, -1); } inline void cat(const char* x, char y, String& r) { r.rep = Scat(r.rep, x, -1, &y, 1); } inline void cat(const String& a, const String& x, const String& y, String& r) { r.rep = Scat(r.rep, a.chars(), a.length(), x.chars(), x.length(), y.chars(), y.length()); } inline void cat(const String& a, const String& x, const SubString& y, String& r) { r.rep = Scat(r.rep, a.chars(), a.length(), x.chars(), x.length(), y.chars(), y.length()); } inline void cat(const String& a, const String& x, const char* y, String& r) { r.rep = Scat(r.rep, a.chars(), a.length(), x.chars(), x.length(), y, -1); } inline void cat(const String& a, const String& x, char y, String& r) { r.rep = Scat(r.rep, a.chars(), a.length(), x.chars(), x.length(), &y, 1); } inline void cat(const String& a, const SubString& x, const String& y, String& r) { r.rep = Scat(r.rep, a.chars(), a.length(), x.chars(), x.length(), y.chars(), y.length()); } inline void cat(const String& a, const SubString& x, const SubString& y, String& r) { r.rep = Scat(r.rep, a.chars(), a.length(), x.chars(), x.length(), y.chars(), y.length()); } inline void cat(const String& a, const SubString& x, const char* y, String& r) { r.rep = Scat(r.rep, a.chars(), a.length(), x.chars(), x.length(), y, -1); } inline void cat(const String& a, const SubString& x, char y, String& r) { r.rep = Scat(r.rep, a.chars(), a.length(), x.chars(), x.length(), &y, 1); } inline void cat(const String& a, const char* x, const String& y, String& r) { r.rep = Scat(r.rep, a.chars(), a.length(), x, -1, y.chars(), y.length()); } inline void cat(const String& a, const char* x, const SubString& y, String& r) { r.rep = Scat(r.rep, a.chars(), a.length(), x, -1, y.chars(), y.length()); } inline void cat(const String& a, const char* x, const char* y, String& r) { r.rep = Scat(r.rep, a.chars(), a.length(), x, -1, y, -1); } inline void cat(const String& a, const char* x, char y, String& r) { r.rep = Scat(r.rep, a.chars(), a.length(), x, -1, &y, 1); } inline void cat(const char* a, const String& x, const String& y, String& r) { r.rep = Scat(r.rep, a, -1, x.chars(), x.length(), y.chars(), y.length()); } inline void cat(const char* a, const String& x, const SubString& y, String& r) { r.rep = Scat(r.rep, a, -1, x.chars(), x.length(), y.chars(), y.length()); } inline void cat(const char* a, const String& x, const char* y, String& r) { r.rep = Scat(r.rep, a, -1, x.chars(), x.length(), y, -1); } inline void cat(const char* a, const String& x, char y, String& r) { r.rep = Scat(r.rep, a, -1, x.chars(), x.length(), &y, 1); } inline void cat(const char* a, const SubString& x, const String& y, String& r) { r.rep = Scat(r.rep, a, -1, x.chars(), x.length(), y.chars(), y.length()); } inline void cat(const char* a, const SubString& x, const SubString& y, String& r) { r.rep = Scat(r.rep, a, -1, x.chars(), x.length(), y.chars(), y.length()); } inline void cat(const char* a, const SubString& x, const char* y, String& r) { r.rep = Scat(r.rep, a, -1, x.chars(), x.length(), y, -1); } inline void cat(const char* a, const SubString& x, char y, String& r) { r.rep = Scat(r.rep, a, -1, x.chars(), x.length(), &y, 1); } inline void cat(const char* a, const char* x, const String& y, String& r) { r.rep = Scat(r.rep, a, -1, x, -1, y.chars(), y.length()); } inline void cat(const char* a, const char* x, const SubString& y, String& r) { r.rep = Scat(r.rep, a, -1, x, -1, y.chars(), y.length()); } inline void cat(const char* a, const char* x, const char* y, String& r) { r.rep = Scat(r.rep, a, -1, x, -1, y, -1); } inline void cat(const char* a, const char* x, char y, String& r) { r.rep = Scat(r.rep, a, -1, x, -1, &y, 1); } // operator versions inline void String::operator +=(const String& y) { cat(*this, y, *this); } inline void String::operator +=(const SubString& y) { cat(*this, y, *this); } inline void String::operator += (const char* y) { cat(*this, y, *this); } inline void String:: operator +=(char y) { cat(*this, y, *this); } // constructive concatenation #if defined(__GNUG__) && !defined(NO_NRV) inline String operator + (const String& x, const String& y) return r; { cat(x, y, r); } inline String operator + (const String& x, const SubString& y) return r; { cat(x, y, r); } inline String operator + (const String& x, const char* y) return r; { cat(x, y, r); } inline String operator + (const String& x, char y) return r; { cat(x, y, r); } inline String operator + (const SubString& x, const String& y) return r; { cat(x, y, r); } inline String operator + (const SubString& x, const SubString& y) return r; { cat(x, y, r); } inline String operator + (const SubString& x, const char* y) return r; { cat(x, y, r); } inline String operator + (const SubString& x, char y) return r; { cat(x, y, r); } inline String operator + (const char* x, const String& y) return r; { cat(x, y, r); } inline String operator + (const char* x, const SubString& y) return r; { cat(x, y, r); } inline String reverse(const String& x) return r; { r.rep = Sreverse(x.rep, r.rep); } inline String upcase(const String& x) return r; { r.rep = Supcase(x.rep, r.rep); } inline String downcase(const String& x) return r; { r.rep = Sdowncase(x.rep, r.rep); } inline String capitalize(const String& x) return r; { r.rep = Scapitalize(x.rep, r.rep); } #else /* NO_NRV */ inline String operator + (const String& x, const String& y) { String r; cat(x, y, r); return r; } inline String operator + (const String& x, const SubString& y) { String r; cat(x, y, r); return r; } inline String operator + (const String& x, const char* y) { String r; cat(x, y, r); return r; } inline String operator + (const String& x, char y) { String r; cat(x, y, r); return r; } inline String operator + (const SubString& x, const String& y) { String r; cat(x, y, r); return r; } inline String operator + (const SubString& x, const SubString& y) { String r; cat(x, y, r); return r; } inline String operator + (const SubString& x, const char* y) { String r; cat(x, y, r); return r; } inline String operator + (const SubString& x, char y) { String r; cat(x, y, r); return r; } inline String operator + (const char* x, const String& y) { String r; cat(x, y, r); return r; } inline String operator + (const char* x, const SubString& y) { String r; cat(x, y, r); return r; } inline String reverse(const String& x) { String r; r.rep = Sreverse(x.rep, r.rep); return r; } inline String upcase(const String& x) { String r; r.rep = Supcase(x.rep, r.rep); return r; } inline String downcase(const String& x) { String r; r.rep = Sdowncase(x.rep, r.rep); return r; } inline String capitalize(const String& x) { String r; r.rep = Scapitalize(x.rep, r.rep); return r; } #endif // prepend inline void String::prepend(const String& y) { rep = Sprepend(rep, y.chars(), y.length()); } inline void String::prepend(const char* y) { rep = Sprepend(rep, y, -1); } inline void String::prepend(char y) { rep = Sprepend(rep, &y, 1); } inline void String::prepend(const SubString& y) { rep = Sprepend(rep, y.chars(), y.length()); } // misc transformations inline void String::reverse() { rep = Sreverse(rep, rep); } inline void String::upcase() { rep = Supcase(rep, rep); } inline void String::downcase() { rep = Sdowncase(rep, rep); } inline void String::capitalize() { rep = Scapitalize(rep, rep); } // element extraction inline char& String::operator [] (int i) { if (((unsigned)i) >= length()) error("invalid index"); return rep->s[i]; } inline char String::elem (int i) const { if (((unsigned)i) >= length()) error("invalid index"); return rep->s[i]; } inline char String::firstchar() const { return elem(0); } inline char String::lastchar() const { return elem(length() - 1); } // searching inline int String::index(char c, int startpos) const { return search(startpos, length(), c); } inline int String::index(const char* t, int startpos) const { return search(startpos, length(), t); } inline int String::index(const String& y, int startpos) const { return search(startpos, length(), y.chars(), y.length()); } inline int String::index(const SubString& y, int startpos) const { return search(startpos, length(), y.chars(), y.length()); } inline int String::index(const Regex& r, int startpos) const { int unused; return r.search(chars(), length(), unused, startpos); } inline int String::contains(char c) const { return search(0, length(), c) >= 0; } inline int String::contains(const char* t) const { return search(0, length(), t) >= 0; } inline int String::contains(const String& y) const { return search(0, length(), y.chars(), y.length()) >= 0; } inline int String::contains(const SubString& y) const { return search(0, length(), y.chars(), y.length()) >= 0; } inline int String::contains(char c, int p) const { return match(p, length(), 0, &c, 1) >= 0; } inline int String::contains(const char* t, int p) const { return match(p, length(), 0, t) >= 0; } inline int String::contains(const String& y, int p) const { return match(p, length(), 0, y.chars(), y.length()) >= 0; } inline int String::contains(const SubString& y, int p) const { return match(p, length(), 0, y.chars(), y.length()) >= 0; } inline int String::contains(const Regex& r) const { int unused; return r.search(chars(), length(), unused, 0) >= 0; } inline int String::contains(const Regex& r, int p) const { return r.match(chars(), length(), p) >= 0; } inline int String::matches(const SubString& y, int p) const { return match(p, length(), 1, y.chars(), y.length()) >= 0; } inline int String::matches(const String& y, int p) const { return match(p, length(), 1, y.chars(), y.length()) >= 0; } inline int String::matches(const char* t, int p) const { return match(p, length(), 1, t) >= 0; } inline int String::matches(char c, int p) const { return match(p, length(), 1, &c, 1) >= 0; } inline int String::matches(const Regex& r, int p) const { int l = (p < 0)? -p : length() - p; return r.match(chars(), length(), p) == l; } inline int SubString::contains(const char* t) const { return S.search(pos, pos+len, t) >= 0; } inline int SubString::contains(const String& y) const { return S.search(pos, pos+len, y.chars(), y.length()) >= 0; } inline int SubString::contains(const SubString& y) const { return S.search(pos, pos+len, y.chars(), y.length()) >= 0; } inline int SubString::contains(char c) const { return S.search(pos, pos+len, c) >= 0; } inline int SubString::contains(const Regex& r) const { int unused; return r.search(chars(), len, unused, 0) >= 0; } inline int SubString::matches(const Regex& r) const { return r.match(chars(), len, 0) == len; } inline int String::gsub(const String& pat, const String& r) { return _gsub(pat.chars(), pat.length(), r.chars(), r.length()); } inline int String::gsub(const SubString& pat, const String& r) { return _gsub(pat.chars(), pat.length(), r.chars(), r.length()); } inline int String::gsub(const Regex& pat, const String& r) { return _gsub(pat, r.chars(), r.length()); } inline int String::gsub(const char* pat, const String& r) { return _gsub(pat, -1, r.chars(), r.length()); } inline int String::gsub(const char* pat, const char* r) { return _gsub(pat, -1, r, -1); } inline ostream& operator<<(ostream& s, const String& x) { s << x.chars(); return s; } // a zillion comparison operators inline int operator==(const String& x, const String& y) { return compare(x, y) == 0; } inline int operator!=(const String& x, const String& y) { return compare(x, y) != 0; } inline int operator>(const String& x, const String& y) { return compare(x, y) > 0; } inline int operator>=(const String& x, const String& y) { return compare(x, y) >= 0; } inline int operator<(const String& x, const String& y) { return compare(x, y) < 0; } inline int operator<=(const String& x, const String& y) { return compare(x, y) <= 0; } inline int operator==(const String& x, const SubString& y) { return compare(x, y) == 0; } inline int operator!=(const String& x, const SubString& y) { return compare(x, y) != 0; } inline int operator>(const String& x, const SubString& y) { return compare(x, y) > 0; } inline int operator>=(const String& x, const SubString& y) { return compare(x, y) >= 0; } inline int operator<(const String& x, const SubString& y) { return compare(x, y) < 0; } inline int operator<=(const String& x, const SubString& y) { return compare(x, y) <= 0; } inline int operator==(const String& x, const char* t) { return compare(x, t) == 0; } inline int operator!=(const String& x, const char* t) { return compare(x, t) != 0; } inline int operator>(const String& x, const char* t) { return compare(x, t) > 0; } inline int operator>=(const String& x, const char* t) { return compare(x, t) >= 0; } inline int operator<(const String& x, const char* t) { return compare(x, t) < 0; } inline int operator<=(const String& x, const char* t) { return compare(x, t) <= 0; } inline int operator==(const SubString& x, const String& y) { return compare(y, x) == 0; } inline int operator!=(const SubString& x, const String& y) { return compare(y, x) != 0; } inline int operator>(const SubString& x, const String& y) { return compare(y, x) < 0; } inline int operator>=(const SubString& x, const String& y) { return compare(y, x) <= 0; } inline int operator<(const SubString& x, const String& y) { return compare(y, x) > 0; } inline int operator<=(const SubString& x, const String& y) { return compare(y, x) >= 0; } inline int operator==(const SubString& x, const SubString& y) { return compare(x, y) == 0; } inline int operator!=(const SubString& x, const SubString& y) { return compare(x, y) != 0; } inline int operator>(const SubString& x, const SubString& y) { return compare(x, y) > 0; } inline int operator>=(const SubString& x, const SubString& y) { return compare(x, y) >= 0; } inline int operator<(const SubString& x, const SubString& y) { return compare(x, y) < 0; } inline int operator<=(const SubString& x, const SubString& y) { return compare(x, y) <= 0; } inline int operator==(const SubString& x, const char* t) { return compare(x, t) == 0; } inline int operator!=(const SubString& x, const char* t) { return compare(x, t) != 0; } inline int operator>(const SubString& x, const char* t) { return compare(x, t) > 0; } inline int operator>=(const SubString& x, const char* t) { return compare(x, t) >= 0; } inline int operator<(const SubString& x, const char* t) { return compare(x, t) < 0; } inline int operator<=(const SubString& x, const char* t) { return compare(x, t) <= 0; } // a helper needed by at, before, etc. inline SubString String::_substr(int first, int l) { if (first < 0 || (unsigned)(first + l) > length() ) return SubString(_nilString, 0, 0) ; else return SubString(*this, first, l); } #endif ./g++-include/Uniform.h100644 0 1 3412 5522102313 13331 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef _Uniform_h #ifdef __GNUG__ #pragma interface #endif #define _Uniform_h 1 #include // // The interval [lo..hi] // class Uniform: public Random { double pLow; double pHigh; double delta; public: Uniform(double low, double high, RNG *gen); double low(); double low(double x); double high(); double high(double x); virtual double operator()(); }; inline Uniform::Uniform(double low, double high, RNG *gen) : Random(gen) { pLow = (low < high) ? low : high; pHigh = (low < high) ? high : low; delta = pHigh - pLow; } inline double Uniform::low() { return pLow; } inline double Uniform::low(double x) { double tmp = pLow; pLow = x; delta = pHigh - pLow; return tmp; } inline double Uniform::high() { return pHigh; } inline double Uniform::high(double x) { double tmp = pHigh; pHigh = x; delta = pHigh - pLow; return tmp; } #endif ./g++-include/Weibull.h100644 0 1 3425 5522102314 13322 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Dirk Grunwald (grunwald@cs.uiuc.edu) 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. */ #ifndef _Weibull_h #ifdef __GNUG__ #pragma interface #endif #define _Weibull_h #include class Weibull: public Random { protected: double pAlpha; double pInvAlpha; double pBeta; void setState(); public: Weibull(double alpha, double beta, RNG *gen); double alpha(); double alpha(double x); double beta(); double beta(double x); virtual double operator()(); }; inline void Weibull::setState() { pInvAlpha = 1.0 / pAlpha; } inline Weibull::Weibull(double alpha, double beta, RNG *gen) : Random(gen) { pAlpha = alpha; pBeta = beta; setState(); } inline double Weibull::alpha() { return pAlpha; } inline double Weibull::alpha(double x) { double tmp = pAlpha; pAlpha = x; setState(); return tmp; } inline double Weibull::beta() { return pBeta; }; inline double Weibull::beta(double x) { double tmp = pBeta; pBeta = x; return tmp; }; #endif ./g++-include/bool.h100644 0 1 435 5522102314 12630 0ustar rootdaemon// Defining TRUE and FALSE is usually a Bad Idea, // because you will probably be inconsistent with anyone // else who had the same clever idea. // Therefore: DON'T USE THIS FILE. #ifndef _bool_h #define _bool_h 1 #undef FALSE #undef TRUE enum bool { FALSE = 0, TRUE = 1 }; #endif ./g++-include/builtin.h100644 0 1 6521 5522102315 13366 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988, 1992 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) 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. */ /* arithmetic, etc. functions on built in types */ #ifndef _builtin_h #ifdef __GNUG__ #pragma interface #endif #define _builtin_h 1 #include #include #include #ifdef __GNUG__ #define _VOLATILE_VOID volatile void #else #define _VOLATILE_VOID void #endif typedef void (*one_arg_error_handler_t)(const char*); typedef void (*two_arg_error_handler_t)(const char*, const char*); long gcd(long, long); long lg(unsigned long); double pow(double, long); long pow(long, long); extern "C" double start_timer(); extern "C" double return_elapsed_time(double last_time = 0.0); char* dtoa(double x, char cvt = 'g', int width = 0, int prec = 6); unsigned int hashpjw(const char*); unsigned int multiplicativehash(int); unsigned int foldhash(double); extern _VOLATILE_VOID default_one_arg_error_handler(const char*); extern _VOLATILE_VOID default_two_arg_error_handler(const char*, const char*); extern two_arg_error_handler_t lib_error_handler; extern two_arg_error_handler_t set_lib_error_handler(two_arg_error_handler_t f); double abs(double arg); float abs(float arg); short abs(short arg); long abs(long arg); int sign(long arg); int sign(double arg); long sqr(long arg); double sqr(double arg); int even(long arg); int odd(long arg); long lcm(long x, long y); void (setbit)(long& x, long b); void clearbit(long& x, long b); int testbit(long x, long b); #if !defined(IV) #if ! _G_MATH_H_INLINES /* hpux and SCO define this in math.h */ inline double abs(double arg) { return (arg < 0.0)? -arg : arg; } #endif inline float abs(float arg) { return (arg < 0.0)? -arg : arg; } inline short abs(short arg) { return (arg < 0)? -arg : arg; } inline long abs(long arg) { return (arg < 0)? -arg : arg; } inline int sign(long arg) { return (arg == 0) ? 0 : ( (arg > 0) ? 1 : -1 ); } inline int sign(double arg) { return (arg == 0.0) ? 0 : ( (arg > 0.0) ? 1 : -1 ); } inline long sqr(long arg) { return arg * arg; } #if ! _G_MATH_H_INLINES /* hpux and SCO define this in math.h */ inline double sqr(double arg) { return arg * arg; } #endif inline int even(long arg) { return !(arg & 1); } inline int odd(long arg) { return (arg & 1); } inline long lcm(long x, long y) { return x / gcd(x, y) * y; } inline void (setbit)(long& x, long b) { x |= (1 << b); } inline void clearbit(long& x, long b) { x &= ~(1 << b); } inline int testbit(long x, long b) { return ((x & (1 << b)) != 0); } #endif #endif ./g++-include/compare.h100644 0 1 4227 5522102316 13350 0ustar rootdaemon// 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) 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. */ #ifndef _compare_h #ifdef __GNUG__ #pragma interface #endif #define _compare_h 1 #include int compare(int a, int b); int compare(short a, short b); int compare(unsigned long a, unsigned long b); int compare(unsigned int a, unsigned int b); int compare(unsigned short a, unsigned short b); int compare(unsigned char a, unsigned char b); int compare(signed char a, signed char b); int compare(float a, float b); int compare(double a, double b); int compare(const char* a, const char* b); inline int compare(int a, int b) { return a - b; } inline int compare(short a, short b) { return a - b; } inline int compare(signed char a, signed char b) { return a - b; } inline int compare(unsigned long a, unsigned long b) { return (a < b)? -1 : (a > b)? 1 : 0; } inline int compare(unsigned int a, unsigned int b) { return (a < b)? -1 : (a > b)? 1 : 0; } inline int compare(unsigned short a, unsigned short b) { return (a < b)? -1 : (a > b)? 1 : 0; } inline int compare(unsigned char a, unsigned char b) { return (a < b)? -1 : (a > b)? 1 : 0; } inline int compare(float a, float b) { return (a < b)? -1 : (a > b)? 1 : 0; } inline int compare(double a, double b) { return (a < b)? -1 : (a > b)? 1 : 0; } inline int compare(const char* a, const char* b) { return strcmp(a,b); } #endif ./g++-include/complex.h100644 0 1 171 5522102317 13344 0ustar rootdaemon#ifndef _complex_h #define _complex_h #define __ATT_complex__ #include typedef class Complex complex; #endif ./g++-include/generic.h100644 0 1 3372 5522102317 13337 0ustar rootdaemon// 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) 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. */ #ifndef generic_h #define generic_h 1 /* * See the CPP manual, argument prescan section for explanation */ #define name2(a,b) gEnErIc2(a,b) #define gEnErIc2(a,b) a ## b #define name3(a,b,c) gEnErIc3(a,b,c) #define gEnErIc3(a,b,c) a ## b ## c #define name4(a,b,c,d) gEnErIc4(a,b,c,d) #define gEnErIc4(a,b,c,d) a ## b ## c ## d #define GENERIC_STRING(a) gEnErIcStRiNg(a) #define gEnErIcStRiNg(a) #a #define declare(clas,t) name2(clas,declare)(t) #define declare2(clas,t1,t2) name2(clas,declare2)(t1,t2) #define implement(clas,t) name2(clas,implement)(t) #define implement2(clas,t1,t2) name2(clas,implement2)(t1,t2) //extern genericerror(int,char*); typedef int (*GPT)(int,char*); #define set_handler(gen,type,x) name4(set_,type,gen,_handler)(x) #define errorhandler(gen,type) name3(type,gen,handler) #define callerror(gen,type,a,b) (*errorhandler(gen,type))(a,b) #endif generic_h ./g++-include/getpagesize.h100644 0 1 727 5522102320 14205 0ustar rootdaemon#if defined(BSD) || defined(DGUX) #ifndef BSD4_1 #define HAVE_GETPAGESIZE #endif #endif #ifndef HAVE_GETPAGESIZE #include #ifdef EXEC_PAGESIZE #define getpagesize() EXEC_PAGESIZE #else #ifdef NBPG #define getpagesize() NBPG * CLSIZE #ifndef CLSIZE #define CLSIZE 1 #endif /* no CLSIZE */ #else /* no NBPG */ #ifdef NBPC #define getpagesize() NBPC #endif /* NBPC */ #endif /* no NBPG */ #endif /* no EXEC_PAGESIZE */ #endif /* not HAVE_GETPAGESIZE */ ./g++-include/libc.h100644 0 1 24 5522102321 12556 0ustar rootdaemon#include ./g++-include/minmax.h100644 0 1 4655 5522102322 13215 0ustar rootdaemon/* Copyright (C) 1992 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) 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. */ #ifndef _minmax_h #ifdef _GNUG_ #pragma interface #endif #define _minmax_h 1 #include <_G_config.h> inline char min(char a, char b) { return (a < b)?a:b;} #ifndef _G_BROKEN_SIGNED_CHAR inline signed char min(signed char a, signed char b) { return (a < b)?a:b;} #endif inline unsigned char min(unsigned char a, unsigned char b) {return (a b)?a:b;} #ifndef _G_BROKEN_SIGNED_CHAR inline signed char max(signed char a, signed char b) {return (a > b)?a:b;} #endif inline unsigned char max(unsigned char a, unsigned char b) {return (a>b)?a:b;} inline short max(short a, short b) {return (a > b) ?a:b;} inline unsigned short max(unsigned short a, unsigned short b) {return (a > b)?a:b;} inline int max(int a, int b) {return (a > b)?a:b;} inline unsigned int max(unsigned int a, unsigned int b) {return (a > b)?a:b;} inline long max(long a, long b) {return (a > b)?a:b;} inline unsigned long max(unsigned long a, unsigned long b) {return (a>b)?a:b;} inline float max(float a, float b) {return (a > b)?a:b;} inline double max(double a, double b) {return (a > b)?a:b;} #endif ./g++-include/new.h100644 0 1 1436 5522102323 12510 0ustar rootdaemon#ifndef _new_h #ifdef __GNUG__ #pragma interface #endif #define _new_h 1 #include #include #ifndef NO_LIBGXX_MALLOC #define MALLOC_ALIGN_MASK 7 /* ptrs aligned at 8 byte boundaries */ #define MALLOC_MIN_OVERHEAD 8 /* 8 bytes of overhead per pointer */ #endif typedef void (*new_handler_t)(); extern new_handler_t __new_handler; extern "C" void default_new_handler(); extern "C" new_handler_t set_new_handler(new_handler_t); #ifdef __GNUG__ #define NEW(where) new { where } #endif // default placement version of operator new static inline void *operator new(size_t, void *place) { return place; } // provide a C++ interface to vector-resize via realloc inline void *operator new(size_t size, void *ptr, size_t new_len) { return realloc(ptr, new_len * size); } #endif ./g++-include/osfcn.h100644 0 1 355 5522102323 13006 0ustar rootdaemon #ifndef OSFCN_H #define OSFCN_H 1 #include #include #include #if _G_HAVE_SYS_SOCKET #include #endif #if _G_HAVE_SYS_RESOURCE #include #include #endif #endif ./g++-include/std.h100644 0 1 2204 5522102325 12505 0ustar rootdaemon// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988, 1992 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) 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. */ #ifndef _std_h #define _std_h 1 #include <_G_config.h> #include #include #include #include #include #include #include extern "C" { int strcasecmp _G_ARGS((const char*, const char*)); } #endif ./g++-include/strclass.h100644 0 1 140 5522102326 13527 0ustar rootdaemon#ifndef _strclass_h #define _strclass_h #include typedef class String string; #endif ./g++-include/swap.h100644 0 1 205 5522102327 12646 0ustar rootdaemon/* From Ron Guillmette; apparently needed for Hansen's code */ #define swap(a,b) ({ typeof(a) temp = (a); (a) = (b); (b) = temp; }) ./g++-include/typemacros.h100644 0 1 414 5522102330 14056 0ustar rootdaemon#define _T(type) typeof(type) #define pointer_to(type) _T(_T(type)*) #define member_of(cls,type) _T(_T(type) cls::) #define function(res, args) _T(_T(res) args) #define _xq_yq(x,y) x ## _ ## y #define _x_y(x,y) _xq_yq(x,y) #define _gensym(stem) _x_y(stem, __LINE__)