/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 *    File: $Id: RooLinkedList.h,v 1.15 2007/05/11 09:11:30 verkerke Exp $
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/
#ifndef ROO_LINKED_LIST
#define ROO_LINKED_LIST

#include <map>
#include <list>

#include "TNamed.h"
#include "RooLinkedListElem.h"
#include "RooHashTable.h"
class RooLinkedListIter ;
class RooFIter ;
class TIterator ;
class RooAbsArg ;

namespace RooLinkedListImplDetails {
    class Chunk;
    class Pool;
}

class RooLinkedList : public TObject {
public:
  // Constructor
  RooLinkedList(Int_t htsize=0) ;

  // Copy constructor
  RooLinkedList(const RooLinkedList& other) ;

  virtual TObject* Clone(const char* =0) const { 
    return new RooLinkedList(*this) ;
  }

  // Assignment operator
  RooLinkedList& operator=(const RooLinkedList& other) ;

  Int_t getHashTableSize() const {
    // Return size of hash table
    return _htableName ? _htableName->size() : 0 ;
  }

  void setHashTableSize(Int_t size) ;

  // Destructor
  virtual ~RooLinkedList() ;

  Int_t GetSize() const { return _size ; }

  virtual void Add(TObject* arg) { Add(arg,1) ; }
  virtual Bool_t Remove(TObject* arg) ;
  TObject* At(Int_t index) const ;
  Bool_t Replace(const TObject* oldArg, const TObject* newArg) ;
  TIterator* MakeIterator(Bool_t dir=kTRUE) const ;
  RooLinkedListIter iterator(Bool_t dir=kTRUE) const ;
  RooFIter fwdIterator() const ; 

  void Clear(Option_t *o=0) ;
  void Delete(Option_t *o=0) ;
  TObject* find(const char* name) const ;
  RooAbsArg* findArg(const RooAbsArg*) const ;
  TObject* FindObject(const char* name) const ; 
  TObject* FindObject(const TObject* obj) const ;
  Int_t IndexOf(const char* name) const ;
  Int_t IndexOf(const TObject* arg) const ;
  TObject* First() const {
    return _first?_first->_arg:0 ;
  }

  void Print(const char* opt) const ;
  void Sort(Bool_t ascend=kTRUE) ;
  
  // const char* GetName() const { return "" ; /*_name.Data() ; */ }
  // void SetName(const char* /*name*/) { /*_name = name ; */ }
  const char* GetName() const { return _name.Data() ;  }
  void SetName(const char* name) { _name = name ;  }

   void useNptr(Bool_t flag) { _useNptr = flag ; }
   // needed for using it in THashList/THashTable

   ULong_t  Hash() const { return _name.Hash(); }
   //ULong_t  Hash() const { return TString().Hash(); }

protected:  

  RooLinkedListElem* createElement(TObject* obj, RooLinkedListElem* elem=0) ;
  void deleteElement(RooLinkedListElem*) ;


  friend class RooLinkedListIter ;
  friend class RooFIter ;

  virtual void Add(TObject* arg, Int_t refCount) ;

  RooLinkedListElem* findLink(const TObject* arg) const ;
    
  Int_t _hashThresh ;          //  Size threshold for hashing
  Int_t _size ;                //  Current size of list
  RooLinkedListElem*  _first ; //! Link to first element of list
  RooLinkedListElem*  _last ;  //! Link to last element of list
  RooHashTable*       _htableName ; //! Hash table by name 
  RooHashTable*       _htableLink ; //! Hash table by link pointer

  TString             _name ; 
  Bool_t              _useNptr ; //!

private:
  template <bool ascending>
  static RooLinkedListElem* mergesort_impl(RooLinkedListElem* l1,
	  const unsigned sz, RooLinkedListElem** tail = 0);
  /// memory pool for quick allocation of RooLinkedListElems
  typedef RooLinkedListImplDetails::Pool Pool;
  /// shared memory pool for allocation of RooLinkedListElems
  static Pool* _pool; //!

  ClassDef(RooLinkedList,3) // Doubly linked list for storage of RooAbsArg objects
};




#endif
 RooLinkedList.h:1
 RooLinkedList.h:2
 RooLinkedList.h:3
 RooLinkedList.h:4
 RooLinkedList.h:5
 RooLinkedList.h:6
 RooLinkedList.h:7
 RooLinkedList.h:8
 RooLinkedList.h:9
 RooLinkedList.h:10
 RooLinkedList.h:11
 RooLinkedList.h:12
 RooLinkedList.h:13
 RooLinkedList.h:14
 RooLinkedList.h:15
 RooLinkedList.h:16
 RooLinkedList.h:17
 RooLinkedList.h:18
 RooLinkedList.h:19
 RooLinkedList.h:20
 RooLinkedList.h:21
 RooLinkedList.h:22
 RooLinkedList.h:23
 RooLinkedList.h:24
 RooLinkedList.h:25
 RooLinkedList.h:26
 RooLinkedList.h:27
 RooLinkedList.h:28
 RooLinkedList.h:29
 RooLinkedList.h:30
 RooLinkedList.h:31
 RooLinkedList.h:32
 RooLinkedList.h:33
 RooLinkedList.h:34
 RooLinkedList.h:35
 RooLinkedList.h:36
 RooLinkedList.h:37
 RooLinkedList.h:38
 RooLinkedList.h:39
 RooLinkedList.h:40
 RooLinkedList.h:41
 RooLinkedList.h:42
 RooLinkedList.h:43
 RooLinkedList.h:44
 RooLinkedList.h:45
 RooLinkedList.h:46
 RooLinkedList.h:47
 RooLinkedList.h:48
 RooLinkedList.h:49
 RooLinkedList.h:50
 RooLinkedList.h:51
 RooLinkedList.h:52
 RooLinkedList.h:53
 RooLinkedList.h:54
 RooLinkedList.h:55
 RooLinkedList.h:56
 RooLinkedList.h:57
 RooLinkedList.h:58
 RooLinkedList.h:59
 RooLinkedList.h:60
 RooLinkedList.h:61
 RooLinkedList.h:62
 RooLinkedList.h:63
 RooLinkedList.h:64
 RooLinkedList.h:65
 RooLinkedList.h:66
 RooLinkedList.h:67
 RooLinkedList.h:68
 RooLinkedList.h:69
 RooLinkedList.h:70
 RooLinkedList.h:71
 RooLinkedList.h:72
 RooLinkedList.h:73
 RooLinkedList.h:74
 RooLinkedList.h:75
 RooLinkedList.h:76
 RooLinkedList.h:77
 RooLinkedList.h:78
 RooLinkedList.h:79
 RooLinkedList.h:80
 RooLinkedList.h:81
 RooLinkedList.h:82
 RooLinkedList.h:83
 RooLinkedList.h:84
 RooLinkedList.h:85
 RooLinkedList.h:86
 RooLinkedList.h:87
 RooLinkedList.h:88
 RooLinkedList.h:89
 RooLinkedList.h:90
 RooLinkedList.h:91
 RooLinkedList.h:92
 RooLinkedList.h:93
 RooLinkedList.h:94
 RooLinkedList.h:95
 RooLinkedList.h:96
 RooLinkedList.h:97
 RooLinkedList.h:98
 RooLinkedList.h:99
 RooLinkedList.h:100
 RooLinkedList.h:101
 RooLinkedList.h:102
 RooLinkedList.h:103
 RooLinkedList.h:104
 RooLinkedList.h:105
 RooLinkedList.h:106
 RooLinkedList.h:107
 RooLinkedList.h:108
 RooLinkedList.h:109
 RooLinkedList.h:110
 RooLinkedList.h:111
 RooLinkedList.h:112
 RooLinkedList.h:113
 RooLinkedList.h:114
 RooLinkedList.h:115
 RooLinkedList.h:116
 RooLinkedList.h:117
 RooLinkedList.h:118
 RooLinkedList.h:119
 RooLinkedList.h:120
 RooLinkedList.h:121
 RooLinkedList.h:122
 RooLinkedList.h:123
 RooLinkedList.h:124
 RooLinkedList.h:125
 RooLinkedList.h:126
 RooLinkedList.h:127
 RooLinkedList.h:128
 RooLinkedList.h:129
 RooLinkedList.h:130
 RooLinkedList.h:131
 RooLinkedList.h:132
 RooLinkedList.h:133
 RooLinkedList.h:134