55 _sz(sz), _free(capacity()),
60 for (
Int_t i = 0; i < _free; ++i)
61 _chunk[i]._next = (i + 1 < _free) ? &_chunk[i + 1] : 0;
64 ~Chunk() {
delete[] _chunk; }
66 Int_t capacity()
const
71 Int_t size()
const {
return capacity() -
free(); }
73 int szclass()
const {
return _sz; }
75 bool full()
const {
return !
free(); }
77 bool empty()
const {
return capacity() ==
free(); }
79 const void* chunkaddr()
const {
return _chunk; }
82 {
return _chunk <= el && el < &_chunk[capacity()]; }
86 if (!_freelist)
return 0;
88 _freelist = retVal->
_next;
97 el->
_next = _freelist;
121 typedef RooLinkedListImplDetails::Chunk Chunk;
122 typedef std::list<Chunk*> ChunkList;
123 typedef std::map<const void*, Chunk*> AddrMap;
130 inline void acquire() { ++_refCount; }
132 inline bool release() {
return 0 == --_refCount; }
140 UInt_t _szmap[(maxsz - minsz) / szincr];
147 Int_t nextChunkSz()
const;
150 Pool::Pool() : _cursz(minsz), _refCount(0)
152 std::fill(_szmap, _szmap + ((maxsz - minsz) / szincr), 0);
158 for (AddrMap::iterator it = _addrmap.begin(); _addrmap.end() != it; ++it)
165 if (_freelist.empty()) {
167 const Int_t sz = nextChunkSz();
168 Chunk *
c =
new Chunk(sz);
169 _addrmap[
c->chunkaddr()] =
c;
170 _freelist.push_back(
c);
174 Chunk*
c = _freelist.front();
177 if (
c->full()) _freelist.pop_front();
184 AddrMap::iterator ci = _addrmap.end();
185 if (!_addrmap.empty()) {
186 ci = _addrmap.lower_bound(el);
187 if (ci == _addrmap.end()) {
189 ci = (++_addrmap.rbegin()).base();
193 if (_addrmap.begin() != ci && ci->first != el) --ci;
198 if (_addrmap.empty() || !ci->second->contains(el)) {
203 Chunk *
c = ci->second;
204 const bool moveToFreelist =
c->full();
205 c->push_free_elem(el);
208 ChunkList::iterator it = std::find( _freelist.begin(), _freelist.end(),
c);
209 if (_freelist.end() != it) _freelist.erase(it);
210 _addrmap.erase(ci->first);
211 updateCurSz(
c->szclass(), -1);
213 }
else if (moveToFreelist) {
214 _freelist.push_back(
c);
220 _szmap[(sz - minsz) / szincr] += incr;
222 for (
int i = (maxsz - minsz) / szincr; i--; ) {
224 _cursz += i * szincr;
230 Int_t Pool::nextChunkSz()
const
234 if (_addrmap.empty()) {
242 if (1 != _addrmap.size()) {
252 if (sz > maxsz) sz = maxsz;
253 if (sz < minsz) sz = minsz;
263 _hashThresh(htsize), _size(0), _first(0), _last(0), _htableName(0), _htableLink(0), _useNptr(
kTRUE)
273 TObject(other), _hashThresh(other._hashThresh), _size(0), _first(0), _last(0), _htableName(0), _htableLink(0),
275 _useNptr(other._useNptr)
282 Add(elem->_arg, elem->_refCount) ;
292 ret->
init(obj, elem);
301 _pool->push_free_elem(elem);
311 if (&other==
this)
return *this ;
330 coutE(
InputArguments) <<
"RooLinkedList::setHashTable() ERROR size must be positive" << endl ;
381 if (
_pool->release()) {
398 if (ptr->
_arg == arg) {
458 if (!elem)
return kFALSE ;
473 auto at_elem_it = std::find(
_at.begin(),
_at.end(), elem);
474 _at.erase(at_elem_it);
498 if (index<0 || index>=
_size)
return 0 ;
500 return _at[index]->_arg;
519 if (!elem)
return kFALSE ;
550 return elem ? elem->
_arg : 0 ;
704 if (ptr->
_arg==arg)
return idx ;
735 cout << elem->
_arg <<
" : " ;
747 auto iterImpl = std::make_unique<RooLinkedListIterImpl>(
this,
forward);
757 auto iterImpl = std::make_unique<RooLinkedListIterImpl>(
this,
forward);
766 auto iterImpl = std::make_unique<RooFIterForLinkedList>(
this);
767 return RooFIter(std::move(iterImpl));
779 for (
auto it =
_at.begin(); it !=
_at.end(); ++it, elem = elem->
_next) {
787template <
bool ascending>
793 if (tail) *tail = l1;
798#if !defined(_WIN32) && !defined(R__SOLARIS_CC50)
806 for (
int i = 0; l1; l1 = l1->
_next, ++i) arr[i] = l1;
814 const bool inOrder = ascending ?
816 (arr[j]->_arg->Compare(tmp->
_arg) <= 0);
823 }
while (
int(sz) != i);
827 for (
int i = 0; i < int(sz - 1); ++i) {
828 arr[i]->
_next = arr[i + 1];
829 arr[i + 1]->
_prev = arr[i];
831 if (tail) *tail = arr[sz - 1];
839 if (!end->_next)
break;
845 if (l1->
_next) l1 = mergesort_impl<ascending>(l1, sz / 2);
846 if (l2->
_next) l2 = mergesort_impl<ascending>(l2, sz - sz / 2);
879 if (t) t->
_next = l2;
883 for (l1 = t; l1; l1 = l1->
_next) t = l1;
903void RooLinkedList::Streamer(
TBuffer &R__b)
909 TObject::Streamer(R__b);
920 if (
v > 1 &&
v < 4) {
926 TObject::Streamer(R__b);
Binding & operator=(OUT(*fun)(void))
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
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.
void forward(const LAYERDATA &prevLayerData, LAYERDATA &currLayerData)
apply the weights (and functions) in forward direction of the DNN