University of Sheffield   

    The Simons
    Component Library

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

Set.h

00001 
00002 //
00003 //  SCL : Simons Component Library
00004 //
00006 //
00007 //  Filename:   Set.h
00008 //  Contents:   Set 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_SET
00020 #define SCL_SET
00021 
00022 #include "Unordered.h"          // Include my superclass type
00023 #include "SetID.h"              // Include my pointer type
00024 
00025 #include "EntryID.h"            // Depend on the pointer type
00026 
00043 
00044 class Set : public Unordered {
00045 private:
00046         Natural alloc;                  // capacity of table
00047         Natural items;                  // count of elements
00048         ObjectID* block;
00049         struct Memo {
00050                 Integer index;          // index of item-rank
00051                 Integer slot;           // place in hash table
00052                 Memo() : index(0), slot(0) {}
00053         } *memo;
00054         enum Constants { OFFSET = 3 };
00055         Integer locate(ObjectID) const;
00056         Void expand();                  // expand hash table
00057         Void compact(Integer);          // rehash after remove
00058         Void memoSeek(Integer) const;   // find ith element
00059         Void memoReset() const;         // find 0th element
00060 protected:
00061         Set(const Set&);
00062         Void deepRemove(EntryID);
00063 public:
00064         Set();
00065         virtual ~Set();
00066         Set(CollectionID);
00067         virtual ObjectID clone() const;
00068         virtual Natural size() const;
00069         virtual Boolean has(ObjectID) const;
00070         virtual Natural count(ObjectID) const;
00071         virtual ObjectID find(ObjectID) const;
00072         virtual ObjectID item(Integer) const;
00073         virtual Void add(ObjectID);
00074         virtual Void remove(ObjectID);
00075 };
00076 
00078 
00081 inline SetID::SetID() {}
00082 
00084 inline SetID::~SetID() {}
00085 
00089 inline SetID::SetID(const Null* null) :
00090         UnorderedID(null) {}
00091         
00095 inline SetID::SetID(const Set* set) :
00096         UnorderedID(set) {}
00097         
00101 inline SetID::SetID(const SetID& pointer) :
00102         UnorderedID(pointer) {}
00103         
00107 inline SetID& SetID::operator=(const Set* set) {
00108         assign(set);
00109         return *this;
00110 }
00111 
00116 inline SetID& SetID::operator=(const SetID& pointer) {
00117         assign(pointer);
00118         return *this;
00119 }
00120 
00121 
00122 #endif
00123 

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