Mercurial > hg > octave-lyh
changeset 741:2d2f3c07cedd
[project @ 1994-09-30 14:47:29 by jwe]
Initial revision
author | jwe |
---|---|
date | Fri, 30 Sep 1994 14:47:49 +0000 |
parents | d8295febb0df |
children | 9004af8c7a33 |
files | src/Queue.h src/SLQueue.h src/tMap.cc |
diffstat | 3 files changed, 220 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
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 T> +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
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 T> +class +SLQueue : public Queue<T> +{ + private: + SLList<T> p; + + public: + SLQueue (void) : p () { } + + SLQueue (const SLQueue<T>& q) : p (q.p) { } + + ~SLQueue (void) { } + + void operator = (const SLQueue<T>& 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: *** +*/
new file mode 100644 --- /dev/null +++ b/src/tMap.cc @@ -0,0 +1,91 @@ +#include <iostream.h> +#include <assert.h> +#include <builtin.h> + +#include "Map.h" + +int SIZE; + +char **keys; +double *values; + +void +add (char *x[], double y[], Map<double>& 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<double>& 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<double> 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; +}