49 ClassImp(TEntryListBlock);
54 TEntryListBlock::TEntryListBlock()
62 fLastIndexReturned = -1;
63 fLastIndexQueried = -1;
69 TEntryListBlock::TEntryListBlock(
const TEntryListBlock &eblock) : TObject(eblock)
73 fIndices =
new UShort_t[fN];
74 for (Int_t i=0; i<fN; i++)
75 fIndices[i] = eblock.fIndices[i];
79 fNPassed = eblock.fNPassed;
81 fPassing = eblock.fPassing;
82 fCurrent = eblock.fCurrent;
83 fLastIndexReturned = -1;
84 fLastIndexQueried = -1;
90 TEntryListBlock::~TEntryListBlock()
99 TEntryListBlock &TEntryListBlock::operator=(
const TEntryListBlock &eblock)
101 if (
this != &eblock) {
106 if (eblock.fIndices){
107 fIndices =
new UShort_t[fN];
108 for (Int_t i=0; i<fN; i++)
109 fIndices[i] = eblock.fIndices[i];
113 fNPassed = eblock.fNPassed;
114 fType = eblock.fType;
115 fPassing = eblock.fPassing;
116 fCurrent = eblock.fCurrent;
117 fLastIndexReturned = -1;
118 fLastIndexQueried = -1;
128 Bool_t TEntryListBlock::Enter(Int_t entry)
130 if (entry > kBlockSize*16) {
131 Error(
"Enter",
"illegal entry value!");
135 fIndices =
new UShort_t[kBlockSize] ;
136 for (Int_t i=0; i<kBlockSize; i++)
143 Int_t j = entry & 15;
144 if ((fIndices[i] & (1<<j))==0){
154 UShort_t *bits =
new UShort_t[kBlockSize];
166 Bool_t TEntryListBlock::Remove(Int_t entry)
168 if (entry > kBlockSize*16) {
169 Error(
"Remove",
"Illegal entry value!\n");
174 Int_t j = entry & 15;
175 if ((fIndices[i] & (1<<j))!=0){
176 fIndices[i] &= (0xFFFF^(1<<j));
185 UShort_t *bits =
new UShort_t[kBlockSize];
187 return Remove(entry);
194 Int_t TEntryListBlock::Contains(Int_t entry)
196 if (entry > kBlockSize*16) {
197 Error(
"Contains",
"Illegal entry value!\n");
200 if (!fIndices && fPassing)
202 if (fType==0 && fIndices){
205 Int_t j = entry & 15;
206 Bool_t result = (fIndices[i] & (1<<j))!=0;
210 if (entry < fCurrent) fCurrent = 0;
211 if (fPassing && fIndices){
212 for (Int_t i = fCurrent; i<fNPassed; i++){
213 if (fIndices[i]==entry){
219 if (!fIndices || fNPassed==0){
223 if (entry > fIndices[fNPassed-1])
225 for (Int_t i= fCurrent; i<fNPassed; i++){
226 if (fIndices[i]==entry){
230 if (fIndices[i]>entry){
243 Int_t TEntryListBlock::Merge(TEntryListBlock *block)
246 if (block->GetNPassed() == 0)
return GetNPassed();
247 if (GetNPassed() == 0){
250 fIndices =
new UShort_t[fN];
252 fIndices[i] = block->fIndices[i];
253 fNPassed = block->fNPassed;
254 fType = block->fType;
255 fPassing = block->fPassing;
256 fCurrent = block->fCurrent;
257 fLastIndexReturned = -1;
258 fLastIndexQueried = -1;
263 if (block->fType == 0){
264 for (i=0; i<kBlockSize*16; i++){
265 if (block->Contains(i))
269 if (block->fPassing){
271 for (i=0; i<block->fNPassed; i++){
272 Enter(block->fIndices[i]);
276 if (block->fNPassed==0){
277 for (i=0; i<kBlockSize*16; i++){
281 for (j=0; j<block->fIndices[0]; j++)
283 for (i=0; i<block->fNPassed-1; i++){
284 for (j=block->fIndices[i]+1; j<block->fIndices[i+1]; j++){
288 for (j=block->fIndices[block->fNPassed-1]+1; j<kBlockSize*16; j++)
294 if (GetNPassed() + block->GetNPassed() > kBlockSize){
296 UShort_t *bits =
new UShort_t[kBlockSize];
301 if (block->fType==1){
304 Int_t en = block->fNPassed;
305 Int_t newsize = fNPassed + en;
306 UShort_t *newlist =
new UShort_t[newsize];
307 UShort_t *elst = block->fIndices;
310 for (i=0; i<fNPassed; i++) {
311 while (elpos < en && fIndices[i] > elst[elpos]) {
312 newlist[newpos] = elst[elpos];
316 if (fIndices[i] == elst[elpos]) elpos++;
317 newlist[newpos] = fIndices[i];
321 newlist[newpos] = elst[elpos];
332 Int_t en = block->fNPassed;
333 Int_t newsize = fNPassed + en;
334 UShort_t *newlist =
new UShort_t[newsize];
335 Int_t newpos, current;
336 newpos = current = 0;
337 for (i=0; i<kBlockSize*16; i++){
338 if (!block->Contains(i))
continue;
339 while(current < fNPassed && fIndices[current]<i){
340 newlist[newpos] = fIndices[current];
344 if (fIndices[current]==i) current++;
348 while(current<fNPassed){
349 newlist[newpos] = fIndices[current];
360 fLastIndexQueried = -1;
361 fLastIndexReturned = -1;
370 Int_t TEntryListBlock::GetNPassed()
375 return kBlockSize*16-fNPassed;
382 Int_t TEntryListBlock::GetEntry(Int_t entry)
384 if (entry > kBlockSize*16)
return -1;
385 if (entry > GetNPassed())
return -1;
386 if (entry == fLastIndexQueried+1)
return Next();
388 Int_t i=0; Int_t j=0; Int_t entries_found=0;
390 if ((fIndices[i] & (1<<j))!=0)
392 while (entries_found<entry+1){
393 if (j==15){i++; j=0;}
395 if ((fIndices[i] & (1<<j))!=0)
398 fLastIndexQueried = entry;
399 fLastIndexReturned = i*16+j;
400 return fLastIndexReturned;
404 fLastIndexQueried = entry;
405 fLastIndexReturned = fIndices[entry];
406 return fIndices[entry];
408 fLastIndexQueried = entry;
409 if (!fIndices || fNPassed==0){
411 fLastIndexReturned = entry;
412 return fLastIndexReturned;
414 for (i=0; i<fIndices[0]; i++){
416 if (entries_found==entry+1){
417 fLastIndexReturned = i;
418 return fLastIndexReturned;
421 for (i=0; i<fNPassed-1; i++){
422 for (j=fIndices[i]+1; j<fIndices[i+1]; j++){
424 if (entries_found==entry+1){
425 fLastIndexReturned = j;
426 return fLastIndexReturned;
430 for (j=fIndices[fNPassed-1]+1; j<kBlockSize*16; j++){
432 if (entries_found==entry+1){
433 fLastIndexReturned = j;
434 return fLastIndexReturned;
447 Int_t TEntryListBlock::Next()
449 if (fLastIndexQueried==GetNPassed()-1){
450 fLastIndexQueried=-1;
451 fLastIndexReturned = -1;
459 fLastIndexReturned++;
460 i = fLastIndexReturned>>4;
461 j = fLastIndexReturned & 15;
462 Bool_t result=(fIndices[i] & (1<<j))!=0;
464 if (j==15) {j=0; i++;}
466 result = (fIndices[i] & (1<<j))!=0;
468 fLastIndexReturned = i*16+j;
470 return fLastIndexReturned;
476 fLastIndexReturned = fIndices[fLastIndexQueried];
477 return fIndices[fLastIndexQueried];
479 fLastIndexReturned++;
480 while (!Contains(fLastIndexReturned)){
481 fLastIndexReturned++;
483 return fLastIndexReturned;
493 void TEntryListBlock::Print(
const Option_t *option)
const
495 TString opt = option;
497 if (opt.Contains(
"A")) PrintWithShift(0);
504 void TEntryListBlock::PrintWithShift(Int_t shift)
const
510 for (i=0; i<kBlockSize*16; i++){
513 result = (fIndices[ibite] & (1<<ibit))!=0;
515 printf(
"%d\n", i+shift);
519 for (i=0; i<fNPassed; i++){
520 printf(
"%d\n", fIndices[i]+shift);
524 for (i=0; i<kBlockSize*16; i++)
525 printf(
"%d\n", i+shift);
528 for (i=0; i<fIndices[0]; i++){
529 printf(
"%d\n", i+shift);
531 for (i=0; i<fNPassed-1; i++){
532 for (Int_t j=fIndices[i]+1; j<fIndices[i+1]; j++){
533 printf(
"%d\n", j+shift);
536 for (Int_t j=fIndices[fNPassed-1]+1; j<kBlockSize*16; j++){
537 printf(
"%d\n", j+shift);
547 void TEntryListBlock::OptimizeStorage()
549 if (fType!=0)
return;
550 if (fNPassed > kBlockSize*15)
552 if (fNPassed<kBlockSize || !fPassing){
554 UShort_t *indexnew =
new UShort_t[fNPassed];
555 Transform(0, indexnew);
564 void TEntryListBlock::Transform(Bool_t dir, UShort_t *indexnew)
570 for (i=0; i<kBlockSize*16; i++){
573 Bool_t result = (fIndices[ibite] & (1<<ibit))!=0;
574 if (result && fPassing){
579 else if (!result && !fPassing){
590 fNPassed = kBlockSize*16-fNPassed;
596 for (i=0; i<kBlockSize; i++)
598 for (i=0; i<fNPassed; i++){
599 ibite = fIndices[i]>>4;
600 ibit = fIndices[i] & 15;
601 indexnew[ibite] |= 1<<ibit;
604 for (i=0; i<kBlockSize; i++)
606 for (i=0; i<fNPassed; i++){
607 ibite = fIndices[i]>>4;
608 ibit = fIndices[i] & 15;
609 indexnew[ibite] ^= 1<<ibit;
611 fNPassed = kBlockSize*16-fNPassed;