50 _sz(sz), _free(capacity()),
55 for (
Int_t i = 0; i < _free; ++i)
56 _chunk[i]._next = (i + 1 < _free) ? &_chunk[i + 1] : 0;
59 ~Chunk() {
delete[] _chunk; }
61 Int_t capacity()
const
66 Int_t size()
const {
return capacity() -
free(); }
68 int szclass()
const {
return _sz; }
70 bool full()
const {
return !
free(); }
72 bool empty()
const {
return capacity() ==
free(); }
74 const void* chunkaddr()
const {
return _chunk; }
77 {
return _chunk <= el && el < &_chunk[capacity()]; }
81 if (!_freelist)
return 0;
83 _freelist = retVal->
_next;
92 el->
_next = _freelist;
116 typedef RooLinkedListImplDetails::Chunk Chunk;
117 typedef std::list<Chunk*> ChunkList;
118 typedef std::map<const void*, Chunk*> AddrMap;
125 inline void acquire() { ++_refCount; }
127 inline bool release() {
return 0 == --_refCount; }
135 UInt_t _szmap[(maxsz - minsz) / szincr];
142 Int_t nextChunkSz()
const;
145 Pool::Pool() : _cursz(minsz), _refCount(0)
147 std::fill(_szmap, _szmap + ((maxsz - minsz) / szincr), 0);
153 for (AddrMap::iterator it = _addrmap.begin(); _addrmap.end() != it; ++it)
160 if (_freelist.empty()) {
162 const Int_t sz = nextChunkSz();
163 Chunk *c =
new Chunk(sz);
164 _addrmap[c->chunkaddr()] =
c;
165 _freelist.push_back(c);
169 Chunk* c = _freelist.front();
172 if (c->full()) _freelist.pop_front();
179 AddrMap::iterator ci = _addrmap.end();
180 if (!_addrmap.empty()) {
181 ci = _addrmap.lower_bound(el);
182 if (ci == _addrmap.end()) {
184 ci = (++_addrmap.rbegin()).base();
188 if (_addrmap.begin() != ci && ci->first != el) --ci;
193 if (_addrmap.empty() || !ci->second->contains(el)) {
198 Chunk *c = ci->second;
199 const bool moveToFreelist = c->full();
200 c->push_free_elem(el);
203 ChunkList::iterator it = std::find( _freelist.begin(), _freelist.end(),
c);
204 if (_freelist.end() != it) _freelist.erase(it);
205 _addrmap.erase(ci->first);
206 updateCurSz(c->szclass(), -1);
208 }
else if (moveToFreelist) {
209 _freelist.push_back(c);
215 _szmap[(sz - minsz) / szincr] += incr;
217 for (
int i = (maxsz - minsz) / szincr; i--; ) {
219 _cursz += i * szincr;
225 Int_t Pool::nextChunkSz()
const
229 if (_addrmap.empty()) {
237 if (1 != _addrmap.size()) {
247 if (sz > maxsz) sz = maxsz;
248 if (sz < minsz) sz = minsz;
258 _hashThresh(htsize), _size(0), _first(0), _last(0), _htableName(0), _htableLink(0), _useNptr(
kTRUE)
268 TObject(other), _hashThresh(other._hashThresh), _size(0), _first(0), _last(0), _htableName(0), _htableLink(0),
270 _useNptr(other._useNptr)
277 Add(elem->_arg, elem->_refCount) ;
287 ret->
init(obj, elem);
296 _pool->push_free_elem(elem);
306 if (&other==
this)
return *this ;
325 coutE(
InputArguments) <<
"RooLinkedList::setHashTable() ERROR size must be positive" << endl ;
373 if (
_pool->release()) {
390 if (ptr->
_arg == arg) {
449 if (!elem)
return kFALSE ;
476 if (index<0 || index>=
_size)
return 0 ;
481 while(index--) ptr = ptr->
_next ;
495 if (!elem)
return kFALSE ;
526 return elem ? elem->
_arg : 0 ;
674 if (ptr->
_arg==arg)
return idx ;
705 cout << elem->
_arg <<
" : " ;
744 template <
bool ascending>
750 if (tail) *tail = l1;
755 #if !defined(_WIN32) && !defined(R__SOLARIS_CC50)
757 #else // _WIN32 && Solaris
763 for (
int i = 0; l1; l1 = l1->
_next, ++i) arr[i] = l1;
771 const bool inOrder = ascending ?
773 (arr[j]->_arg->Compare(tmp->
_arg) <= 0);
780 }
while (
int(sz) != i);
784 for (
int i = 0; i < int(sz - 1); ++i) {
785 arr[i]->
_next = arr[i + 1];
786 arr[i + 1]->
_prev = arr[i];
788 if (tail) *tail = arr[sz - 1];
796 if (!end->_next)
break;
802 if (l1->
_next) l1 = mergesort_impl<ascending>(l1, sz / 2);
803 if (l2->
_next) l2 = mergesort_impl<ascending>(l2, sz - sz / 2);
807 (l2->_arg->Compare(l1->_arg) <= 0)) ? l1 : l2;
816 const bool inOrder = ascending ? (l1->_arg->Compare(l2->_arg) <= 0) :
817 (l2->_arg->Compare(l1->_arg) <= 0);
836 if (t) t->
_next = l2;
840 for (l1 = t; l1; l1 = l1->
_next) t = l1;
860 void RooLinkedList::Streamer(
TBuffer &R__b)
866 TObject::Streamer(R__b);
883 TObject::Streamer(R__b);
static RooLinkedListElem * mergesort_impl(RooLinkedListElem *l1, const unsigned sz, RooLinkedListElem **tail=0)
length 0, 1 lists are sorted
void Print(const char *opt) const
Print contents of list, defers to Print() function of contained objects.
RooHashTable * _htableLink
Hash table by name.
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
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 the object with given name from the table.
Buffer base class used for serializing objects.
RooAbsArg * findArg(const RooAbsArg *) const
Return pointer to object with given name in collection.
Bool_t replace(const TObject *oldArg, const TObject *newArg, const TObject *oldHashArg=0)
Replace oldArg with newArg in the table.
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
Vc_ALWAYS_INLINE void free(T *p)
Frees memory that was allocated with Vc::malloc.
RooLinkedListElem * _next
RooLinkedListElem * _first
The TNamed class is the base class for all named ROOT classes.
const TNamed * namePtr() const
Int_t IndexOf(const char *name) const
Return position of given object in list.
TString _name
Hash table by link pointer.
TIterator * MakeIterator(Bool_t dir=kTRUE) const
Return an iterator over this list.
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
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)
Bool_t TestBit(UInt_t f) const
RooLinkedListElem * findLink(const TObject *arg) const
Find the element link containing the given object.
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
Bool_t remove(TObject *arg, TObject *hashArg=0)
Remove given object from table.
void Delete(Option_t *o=0)
Remove all elements in collection and delete all elements NB: Collection does not own elements...
virtual const char * GetName() const
Returns name of object.
RooFIter fwdIterator() const
TObject * At(Int_t index) const
Return object stored in sequential position given by index.
TObject * find(const char *name) const
Return pointer to object with given name in collection.
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
virtual ~RooLinkedList()
Destructor.
virtual Int_t Compare(const TObject *obj) const
Compare abstract method.
RooLinkedListIter iterator(Bool_t dir=kTRUE) const
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 ; ...
RooLinkedListElem * findLinkTo(const TObject *arg) const
Return RooLinkedList element link to object 'hashArg'.
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)