University of Sheffield   

    The Simons
    Component Library

Introduction   Class Hierarchy   Class Listing   Index of Classes   Index of Methods   Header Files  

Bag.h

00001 
00002 //
00003 //  SCL : Simons Component Library
00004 //
00006 //
00007 //  Filename:   Bag.h
00008 //  Contents:   Bag class
00009 //  Author:     Anthony J H Simons
00010 //  Revised:    22 November 2005
00011 
00012 // This software is distributed free in the hope that others will
00013 // find it useful.  However, it comes WITHOUT ANY WARRANTY.  No
00014 // liability can be accepted for software failure, merchantability
00015 // or fitness for a particular purpose.  You can redistribute this
00016 // software in its original form, or in a modified form, provided
00017 // that this disclaimer is retained in the file banner.
00018 
00019 #ifndef SCL_BAG
00020 #define SCL_BAG
00021 
00022 #include "Unordered.h"          // Include my superclass type
00023 #include "BagID.h"              // Include my pointer type
00024 
00025 #include "EntryID.h"            // Depend on the pointer type
00026 
00044 
00045 class Bag : public Unordered {
00046 private:
00047         Natural alloc;                  // capacity of table
00048         Natural slots;                  // used hash table slots
00049         Natural items;                  // count of elements
00050         struct Link {
00051                 ObjectID item;
00052                 Link* next;
00053                 Link(ObjectID& o, Link* n) : item(o), next(n) {}
00054         } **block;
00055         struct Memo {
00056                 Integer index;          // index of item-rank
00057                 Integer slot;           // place in hash table
00058                 Link* link;             // referenced link
00059                 Memo() : index(0), slot(0), link(0) {}
00060         } *memo;
00061         enum Constants { OFFSET = 3 };
00062         Integer locate(ObjectID) const;
00063         Void expand();                  // expand hash table
00064         Void compact(Integer);          // rehash after remove
00065         Void memoSeek(Integer) const;   // find ith element
00066         Void memoReset() const;         // find 0th element
00067 protected:
00068         Bag(const Bag&);
00069         Void deepAdd(EntryID);
00070         Void deepRemove(EntryID);
00071 public:
00072         Bag();
00073         virtual ~Bag();
00074         Bag(CollectionID);
00075         virtual ObjectID clone() const;
00076         virtual Natural size() const;
00077         virtual Boolean has(ObjectID) const;
00078         virtual Natural count(ObjectID) const;
00079         virtual ObjectID find(ObjectID) const;
00080         virtual ObjectID item(Integer) const;
00081         virtual Void add(ObjectID);
00082         virtual Void remove(ObjectID);
00083         Void clear(ObjectID);
00084 };
00085 
00086 
00088 
00091 inline BagID::BagID() {}
00092 
00094 inline BagID::~BagID() {}
00095 
00099 inline BagID::BagID(const Null* null) :
00100         UnorderedID(null) {}
00101         
00105 inline BagID::BagID(const Bag* bag) :
00106         UnorderedID(bag) {}
00107         
00111 inline BagID::BagID(const BagID& pointer) :
00112         UnorderedID(pointer) {}
00113         
00117 inline BagID& BagID::operator=(const Bag* bag) {
00118         assign(bag);
00119         return *this;
00120 }
00121 
00126 inline BagID& BagID::operator=(const BagID& pointer) {
00127         assign(pointer);
00128         return *this;
00129 }
00130 
00131 
00132 #endif

Generated on Fri May 5 17:17:15 2006 for The Simons Component Library by doxygen1.3