49namespace RooLinkedListImplDetails {
55 _sz(sz), _free(capacity()),
56 _chunk(new RooLinkedListElem[_free]), _freelist(_chunk)
60 for (
Int_t i = 0; i < _free; ++i)
61 _chunk[i]._next = (i + 1 < _free) ? &_chunk[i + 1] :
nullptr;
64 Chunk(
const Chunk&) =
delete;
68 ~Chunk() {
delete[] _chunk; }
70 Int_t capacity()
const
71 {
return (1ULL << _sz) /
sizeof(RooLinkedListElem); }
77 int szclass()
const {
return _sz; }
79 bool full()
const {
return !
free(); }
81 bool empty()
const {
return capacity() ==
free(); }
83 const void* chunkaddr()
const {
return _chunk; }
85 bool contains(RooLinkedListElem* el)
const
86 {
return _chunk <= el && el < &_chunk[capacity()]; }
88 RooLinkedListElem* pop_free_elem()
90 if (!_freelist)
return nullptr;
91 RooLinkedListElem* retVal = _freelist;
92 _freelist = retVal->
_next;
99 void push_free_elem(RooLinkedListElem* el)
101 el->
_next = _freelist;
108 RooLinkedListElem* _chunk;
109 RooLinkedListElem* _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; }
133 RooLinkedListElem* pop_free_elem();
135 void push_free_elem(RooLinkedListElem* el);
139 UInt_t _szmap[(maxsz - minsz) / szincr];
140 Int_t _cursz = minsz;
146 Int_t nextChunkSz()
const;
151 std::fill(_szmap, _szmap + ((maxsz - minsz) / szincr), 0);
157 for (AddrMap::iterator it = _addrmap.begin(); _addrmap.end() != it; ++it)
162 RooLinkedListElem* Pool::pop_free_elem()
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();
174 RooLinkedListElem* retVal =
c->pop_free_elem();
176 if (
c->full()) _freelist.pop_front();
180 void Pool::push_free_elem(RooLinkedListElem* el)
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;
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" << std::endl;
347 _htableName->insert({elem->_arg->GetName(), elem->_arg});
368 if (
_pool->release()) {
387 if (ptr->
_arg == arg) {
435 _last->_refCount = refCount ;
447 if (!elem)
return false ;
462 auto at_elem_it = std::find(
_at.begin(),
_at.end(), elem);
463 _at.erase(at_elem_it);
487 if (index<0 || index>=
_size)
return nullptr ;
489 return _at[index]->_arg;
508 if (!elem)
return false ;
540 return elem ? elem->
_arg : nullptr ;
634 if (!nptr)
return nullptr;
672 if ((
static_cast<RooAbsArg*
>(ptr->
_arg))->namePtr() == nptr) {
689 if (ptr->
_arg==arg)
return idx ;
720 std::cout << elem->
_arg <<
" : " ;
732 auto iterImpl = std::make_unique<RooLinkedListIterImpl>(
this, forward);
742 auto iterImpl = std::make_unique<RooLinkedListIterImpl>(
this, forward);
751 auto iterImpl = std::make_unique<RooFIterForLinkedList>(
this);
752 return RooFIter(std::move(iterImpl));
760 return {
this,
nullptr,
true};
764 return {
this,
false};
768 return {
this,
nullptr,
false};
780 for (
auto it =
_at.begin(); it !=
_at.end(); ++it, elem = elem->
_next) {
788template <
bool ascending>
794 if (tail) *tail = l1;
799 std::vector<RooLinkedListElem *> arr(sz,
nullptr);
800 for (
int i = 0; l1; l1 = l1->
_next, ++i) arr[i] = l1;
808 const bool inOrder = ascending ?
810 (arr[j]->_arg->Compare(tmp->
_arg) <= 0);
817 }
while (
int(sz) != i);
820 arr[0]->_prev = arr[sz - 1]->_next =
nullptr;
821 for (
int i = 0; i <
int(sz - 1); ++i) {
822 arr[i]->_next = arr[i + 1];
823 arr[i + 1]->_prev = arr[i];
825 if (tail) *tail = arr[sz - 1];
833 if (!
end->_next)
break;
873 if (t) t->
_next = l2;
877 for (l1 = t; l1; l1 = l1->
_next) t = l1;
914 if (
v > 1 &&
v < 4) {
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
short Version_t
Class version identifier (short).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
const char Option_t
Option string (const char).
Binding & operator=(OUT(*fun)(void))
Common abstract base class for objects that represent a value and a "shape" in RooFit.
const TNamed * namePtr() const
De-duplicated pointer to this object's name.
Abstract base class for binned and unbinned datasets.
const TNamed * namePtr() const
De-duplicated pointer to this object's name.
A one-time forward iterator working on RooLinkedList or RooAbsCollection.
Link element for the RooLinkedList class.
TObject * _arg
Link to contents.
Int_t _refCount
! Reference count
RooLinkedListElem * _prev
Link to previous element in list.
RooLinkedListElem * _next
Link to next element in list.
A wrapper around TIterator derivatives.
RooLinkedListIterImpl rend() const
TObject * At(int index) const
Return object stored in sequential position given by index.
RooLinkedListIter iterator(bool forward=true) const
Create an iterator for this list.
static Pool * _pool
shared memory pool for allocation of RooLinkedListElems
~RooLinkedList() override
Destructor.
RooLinkedListIterImpl end() const
RooLinkedListImplDetails::Pool Pool
memory pool for quick allocation of RooLinkedListElems
std::vector< RooLinkedListElem * > _at
! index list for quick index through At
std::unique_ptr< HashTableByName > _htableName
! Hash table by name
void RecursiveRemove(TObject *obj) override
If one of the TObject we have a referenced to is deleted, remove the reference.
bool Replace(const TObject *oldArg, const TObject *newArg)
Replace object 'oldArg' in collection with new object 'newArg'.
RooLinkedList(Int_t htsize=0)
void Print(const char *opt) const override
Print contents of list, defers to Print() function of contained objects.
std::unique_ptr< HashTableByLink > _htableLink
! Hash table by link pointer
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 Streamer(TBuffer &) override
Custom streaming handling schema evolution w.r.t past implementations.
RooLinkedListIterImpl rbegin() const
TClass * IsA() const override
Int_t _hashThresh
Size threshold for hashing.
RooLinkedListElem * createElement(TObject *obj, RooLinkedListElem *elem=nullptr)
std::cout << "RooLinkedList::createElem(" << this << ") obj = " << obj << " elem = " << elem << std::...
RooAbsArg * findArg(const RooAbsArg *) const
Return pointer to object with given name in collection.
void Delete(Option_t *o=nullptr) override
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 Add(TObject *arg)
Int_t _size
Current size of list.
friend class RooLinkedListIterImpl
RooLinkedListIterImpl begin() const
RooLinkedListElem * _last
! Link to last element of list
void setHashTableSize(Int_t size)
Change the threshold for hash-table use to given size.
TObject * FindObject(const char *name) const override
Return pointer to object with given name.
RooLinkedListElem * _first
! Link to first element of list
TIterator * MakeIterator(bool forward=true) const
Create a TIterator for this list.
void Clear(Option_t *o=nullptr) override
Remove all elements from collection.
static RooLinkedListElem * mergesort_impl(RooLinkedListElem *l1, const unsigned sz, RooLinkedListElem **tail=nullptr)
length 0, 1 lists are sorted
void Sort(bool ascend=true)
Int_t IndexOf(const char *name) const
Return position of given object in list.
virtual bool Remove(TObject *arg)
Remove object from collection.
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)...
@ kRenamedArg
TNamed flag to indicate that some RooAbsArg has been renamed (flag set in new name).
Buffer base class used for serializing objects.
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=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.
const char * GetName() const override
Returns name of object.
Bool_t TestBit(UInt_t f) const
virtual const char * GetName() const
Returns name of object.
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
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.
TObject()
TObject constructor.
void CallRecursiveRemoveIfNeeded(TObject &obj)
call RecursiveRemove for obj if gROOT is valid and obj.TestBit(kMustCleanup) is true.