56 _sz(sz), _free(capacity()),
61 for (
Int_t i = 0; i < _free; ++i)
62 _chunk[i]._next = (i + 1 < _free) ? &_chunk[i + 1] : 0;
65 ~Chunk() {
delete[] _chunk; }
67 Int_t capacity()
const
72 Int_t size()
const {
return capacity() -
free(); }
74 int szclass()
const {
return _sz; }
76 bool full()
const {
return !
free(); }
78 bool empty()
const {
return capacity() ==
free(); }
80 const void* chunkaddr()
const {
return _chunk; }
83 {
return _chunk <= el && el < &_chunk[capacity()]; }
87 if (!_freelist)
return 0;
89 _freelist = retVal->
_next;
98 el->
_next = _freelist;
122 typedef RooLinkedListImplDetails::Chunk Chunk;
123 typedef std::list<Chunk*> ChunkList;
124 typedef std::map<const void*, Chunk*> AddrMap;
131 inline void acquire() { ++_refCount; }
133 inline bool release() {
return 0 == --_refCount; }
141 UInt_t _szmap[(maxsz - minsz) / szincr];
148 Int_t nextChunkSz()
const;
151 Pool::Pool() : _cursz(minsz), _refCount(0)
153 std::fill(_szmap, _szmap + ((maxsz - minsz) / szincr), 0);
159 for (AddrMap::iterator it = _addrmap.begin(); _addrmap.end() != it; ++it)
166 if (_freelist.empty()) {
168 const Int_t sz = nextChunkSz();
169 Chunk *
c =
new Chunk(sz);
170 _addrmap[
c->chunkaddr()] =
c;
171 _freelist.push_back(
c);
175 Chunk*
c = _freelist.front();
178 if (
c->full()) _freelist.pop_front();
185 AddrMap::iterator ci = _addrmap.end();
186 if (!_addrmap.empty()) {
187 ci = _addrmap.lower_bound(el);
188 if (ci == _addrmap.end()) {
190 ci = (++_addrmap.rbegin()).base();
194 if (_addrmap.begin() != ci && ci->first != el) --ci;
199 if (_addrmap.empty() || !ci->second->contains(el)) {
204 Chunk *
c = ci->second;
205 const bool moveToFreelist =
c->full();
206 c->push_free_elem(el);
209 ChunkList::iterator it = std::find( _freelist.begin(), _freelist.end(),
c);
210 if (_freelist.end() != it) _freelist.erase(it);
211 _addrmap.erase(ci->first);
212 updateCurSz(
c->szclass(), -1);
214 }
else if (moveToFreelist) {
215 _freelist.push_back(
c);
221 _szmap[(sz - minsz) / szincr] += incr;
223 for (
int i = (maxsz - minsz) / szincr; i--; ) {
225 _cursz += i * szincr;
231 Int_t Pool::nextChunkSz()
const
235 if (_addrmap.empty()) {
243 if (1 != _addrmap.size()) {
253 if (sz > maxsz) sz = maxsz;
254 if (sz < minsz) sz = minsz;
264 _hashThresh(htsize), _size(0), _first(0), _last(0), _htableName(0), _htableLink(0), _useNptr(
kTRUE)
274 TObject(other), _hashThresh(other._hashThresh), _size(0), _first(0), _last(0), _htableName(0), _htableLink(0),
276 _useNptr(other._useNptr)
283 Add(elem->_arg, elem->_refCount) ;
293 ret->
init(obj, elem);
302 _pool->push_free_elem(elem);
312 if (&other==
this)
return *this ;
331 coutE(InputArguments) <<
"RooLinkedList::setHashTable() ERROR size must be positive" << endl ;
382 if (
_pool->release()) {
399 if (ptr->
_arg == arg) {
459 if (!elem)
return kFALSE ;
474 auto at_elem_it = std::find(
_at.begin(),
_at.end(), elem);
475 _at.erase(at_elem_it);
499 if (index<0 || index>=
_size)
return 0 ;
501 return _at[index]->_arg;
520 if (!elem)
return kFALSE ;
551 return elem ? elem->
_arg : 0 ;
705 if (ptr->
_arg==arg)
return idx ;
736 cout << elem->
_arg <<
" : " ;
748 auto iterImpl = std::make_unique<RooLinkedListIterImpl>(
this, forward);
758 auto iterImpl = std::make_unique<RooLinkedListIterImpl>(
this, forward);
767 auto iterImpl = std::make_unique<RooFIterForLinkedList>(
this);
768 return RooFIter(std::move(iterImpl));
780 for (
auto it =
_at.begin(); it !=
_at.end(); ++it, elem = elem->
_next) {
788template <
bool ascending>
794 if (tail) *tail = l1;
799#if !defined(_WIN32) && !defined(R__SOLARIS_CC50)
807 for (
int i = 0; l1; l1 = l1->
_next, ++i) arr[i] = l1;
815 const bool inOrder = ascending ?
824 }
while (
int(sz) != i);
828 for (
int i = 0; i <
int(sz - 1); ++i) {
829 arr[i]->
_next = arr[i + 1];
830 arr[i + 1]->
_prev = arr[i];
832 if (tail) *tail = arr[sz - 1];
840 if (!end->_next)
break;
846 if (l1->
_next) l1 = mergesort_impl<ascending>(l1, sz / 2);
847 if (l2->
_next) l2 = mergesort_impl<ascending>(l2, sz - sz / 2);
880 if (t) t->
_next = l2;
884 for (l1 = t; l1; l1 = l1->
_next) t = l1;
904void RooLinkedList::Streamer(
TBuffer &R__b)
910 TObject::Streamer(R__b);
921 if (
v > 1 &&
v < 4) {
927 TObject::Streamer(R__b);
Binding & operator=(OUT(*fun)(void))
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
const TNamed * namePtr() const
A one-time forward iterator working on RooLinkedList or RooAbsCollection.
RooHashTable implements a hash table for TObjects.
Bool_t remove(TObject *arg, TObject *hashArg=0)
Remove given object from table.
RooLinkedListElem * findLinkTo(const TObject *arg) const
Return RooLinkedList element link to object 'hashArg'.
Bool_t replace(const TObject *oldArg, const TObject *newArg, const TObject *oldHashArg=0)
Replace oldArg with newArg in the table.
TObject * find(const char *name) const
Return the object with given name from the table.
void add(TObject *arg, TObject *hashArg=0)
Add given object to table.
RooAbsArg * findArg(const RooAbsArg *arg) const
RooLinkedListElem is an link element for the RooLinkedList class.
void init(TObject *arg, RooLinkedListElem *after=0)
RooLinkedListElem * _prev
RooLinkedListElem * _next
A wrapper around TIterator derivatives.
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
static Pool * _pool
shared memory pool for allocation of RooLinkedListElems
TString _name
Hash table by link pointer.
RooLinkedListImplDetails::Pool Pool
memory pool for quick allocation of RooLinkedListElems
std::vector< RooLinkedListElem * > _at
RooLinkedListIter iterator(Bool_t forward=kTRUE) const
Create an iterator for this list.
RooHashTable * _htableName
Link to last element of list.
RooLinkedListElem * createElement(TObject *obj, RooLinkedListElem *elem=0)
cout << "RooLinkedList::createElem(" << this << ") obj = " << obj << " elem = " << elem << endl ;
RooLinkedList(Int_t htsize=0)
RooHashTable * _htableLink
Hash table by name.
void Sort(Bool_t ascend=kTRUE)
RooFIter fwdIterator() const
Create a one-time-use forward iterator for this list.
void deleteElement(RooLinkedListElem *)
RooLinkedListElem * findLink(const TObject *arg) const
Find the element link containing the given object.
void Print(const char *opt) const
Print contents of list, defers to Print() function of contained objects.
TIterator * MakeIterator(Bool_t forward=kTRUE) const
Create a TIterator for this list.
static RooLinkedListElem * mergesort_impl(RooLinkedListElem *l1, const unsigned sz, RooLinkedListElem **tail=0)
length 0, 1 lists are sorted
TObject * At(Int_t index) const
Return object stored in sequential position given by index.
RooAbsArg * findArg(const RooAbsArg *) const
Return pointer to object with given name in collection.
void Delete(Option_t *o=0)
Remove all elements in collection and delete all elements NB: Collection does not own elements,...
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'.
virtual void RecursiveRemove(TObject *obj)
If one of the TObject we have a referenced to is deleted, remove the reference.
virtual void Add(TObject *arg)
RooLinkedListElem * _last
Link to first element of list.
void setHashTableSize(Int_t size)
Change the threshold for hash-table use to given size.
void Clear(Option_t *o=0)
Remove all elements from collection.
Bool_t Replace(const TObject *oldArg, const TObject *newArg)
Replace object 'oldArg' in collection with new object 'newArg'.
RooLinkedListElem * _first
virtual Bool_t Remove(TObject *arg)
Remove object from collection.
Int_t IndexOf(const char *name) const
Return position of given object in list.
virtual ~RooLinkedList()
Destructor.
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)...
Buffer base class used for serializing objects.
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
Iterator abstract base class.
The TNamed class is the base class for all named ROOT classes.
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual Int_t Compare(const TObject *obj) const
Compare abstract method.
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
void CallRecursiveRemoveIfNeeded(TObject &obj)
call RecursiveRemove for obj if gROOT is valid and obj.TestBit(kMustCleanup) is true.