54 _sz(sz), _free(capacity()),
59 for (
Int_t i = 0; i < _free; ++i)
60 _chunk[i]._next = (i + 1 < _free) ? &_chunk[i + 1] : 0;
63 ~Chunk() {
delete[] _chunk; }
65 Int_t capacity()
const 70 Int_t size()
const {
return capacity() -
free(); }
72 int szclass()
const {
return _sz; }
74 bool full()
const {
return !
free(); }
76 bool empty()
const {
return capacity() ==
free(); }
78 const void* chunkaddr()
const {
return _chunk; }
81 {
return _chunk <= el && el < &_chunk[capacity()]; }
85 if (!_freelist)
return 0;
87 _freelist = retVal->
_next;
96 el->
_next = _freelist;
120 typedef RooLinkedListImplDetails::Chunk Chunk;
121 typedef std::list<Chunk*> ChunkList;
122 typedef std::map<const void*, Chunk*> AddrMap;
129 inline void acquire() { ++_refCount; }
131 inline bool release() {
return 0 == --_refCount; }
139 UInt_t _szmap[(maxsz - minsz) / szincr];
146 Int_t nextChunkSz()
const;
149 Pool::Pool() : _cursz(minsz), _refCount(0)
151 std::fill(_szmap, _szmap + ((maxsz - minsz) / szincr), 0);
157 for (AddrMap::iterator it = _addrmap.begin(); _addrmap.end() != it; ++it)
164 if (_freelist.empty()) {
166 const Int_t sz = nextChunkSz();
167 Chunk *
c =
new Chunk(sz);
168 _addrmap[c->chunkaddr()] =
c;
169 _freelist.push_back(c);
173 Chunk* c = _freelist.front();
176 if (c->full()) _freelist.pop_front();
183 AddrMap::iterator ci = _addrmap.end();
184 if (!_addrmap.empty()) {
185 ci = _addrmap.lower_bound(el);
186 if (ci == _addrmap.end()) {
188 ci = (++_addrmap.rbegin()).base();
192 if (_addrmap.begin() != ci && ci->first != el) --ci;
197 if (_addrmap.empty() || !ci->second->contains(el)) {
202 Chunk *c = ci->second;
203 const bool moveToFreelist = c->full();
204 c->push_free_elem(el);
207 ChunkList::iterator it = std::find( _freelist.begin(), _freelist.end(),
c);
208 if (_freelist.end() != it) _freelist.erase(it);
209 _addrmap.erase(ci->first);
210 updateCurSz(c->szclass(), -1);
212 }
else if (moveToFreelist) {
213 _freelist.push_back(c);
219 _szmap[(sz - minsz) / szincr] += incr;
221 for (
int i = (maxsz - minsz) / szincr; i--; ) {
223 _cursz += i * szincr;
229 Int_t Pool::nextChunkSz()
const 233 if (_addrmap.empty()) {
241 if (1 != _addrmap.size()) {
251 if (sz > maxsz) sz = maxsz;
252 if (sz < minsz) sz = minsz;
262 _hashThresh(htsize), _size(0), _first(0), _last(0), _htableName(0), _htableLink(0), _useNptr(
kTRUE)
281 Add(elem->_arg, elem->_refCount) ;
291 ret->
init(obj, elem);
300 _pool->push_free_elem(elem);
310 if (&other==
this)
return *this ;
329 coutE(
InputArguments) <<
"RooLinkedList::setHashTable() ERROR size must be positive" << endl ;
380 if (
_pool->release()) {
397 if (ptr->
_arg == arg) {
456 if (!elem)
return kFALSE ;
492 if (index<0 || index>=
_size)
return 0 ;
497 while(index--) ptr = ptr->
_next ;
511 if (!elem)
return kFALSE ;
542 return elem ? elem->
_arg : 0 ;
690 if (ptr->
_arg==arg)
return idx ;
721 cout << elem->
_arg <<
" : " ;
760 template <
bool ascending>
766 if (tail) *tail = l1;
771 #if !defined(_WIN32) && !defined(R__SOLARIS_CC50) 773 #else // _WIN32 && Solaris 779 for (
int i = 0; l1; l1 = l1->
_next, ++i) arr[i] = l1;
787 const bool inOrder = ascending ?
789 (arr[j]->_arg->Compare(tmp->
_arg) <= 0);
796 }
while (
int(sz) != i);
800 for (
int i = 0; i < int(sz - 1); ++i) {
801 arr[i]->
_next = arr[i + 1];
802 arr[i + 1]->
_prev = arr[i];
804 if (tail) *tail = arr[sz - 1];
812 if (!end->_next)
break;
818 if (l1->
_next) l1 = mergesort_impl<ascending>(l1, sz / 2);
819 if (l2->
_next) l2 = mergesort_impl<ascending>(l2, sz - sz / 2);
823 (l2->_arg->Compare(l1->_arg) <= 0)) ? l1 : l2;
832 const bool inOrder = ascending ? (l1->_arg->Compare(l2->_arg) <= 0) :
833 (l2->_arg->Compare(l1->_arg) <= 0);
852 if (t) t->
_next = l2;
856 for (l1 = t; l1; l1 = l1->
_next) t = l1;
876 void RooLinkedList::Streamer(
TBuffer &R__b)
882 TObject::Streamer(R__b);
893 if (v > 1 && v < 4) {
899 TObject::Streamer(R__b);
Int_t IndexOf(const char *name) const
Return position of given object in list.
static RooLinkedListElem * mergesort_impl(RooLinkedListElem *l1, const unsigned sz, RooLinkedListElem **tail=0)
length 0, 1 lists are sorted
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
RooHashTable * _htableLink
Hash table by name.
void CallRecursiveRemoveIfNeeded(TObject &obj)
call RecursiveRemove for obj if gROOT is valid and obj.TestBit(kMustCleanup) is true.
virtual Bool_t Remove(TObject *arg)
Remove object from collection.
void setHashTableSize(Int_t size)
Change the threshold for hash-table use to given size.
TObject * find(const char *name) const
Return pointer to object with given name in collection.
Buffer base class used for serializing objects.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
RooFIter fwdIterator() const
Bool_t replace(const TObject *oldArg, const TObject *newArg, const TObject *oldHashArg=0)
Replace oldArg with newArg in the table.
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
RooLinkedListImplDetails::Pool Pool
memory pool for quick allocation of RooLinkedListElems
void Clear(Option_t *o=0)
Remove all elements from collection.
Iterator abstract base class.
void Sort(Bool_t ascend=kTRUE)
Bool_t Replace(const TObject *oldArg, const TObject *newArg)
Replace object 'oldArg' in collection with new object 'newArg'.
friend class RooLinkedListIter
virtual void RecursiveRemove(TObject *obj)
If one of the TObject we have a referenced to is deleted, remove the reference.
RooLinkedListElem * findLinkTo(const TObject *arg) const
Return RooLinkedList element link to object 'hashArg'.
RooLinkedListElem * _next
RooLinkedListElem * _first
The TNamed class is the base class for all named ROOT classes.
TString _name
Hash table by link pointer.
RooHashTable implements a hash table for TObjects.
RooLinkedListElem * findLink(const TObject *arg) const
Find the element link containing the given object.
static const TNamed * known(const char *stringPtr)
If the name is already known, return its TNamed pointer. Otherwise return 0 (don't register the name)...
virtual void Add(TObject *arg)
void add(TObject *arg, TObject *hashArg=0)
Add given object to table.
RooLinkedListElem * _prev
RooLinkedList(Int_t htsize=0)
TObject * At(Int_t index) const
Return object stored in sequential position given by index.
RooLinkedListIter iterator(Bool_t dir=kTRUE) const
virtual Int_t Compare(const TObject *obj) const
Compare abstract method.
TObject * find(const char *name) const
Return the object with given name from the table.
Bool_t remove(TObject *arg, TObject *hashArg=0)
Remove given object from table.
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
void Delete(Option_t *o=0)
Remove all elements in collection and delete all elements NB: Collection does not own elements...
RooLinkedList & operator=(const RooLinkedList &other)
Assignment operator, copy contents from 'other'.
Binding & operator=(OUT(*fun)(void))
Mother of all ROOT objects.
RooLinkedListElem * _last
Link to first element of list.
void deleteElement(RooLinkedListElem *)
static Pool * _pool
shared memory pool for allocation of RooLinkedListElems
TIterator * MakeIterator(Bool_t dir=kTRUE) const
Return an iterator over this list.
void Print(const char *opt) const
Print contents of list, defers to Print() function of contained objects.
virtual ~RooLinkedList()
Destructor.
RooAbsArg * findArg(const RooAbsArg *) const
Return pointer to object with given name in collection.
RooLinkedListElem is an link element for the RooLinkedList class.
RooAbsArg * findArg(const RooAbsArg *arg) const
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
RooLinkedListElem * createElement(TObject *obj, RooLinkedListElem *elem=0)
cout << "RooLinkedList::createElem(" << this << ") obj = " << obj << " elem = " << elem << endl ; ...
virtual const char * GetName() const
Returns name of object.
RooLinkedListIter is the TIterator implementation for RooLinkedList.
const TNamed * namePtr() const
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
RooHashTable * _htableName
Link to last element of list.
void init(TObject *arg, RooLinkedListElem *after=0)