ROOT logo
#ifndef ALIITSINTMAP_H
#define ALIITSINTMAP_H

//////////////////////////////////////////////////////////////////////
// Author: Henrik Tydesjo                                           //
// This class implements the use of a map of integers.              //
//                                                                  //
//////////////////////////////////////////////////////////////////////  

#include <Rtypes.h>

class AliITSIntMapNode;

class AliITSIntMap {

 public:
  AliITSIntMap();
  AliITSIntMap(AliITSIntMapNode* root, UInt_t nrEntries);
  AliITSIntMap(const AliITSIntMap& imap);
  virtual ~AliITSIntMap();
  AliITSIntMap& operator=(const AliITSIntMap& imap);

  void               Clear();
  AliITSIntMap*      Clone() const;
  Bool_t             Insert(Int_t key, Int_t val);
  Bool_t             Remove(Int_t key);
  Bool_t             Pop(Int_t& key, Int_t& val);
  AliITSIntMapNode*  Find(Int_t key) const;
  Int_t              GetVal(Int_t key) const;

  UInt_t             GetNrEntries() const {return fNrEntries;}
  Int_t              GetKeyIndex(UInt_t index);
  Int_t              GetValIndex(UInt_t index);

  void               PrintEntries() const;
  void               Balance();
  void               PrepareSerialize() {InitFastAccessSerialize();}
  void               PrepareSerializeOrdered() {InitFastAccess();}
  UInt_t             GetTreeHeight() const;

 private:
  UInt_t             fNrEntries;          // nr of entries in map
  AliITSIntMapNode*  fRoot;               // link to first node of tree
  Bool_t             fFastAccess;         // is fast access array initialized (key ordered)?
  Bool_t             fFastAccessSerialize;// is fast access array initialized (tree ordered)?
  AliITSIntMapNode** fFastAccessArray;    // array of pointers to nodes
  UInt_t             fDummyIndex;         // dummy index used when traversing tree

  void               ClearNode(AliITSIntMapNode* &node); // delete this node and all below
  AliITSIntMapNode*  CloneNode(AliITSIntMapNode* node) const;
  void               InsertNode(Int_t key, Int_t val, AliITSIntMapNode* &node, UInt_t height);
  void               RemoveNode(Int_t key, AliITSIntMapNode* &node);
  AliITSIntMapNode*  FindNode(Int_t key, AliITSIntMapNode* node, UInt_t height) const;
  AliITSIntMapNode*  FindNodeIndex(UInt_t index, AliITSIntMapNode* node) const;
  AliITSIntMapNode*  FindMinNode(AliITSIntMapNode* node) const;
  AliITSIntMapNode*  FindMaxNode(AliITSIntMapNode* node) const;
  void               PrintNode(AliITSIntMapNode* node) const;
  UInt_t             GetTreeHeightNode(AliITSIntMapNode* node) const;

  AliITSIntMapNode*  BalanceNode(Int_t lowInd, Int_t highInd);
  void               ClearFastAccess();
  void               InitFastAccess();
  void               InitFastAccessNode(AliITSIntMapNode* node);
  void               InitFastAccessSerialize();
  void               InitFastAccessSerializeNode(AliITSIntMapNode* node);

};

#endif
 AliITSIntMap.h:1
 AliITSIntMap.h:2
 AliITSIntMap.h:3
 AliITSIntMap.h:4
 AliITSIntMap.h:5
 AliITSIntMap.h:6
 AliITSIntMap.h:7
 AliITSIntMap.h:8
 AliITSIntMap.h:9
 AliITSIntMap.h:10
 AliITSIntMap.h:11
 AliITSIntMap.h:12
 AliITSIntMap.h:13
 AliITSIntMap.h:14
 AliITSIntMap.h:15
 AliITSIntMap.h:16
 AliITSIntMap.h:17
 AliITSIntMap.h:18
 AliITSIntMap.h:19
 AliITSIntMap.h:20
 AliITSIntMap.h:21
 AliITSIntMap.h:22
 AliITSIntMap.h:23
 AliITSIntMap.h:24
 AliITSIntMap.h:25
 AliITSIntMap.h:26
 AliITSIntMap.h:27
 AliITSIntMap.h:28
 AliITSIntMap.h:29
 AliITSIntMap.h:30
 AliITSIntMap.h:31
 AliITSIntMap.h:32
 AliITSIntMap.h:33
 AliITSIntMap.h:34
 AliITSIntMap.h:35
 AliITSIntMap.h:36
 AliITSIntMap.h:37
 AliITSIntMap.h:38
 AliITSIntMap.h:39
 AliITSIntMap.h:40
 AliITSIntMap.h:41
 AliITSIntMap.h:42
 AliITSIntMap.h:43
 AliITSIntMap.h:44
 AliITSIntMap.h:45
 AliITSIntMap.h:46
 AliITSIntMap.h:47
 AliITSIntMap.h:48
 AliITSIntMap.h:49
 AliITSIntMap.h:50
 AliITSIntMap.h:51
 AliITSIntMap.h:52
 AliITSIntMap.h:53
 AliITSIntMap.h:54
 AliITSIntMap.h:55
 AliITSIntMap.h:56
 AliITSIntMap.h:57
 AliITSIntMap.h:58
 AliITSIntMap.h:59
 AliITSIntMap.h:60
 AliITSIntMap.h:61
 AliITSIntMap.h:62
 AliITSIntMap.h:63
 AliITSIntMap.h:64
 AliITSIntMap.h:65
 AliITSIntMap.h:66
 AliITSIntMap.h:67
 AliITSIntMap.h:68
 AliITSIntMap.h:69