# HG changeset patch # User jwe # Date 780936469 0 # Node ID 2d2f3c07ceddfcbee20e3389a470d70b5210c528 # Parent d8295febb0df5c737e5f1a07c422b6114dfba6df [project @ 1994-09-30 14:47:29 by jwe] Initial revision diff --git a/src/Queue.h b/src/Queue.h new file mode 100644 --- /dev/null +++ b/src/Queue.h @@ -0,0 +1,57 @@ +// 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 +#define _Queue_h 1 + +#if defined (__GNUG__) && defined (USE_EXTERNAL_TEMPLATES) +//#pragma interface +#endif + +template +class +Queue +{ +public: + Queue (void) { } + + virtual ~Queue (void) { } + + virtual void enq (const T& item) = 0; + + virtual T deq (void) = 0; + + virtual T& front (void) = 0; + + virtual void del_front (void) = 0; + + virtual void clear (void) = 0; + + virtual int empty (void) const = 0; + + virtual int full (void) const = 0; + + virtual int length (void) const = 0; + + void error (const char*); + + virtual int OK (void) = 0; +}; + +#endif diff --git a/src/SLQueue.h b/src/SLQueue.h new file mode 100644 --- /dev/null +++ b/src/SLQueue.h @@ -0,0 +1,72 @@ +// 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. +*/ + + +#if !defined (_SLQueue_h) +#define _SLQueue_h 1 + +#if defined (__GNUG__) && defined (USE_EXTERNAL_TEMPLATES) +//#pragma interface +#endif + +#include "SLList.h" +#include "Queue.h" + +template +class +SLQueue : public Queue +{ + private: + SLList p; + + public: + SLQueue (void) : p () { } + + SLQueue (const SLQueue& q) : p (q.p) { } + + ~SLQueue (void) { } + + void operator = (const SLQueue& s) { p = s.p; } + + void enq (const T& item) { p.append (item); } + + T deq (void) { return p.remove_front (); } + + T& front (void) { return p.front (); } + + void del_front (void) { p.del_front (); } + + void clear (void) { p.clear (); } + + int empty (void) const { return p.empty (); } + + int full (void) const { return 0; } + + int length (void) const { return p.length (); } + + int OK (void) { return p.OK (); } +}; + +#endif + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; page-delimiter: "^/\\*" *** +;;; End: *** +*/ diff --git a/src/tMap.cc b/src/tMap.cc new file mode 100644 --- /dev/null +++ b/src/tMap.cc @@ -0,0 +1,91 @@ +#include +#include +#include + +#include "Map.h" + +int SIZE; + +char **keys; +double *values; + +void +add (char *x[], double y[], Map& a) +{ + for (int i = 0; i < SIZE; ++i) + a[x[i]] = y[i]; +} + +void +makekeys (void) +{ + for (int i = 0; i < SIZE; ++i) + { + char *tmp = new char [10]; + sprintf (tmp, "index_%d", i); + keys[i] = tmp; + } +} + +void +makevalues (void) +{ + for (int i = 0; i < SIZE; ++i) + values[i] = i + 1; +} + +void +printMap (Map& a) +{ + int maxprint = 1000; + cout << "["; + int k = 0; + for (Pix i = a.first (); i != 0 && k < maxprint; a.next (i), ++k) + cout << "(" << a.key (i) << ", " << a.contents (i) << ") "; + + if (i != 0) + cout << "...]\n"; + else + cout << "]\n"; +} + +void +CHtest (void) +{ + CHMap a (-1.0, SIZE); + add (keys, values, a); + + cout << "a: "; + printMap (a); + + assert (a.length () == SIZE); + + for (int j = 0; j < SIZE; ++j) + assert (a.contains (keys[j])); + +// assert (a[SIZE+1] = -1); + + for (j = 0; j < SIZE; ++j) + a.del (keys[j]); + + assert (a.empty ()); + + assert (a.OK ()); +} + +int +main (int argv, char** argc) +{ + SIZE = 100; + + keys = new char *[SIZE]; + makekeys (); + + values = new double [SIZE]; + makevalues (); + + cout << "CHtest\n"; + CHtest(); + + return 0; +}