#include <Set.h>
Inheritance diagram for Core::Set:
Public Member Functions | |
Set (int length=2) | |
virtual | ~Set (void) |
Set (Set &origin) | |
virtual String * | className (void) const |
Answer receiver class name. | |
virtual long | capacity (void) const |
Answer how many elements can be stored in the collection. | |
virtual long | size (void) const |
Answer how many elements the collection includes. | |
virtual Object * | any (void) |
Answer any item from the collection. | |
virtual void | add (Object *obj) |
virtual Set * | asSet (void) |
virtual Object * | copy (void) |
virtual Object * | copyEmpty (long size) |
virtual Object * | remove (Object *obj) |
virtual bool | includes (Object *obj) |
virtual void | atNewIndexPut (int index, Object *obj) |
virtual int | findElementOrNil (Object *obj) |
virtual bool | isEmptyAt (int index) |
virtual Object * | privAtIndex (int index) |
Protected Member Functions | |
virtual Object * | privNextForIterator (CollectionIterator *iter) const |
virtual void | changeCapacity (long newCapacity) |
virtual void | fixCollisionsFrom (int index) |
virtual void | fullCheck (void) |
virtual void | grow (void) |
Protected Attributes | |
Array * | content |
int | tally |
|
Definition at line 32 of file Set.cc. References content, and tally. Referenced by copy(), and copyEmpty().
|
|
Definition at line 38 of file Set.cc. References content. 00039 { 00040 delete content; 00041 }
|
|
Definition at line 44 of file Set.cc. References content, Core::Array::copy(), and tally.
|
|
Reimplemented from Core::Collection. Reimplemented in Core::Dictionary. Definition at line 73 of file Set.cc. References atNewIndexPut(), findElementOrNil(), isEmptyAt(), and nil. Referenced by Core::Collection::asSet(), changeCapacity(), Tools::Configuration::keys(), OS::Thread::run(), and OS::Process::run(). 00074 { 00075 int index; 00076 00077 if (obj == nil) return; 00078 index = findElementOrNil(obj); 00079 if (isEmptyAt(index)) 00080 atNewIndexPut(index, obj); 00081 }
|
|
Answer any item from the collection.
Reimplemented from Core::Collection. Definition at line 67 of file Set.cc. References Core::Array::any(), and content.
|
|
Reimplemented from Core::Collection. Definition at line 84 of file Set.cc. 00085 { 00086 return this; 00087 }
|
|
Definition at line 140 of file Set.cc. References content, fullCheck(), Core::Array::put(), and tally. Referenced by add(), Core::Dictionary::add(), and Core::Dictionary::put().
|
|
Answer how many elements can be stored in the collection.
Reimplemented from Core::Collection. Definition at line 57 of file Set.cc. References content, and Core::Array::size(). Referenced by findElementOrNil(), Core::Dictionary::findKeyOrNil(), fixCollisionsFrom(), Core::Dictionary::fixCollisionsFrom(), fullCheck(), grow(), and privNextForIterator().
|
|
Reimplemented in Core::Dictionary. Definition at line 147 of file Set.cc. References add(), content, Core::Iterator::finished(), Core::Collection::iterator(), Core::Iterator::next(), nil, tally, and Core::Iterator::value(). Referenced by grow(). 00148 { 00149 Array *oldContent; 00150 Iterator *i; 00151 00152 oldContent = content; 00153 content = new Array(newCapacity); 00154 tally = 0; 00155 for (i = oldContent->iterator(); !i->finished(); i->next()) { 00156 if (i->value() != nil) 00157 add(i->value()); 00158 } 00159 delete i; 00160 delete oldContent; 00161 }
|
|
Answer receiver class name. Because there isn't any standard way to obtain class name this method comes to place. Every class should rewrite this method but many didn't (yet). Reimplemented from Core::Collection. Reimplemented in Core::Dictionary. Definition at line 51 of file Set.cc. 00052 { 00053 return new String("Set"); 00054 }
|
|
Reimplemented from Core::Collection. Reimplemented in Core::Dictionary. Definition at line 90 of file Set.cc. References Set(). Referenced by OS::Process::finalizeProcesses(), OS::Thread::finalizeThreads(), and OS::Process::sigchildHandler(). 00091 { 00092 return new Set(*this); 00093 }
|
|
Reimplemented from Core::Collection. Reimplemented in Core::Dictionary. Definition at line 95 of file Set.cc. References Set().
|
|
Definition at line 163 of file Set.cc. References Core::Array::at(), capacity(), content, grow(), Core::Object::hash(), Core::Object::isEqual(), and nil. Referenced by add(), fixCollisionsFrom(), includes(), and remove(). 00164 { 00165 int pass, length = capacity(); 00166 Object *elem; 00167 int index; 00168 00169 index = obj->hash() % length; 00170 /* Unfortunately, result of modulo can be negative */ 00171 if (index < 0) index = length + index; 00172 pass = 1; 00173 while ((elem = content->at(index)) != nil && !elem->isEqual(obj)) { 00174 index++; 00175 if (index >= length) { 00176 index = 0; 00177 pass++; 00178 if (pass > 2) { 00179 grow(); 00180 return findElementOrNil(obj); 00181 } 00182 } 00183 } 00184 return index; 00185 }
|
|
Reimplemented in Core::Dictionary. Definition at line 187 of file Set.cc. References Core::Array::at(), capacity(), content, findElementOrNil(), nil, and Core::Array::put(). Referenced by remove(). 00188 { 00189 int length, nextIndex; 00190 Object *nextObject = nil; 00191 00192 length = capacity(); 00193 nextIndex = oldIndex; 00194 do { 00195 if (nextIndex != oldIndex) { 00196 content->put(nextIndex, nextObject); 00197 content->put(oldIndex, nil); 00198 } 00199 oldIndex = (oldIndex + 1) % length; 00200 nextObject = content->at(oldIndex); 00201 if (nextObject != nil) 00202 nextIndex = findElementOrNil(nextObject); 00203 } while (nextObject != nil); 00204 }
|
|
Definition at line 206 of file Set.cc. References capacity(), grow(), and size(). Referenced by atNewIndexPut(). 00207 { 00208 int sizePlusOne, cap; 00209 00210 cap = capacity(); 00211 sizePlusOne = size() + 1; 00212 if (sizePlusOne >= cap || cap - sizePlusOne < (cap >> 2)) 00213 grow(); 00214 }
|
|
Definition at line 216 of file Set.cc. References capacity(), changeCapacity(), and Core::Collection::growSize(). Referenced by findElementOrNil(), Core::Dictionary::findKeyOrNil(), and fullCheck(). 00217 { 00218 changeCapacity(capacity() + growSize()); 00219 }
|
|
Reimplemented from Core::Collection. Reimplemented in Core::Dictionary. Definition at line 117 of file Set.cc. References findElementOrNil(), and isEmptyAt(). 00118 { 00119 return !isEmptyAt(findElementOrNil(obj)); 00120 }
|
|
Definition at line 221 of file Set.cc. References Core::Array::at(), content, and nil. Referenced by add(), includes(), and remove().
|
|
Definition at line 226 of file Set.cc. References Core::Array::at(), and content.
|
|
Reimplemented from Core::Collection. Definition at line 124 of file Set.cc. References Core::Array::at(), capacity(), content, nil, and Core::CollectionIterator::position(). 00125 { 00126 Object *obj; 00127 long index = iter->position(); 00128 00129 for (; index < capacity(); index += 1) { 00130 if ((obj = content->at(index)) != nil) { 00131 iter->position(index); 00132 return obj; 00133 } 00134 } 00135 iter->position(index); 00136 return nil; 00137 }
|
|
Reimplemented from Core::Collection. Reimplemented in Core::Dictionary. Definition at line 101 of file Set.cc. References content, findElementOrNil(), fixCollisionsFrom(), isEmptyAt(), nil, Core::Array::put(), and tally. Referenced by OS::Thread::finalize(), and OS::Process::finalize(). 00102 { 00103 int index; 00104 00105 index = findElementOrNil(obj); 00106 if (isEmptyAt(index)) { 00107 (new NotFoundError(__PRETTY_FUNCTION__, obj))->raiseFrom(this); 00108 } else { 00109 content->put(index, nil); 00110 tally = tally - 1; 00111 fixCollisionsFrom(index); 00112 } 00113 return obj; 00114 }
|
|
Answer how many elements the collection includes.
Reimplemented from Core::Collection. Definition at line 62 of file Set.cc. References tally. Referenced by fullCheck(), and Tools::Configuration::keys(). 00063 { 00064 return tally; 00065 }
|
|
|
Definition at line 39 of file Set.h. Referenced by atNewIndexPut(), changeCapacity(), Core::Dictionary::changeCapacity(), Core::Dictionary::noCheckAdd(), remove(), Core::Dictionary::removeKey(), Set(), and size(). |