53 _sz(sz), _free(capacity()),
58 for (
Int_t i = 0; i < _free; ++i)
59 _chunk[i]._next = (i + 1 < _free) ? &_chunk[i + 1] : 0;
62 ~Chunk() {
delete[] _chunk; }
64 Int_t capacity()
const 69 Int_t size()
const {
return capacity() -
free(); }
71 int szclass()
const {
return _sz; }
73 bool full()
const {
return !
free(); }
75 bool empty()
const {
return capacity() ==
free(); }
77 const void* chunkaddr()
const {
return _chunk; }
80 {
return _chunk <= el && el < &_chunk[capacity()]; }
84 if (!_freelist)
return 0;
86 _freelist = retVal->
_next;
95 el->
_next = _freelist;
119 typedef RooLinkedListImplDetails::Chunk Chunk;
120 typedef std::list<Chunk*> ChunkList;
121 typedef std::map<const void*, Chunk*> AddrMap;
128 inline void acquire() { ++_refCount; }
130 inline bool release() {
return 0 == --_refCount; }
138 UInt_t _szmap[(maxsz - minsz) / szincr];
145 Int_t nextChunkSz()
const;
148 Pool::Pool() : _cursz(minsz), _refCount(0)
150 std::fill(_szmap, _szmap + ((maxsz - minsz) / szincr), 0);
156 for (AddrMap::iterator it = _addrmap.begin(); _addrmap.end() != it; ++it)
163 if (_freelist.empty()) {
165 const Int_t sz = nextChunkSz();
166 Chunk *c =
new Chunk(sz);
167 _addrmap[c->chunkaddr()] = c;
168 _freelist.push_back(c);
172 Chunk* c = _freelist.front();
175 if (c->full()) _freelist.pop_front();
182 AddrMap::iterator ci = _addrmap.end();
183 if (!_addrmap.empty()) {
184 ci = _addrmap.lower_bound(el);
185 if (ci == _addrmap.end()) {
187 ci = (++_addrmap.rbegin()).base();
191 if (_addrmap.begin() != ci && ci->first != el) --ci;
196 if (_addrmap.empty() || !ci->second->contains(el)) {
201 Chunk *c = ci->second;
202 const bool moveToFreelist = c->full();
203 c->push_free_elem(el);
206 ChunkList::iterator it = std::find( _freelist.begin(), _freelist.end(), c);
207 if (_freelist.end() != it) _freelist.erase(it);
208 _addrmap.erase(ci->first);
209 updateCurSz(c->szclass(), -1);
211 }
else if (moveToFreelist) {
212 _freelist.push_back(c);
218 _szmap[(sz - minsz) / szincr] += incr;
220 for (
int i = (maxsz - minsz) / szincr; i--; ) {
222 _cursz += i * szincr;
228 Int_t Pool::nextChunkSz()
const 232 if (_addrmap.empty()) {
240 if (1 != _addrmap.size()) {
250 if (sz > maxsz) sz = maxsz;
251 if (sz < minsz) sz = minsz;
261 _hashThresh(htsize), _size(0), _first(0), _last(0), _htableName(0), _htableLink(0), _useNptr(
kTRUE)
280 Add(elem->_arg, elem->_refCount) ;
290 ret->
init(obj, elem);
299 _pool->push_free_elem(elem);
309 if (&other==
this)
return *this ;
328 coutE(
InputArguments) <<
"RooLinkedList::setHashTable() ERROR size must be positive" << endl ;
376 if (
_pool->release()) {
393 if (ptr->
_arg == arg) {
452 if (!elem)
return kFALSE ;
479 if (index<0 || index>=
_size)
return 0 ;
484 while(index--) ptr = ptr->
_next ;
498 if (!elem)
return kFALSE ;
529 return elem ? elem->
_arg : 0 ;
677 if (ptr->
_arg==arg)
return idx ;
708 cout << elem->
_arg <<
" : " ;
747 template <
bool ascending>
753 if (tail) *tail = l1;
758 #if !defined(_WIN32) && !defined(R__SOLARIS_CC50) 760 #else // _WIN32 && Solaris 766 for (
int i = 0; l1; l1 = l1->
_next, ++i) arr[i] = l1;
774 const bool inOrder = ascending ?
776 (arr[j]->_arg->Compare(tmp->
_arg) <= 0);
783 }
while (
int(sz) != i);
787 for (
int i = 0; i < int(sz - 1); ++i) {
788 arr[i]->
_next = arr[i + 1];
789 arr[i + 1]->
_prev = arr[i];
791 if (tail) *tail = arr[sz - 1];
799 if (!end->_next)
break;
805 if (l1->
_next) l1 = mergesort_impl<ascending>(l1, sz / 2);
806 if (l2->
_next) l2 = mergesort_impl<ascending>(l2, sz - sz / 2);
810 (l2->_arg->Compare(l1->_arg) <= 0)) ? l1 : l2;
819 const bool inOrder = ascending ? (l1->_arg->Compare(l2->_arg) <= 0) :
820 (l2->_arg->Compare(l1->_arg) <= 0);
839 if (t) t->
_next = l2;
843 for (l1 = t; l1; l1 = l1->
_next) t = l1;
863 void RooLinkedList::Streamer(
TBuffer &R__b)
869 TObject::Streamer(R__b);
886 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.
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.
Bool_t TestBit(UInt_t f) const
TObject * find(const char *name) const
Return pointer to object with given name in collection.
Buffer base class used for serializing objects.
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
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)