Grafalgo
Library of useful data structures and algorithms
/Users/jst/src/grafalgo/cpp/include/ListSet.h
Go to the documentation of this file.
00001 
00009 #ifndef UILISTSET_H
00010 #define UILISTSET_H
00011 
00012 #include "Adt.h"
00013 
00014 namespace grafalgo {
00015 
00016 typedef int32_t alist;
00017 
00022 class ListSet : public Adt {
00023 public:         ListSet(int=26,int=5);
00024                 ~ListSet();
00025 
00026         // common methods
00027         void    clear();
00028         void    resize(int siz) { resize(siz,siz); }
00029         void    resize(int,int);
00030         void    expand(int siz) { expand(siz,siz); }
00031         void    expand(int,int);
00032         void    copyFrom(const ListSet&);
00033 
00034         // access items in list
00035         index   next(index) const;      
00036         index   first(alist) const;
00037         index   last(alist) const;      
00038 
00039         // predicates
00040         bool    member(index) const;
00041         bool    empty(alist) const;
00042 
00043         // modifiers
00044         void    addLast(index, alist);
00045         void    addFirst(index,alist);
00046         index   removeFirst(alist);
00047 
00048         // input/output
00049         string& toString(string&) const;
00050         string& list2string(alist, string&) const;
00051 private:
00052         int     nlst;                   // lists 1..nlst
00053         struct listhdr {
00054                 alist head, tail;
00055         };
00056         listhdr *lh;                    // array of list headers
00057         index   *nxt;                   // next[i] is successor of i
00058 
00059         void    makeSpace(int,int);
00060         void    freeSpace();
00061 };
00062 
00067 inline index ListSet::first(alist lst) const { return lh[lst].head; }
00068 
00073 inline index ListSet::last(alist lst) const { return lh[lst].tail; }
00074 
00079 inline bool ListSet::empty(alist lst) const { return lh[lst].head == 0; }
00080 
00085 inline bool ListSet::member(index i) const { return nxt[i] != -1; }
00086 
00091 inline index ListSet::next(index i) const { return nxt[i]; }
00092 
00093 } // ends namespace
00094 
00095 #endif
 All Classes Files Functions Variables Typedefs Friends