Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Got rid of several warnings due to implicit type conversions.

  • Loading branch information...
commit d7e2427a66685470d5335ba3011ce3917afb35e8 1 parent f29161a
authored January 05, 2012
268  headers/ewah.h
@@ -20,7 +20,7 @@ template <class uword>
20 20
 inline string toBinaryString(const uword w) {
21 21
  stringstream s;
22 22
  for(uint k = 0; k <sizeof(uword)*8;++k) {
23  
-        if(w & (1<<k)) s <<"1"; else s << "0";
  23
+        if(w & (static_cast<uword>(1)<<k)) s <<"1"; else s << "0";
24 24
  }
25 25
  string ans;
26 26
  s >> ans;
@@ -81,7 +81,7 @@ class RunningLengthWord {
81 81
      * followed by how many literal words?
82 82
      */
83 83
     uword getNumberOfLiteralWords() const {
84  
-        return mydata >> (1+runninglengthbits);
  84
+        return static_cast<uword>(mydata >> (1+runninglengthbits));
85 85
     }
86 86
 
87 87
     /**
@@ -105,7 +105,7 @@ class RunningLengthWord {
105 105
      */
106 106
     void setRunningBit(bool b) {
107 107
         if(b) mydata |= static_cast<uword>(1);
108  
-        else mydata &= ~static_cast<uword>(1);
  108
+        else mydata &= static_cast<uword>(~1);
109 109
     }
110 110
     
111 111
     
@@ -136,23 +136,23 @@ class RunningLengthWord {
136 136
     
137 137
     void setRunningLength(uword l) {
138 138
         mydata |= shiftedlargestrunninglengthcount;
139  
-        mydata &= ((static_cast<uword>(l)) << 1) | notshiftedlargestrunninglengthcount;
  139
+        mydata &= static_cast<uword>(l  << 1) | notshiftedlargestrunninglengthcount;
140 140
     }
141 141
     
142 142
     // static call for people who hate objects
143 143
     static inline void setRunningLength(uword & data, uword l) {
144 144
         data |= shiftedlargestrunninglengthcount;
145  
-        data &= ((static_cast<uword>(l)) << 1) | notshiftedlargestrunninglengthcount;
  145
+        data &= static_cast<uword>(l<<1) | notshiftedlargestrunninglengthcount;
146 146
     }
147 147
 
148 148
     void setNumberOfLiteralWords(uword l) {
149 149
         mydata |= notrunninglengthplusrunningbit;
150  
-        mydata &= ((static_cast<uword>(l)) << (runninglengthbits +1) ) |runninglengthplusrunningbit;
  150
+        mydata &= static_cast<uword>(l << (runninglengthbits +1) ) |runninglengthplusrunningbit;
151 151
     }
152 152
     // static call for people who hate objects
153 153
     static inline void setNumberOfLiteralWords(uword & data, uword l) {
154 154
         data |= notrunninglengthplusrunningbit;
155  
-        data &= ((static_cast<uword>(l)) << (runninglengthbits +1) ) |runninglengthplusrunningbit;
  155
+        data &= static_cast<uword>(l << (runninglengthbits +1) ) |runninglengthplusrunningbit;
156 156
     }
157 157
     static const uint runninglengthbits = sizeof(uword)*4;//16;
158 158
     static const uint literalbits = sizeof(uword)*8 - 1 - runninglengthbits;
@@ -205,6 +205,9 @@ class ConstRunningLengthWord {
205 205
         return static_cast<uword>(mydata >> (1+RunningLengthWord<uword>::runninglengthbits));
206 206
     }
207 207
 
  208
+    /**
  209
+     * Total of getRunningLength() and getNumberOfLiteralWords() 
  210
+     */
208 211
     uword size() const {
209 212
         return getRunningLength() + getNumberOfLiteralWords();
210 213
     }
@@ -268,6 +271,10 @@ class BufferedRunningLengthWord {
268 271
         return NumberOfLiteralWords;
269 272
     }
270 273
 
  274
+
  275
+    /**
  276
+     * Total of getRunningLength() and getNumberOfLiteralWords() 
  277
+     */
271 278
     uword size() const {
272 279
         return static_cast<uword>(RunningLength + NumberOfLiteralWords);
273 280
     }
@@ -375,7 +382,7 @@ class EWAHBoolArray {
375 382
 
376 383
     /**
377 384
      * set the ith bit to true (starting at zero).
378  
-     * Auto-expands the bitmap.
  385
+     * Auto-expands the bitmap. It has constant running time complexity.
379 386
      * Note that you must set the bits in increasing order:
380 387
      * set(1), set(2) is ok; set(2), set(1) is not ok.
381 388
      */
@@ -383,7 +390,7 @@ class EWAHBoolArray {
383 390
 
384 391
     /**
385 392
     * Make sure the two bitmaps have the same size (padding with zeroes
386  
-    * if necessary)
  393
+    * if necessary). It has constant running time complexity.
387 394
     */
388 395
     void makeSameSize(EWAHBoolArray & a) {
389 396
         if(a.sizeinbits<sizeinbits)
@@ -399,10 +406,12 @@ class EWAHBoolArray {
399 406
     
400 407
     /*
401 408
     * Returns an iterator that can be used to access the position of the
402  
-    * set bits
  409
+    * set bits. The running time complexity of a full scan is proportional to the number
  410
+    * of set bits: be aware that if you have long strings of 1s, this can be
  411
+    * very inefficient.
403 412
     */
404 413
     const_iterator begin() const {
405  
-    	return EWAHBoolArraySetBitForwardIterator<uword>(buffer);
  414
+	  return EWAHBoolArraySetBitForwardIterator<uword>(buffer);
406 415
     }
407 416
     
408 417
     
@@ -411,7 +420,7 @@ class EWAHBoolArray {
411 420
     * for constructions such as for(EWAHBoolArray<uword>::iterator i = b.begin(); i!=b.end(); ++i) {}
412 421
     */
413 422
     const_iterator end() const {
414  
-    	return EWAHBoolArraySetBitForwardIterator<uword>(buffer,buffer.size());
  423
+	   return EWAHBoolArraySetBitForwardIterator<uword>(buffer,buffer.size());
415 424
     }
416 425
 
417 426
     /*
@@ -424,32 +433,40 @@ class EWAHBoolArray {
424 433
     /*
425 434
     * compute the logical and with another compressed bitmap
426 435
     * answer goes into container
427  
-    */
  436
+    * Running time complexity is proportional to the sum of the compressed
  437
+    * bitmap sizes.
  438
+     */
428 439
     void rawlogicaland( EWAHBoolArray &a, EWAHBoolArray &container) ;
429 440
 
430 441
     /*
431 442
     * compute the logical and with another compressed bitmap
432 443
     * answer goes into container
433  
-    */
  444
+    * Running time complexity is proportional to the sum of the compressed
  445
+    * bitmap sizes.
  446
+     */
434 447
     void rawlogicalor( EWAHBoolArray &a, EWAHBoolArray &container) ;
435 448
 
436 449
 
437 450
     /*
438 451
     * compute the logical and with another compressed bitmap
439 452
     * answer goes into container
440  
-    * (alias for rawlogicaland)
  453
+    * Running time complexity is proportional to the sum of the compressed
  454
+    * bitmap sizes.
  455
+     * (alias for rawlogicaland)
441 456
     */
442 457
     void logicaland( EWAHBoolArray &a, EWAHBoolArray &container) {
443  
-    	rawlogicaland(a,container);
  458
+       rawlogicaland(a,container);
444 459
     }
445 460
 
446 461
     /*
447 462
     * compute the logical and with another compressed bitmap
448  
-    * answer goes into container
  463
+    * answer goes into container.
  464
+    * Running time complexity is proportional to the sum of the compressed
  465
+    * bitmap sizes.
449 466
     * (alias for rawlogicalor)
450 467
     */
451 468
     void logicalor( EWAHBoolArray &a, EWAHBoolArray &container)  {
452  
-    	rawlogicalor(a,container);
  469
+	   rawlogicalor(a,container);
453 470
     }
454 471
 
455 472
 	/**
@@ -479,12 +496,25 @@ class EWAHBoolArray {
479 496
     */
480 497
     void debugprintout() const;
481 498
 
  499
+    /**
  500
+    * Return the size in bits of this bitmap (this refers
  501
+    * to the uncompressed size in bits).
  502
+    */
482 503
     inline size_t sizeInBits() const {
483 504
         return sizeinbits;
484 505
     }
  506
+
  507
+    /**
  508
+    * set size in bits.
  509
+    */
485 510
     inline void setSizeInBits(const size_t size) {
486 511
         sizeinbits = size;
487 512
     }
  513
+
  514
+    /**
  515
+    * Return the size of the buffer in bytes. This 
  516
+    * is equivalent to the storage cost, minus some overhead.
  517
+    */
488 518
     inline size_t sizeInBytes() const {
489 519
         return buffer.size()*sizeof(uword);
490 520
     }
@@ -564,19 +594,28 @@ class EWAHBoolArray {
564 594
 
565 595
     bool operator!=(const BoolArray<uword> & x) const;
566 596
     
567  
-    /*
568  
-    * For expert users.
569  
-	*/
  597
+    /**
  598
+    * Iterate over the uncompressed words.
  599
+    * Can be considerably faster than begin()/end().
  600
+    * Running time complexity of a full scan is proportional to the 
  601
+    * uncompressed size of the bitmap.
  602
+    */
570 603
     EWAHBoolArrayIterator<uword> uncompress() const ;
571 604
     
572  
-    /*
573  
-    * For expert users.
574  
-	*/
  605
+    /**
  606
+    * To iterate over non-zero uncompressed words.
  607
+    * Can be considerably faster than begin()/end().
  608
+    * Running time complexity of a fun scan is proportional to the number of
  609
+    * non-zero uncompressed words.
  610
+    */
575 611
     EWAHBoolArraySparseIterator<uword> sparse_uncompress() const ;
576 612
 
577  
-    /*
578  
-    * For expert users.
579  
-	*/
  613
+    /**
  614
+    * To iterate over the compressed data.
  615
+    * Can be faster than any other iterator.
  616
+    * Running time complexity of a full scan is proportional to the
  617
+    * compressed size of the bitmap.
  618
+    */
580 619
     EWAHBoolArrayRawIterator<uword> raw_iterator() const ;
581 620
 
582 621
     /*
@@ -608,11 +647,20 @@ class EWAHBoolArray {
608 647
     */
609 648
     template <class container>
610 649
     void appendSetBits(container & out, const size_t offset = 0) const {
611  
-    	return appendRowIDs(out,offset);
  650
+	return appendRowIDs(out,offset);
612 651
     }
613 652
     
  653
+    /**
  654
+    * Returns the number of bits set to the value 1.
  655
+    * The running time complexity is proportional to the 
  656
+    * compressed size of the bitmap.
  657
+    */
614 658
     size_t numberOfOnes();
615 659
     
  660
+    /**
  661
+    * Swap the content of this bitmap with another bitmap.
  662
+    * No copying is done. (Running time complexity is constant.)
  663
+    */
616 664
     void swap(EWAHBoolArray & x);
617 665
     
618 666
     const vector<uword> & getBuffer() const {
@@ -622,7 +670,8 @@ class EWAHBoolArray {
622 670
 
623 671
 
624 672
     /**
625  
-     *Please don't copy your bitmaps!
  673
+     *Please don't copy your bitmaps! The running time
  674
+     * complexity of a copy is the size of the compressed bitmap.
626 675
      **/
627 676
     EWAHBoolArray(const EWAHBoolArray& other) :
628 677
         buffer(other.buffer),
@@ -632,18 +681,22 @@ class EWAHBoolArray {
632 681
 
633 682
     }
634 683
     
635  
-    /*
  684
+    /**
  685
+    * Copies the content of one bitmap onto another. Running time complexity
  686
+    * is proportional to the size of the compressed bitmap.
636 687
     * please, never hard-copy this object. Use the swap method if you must.
637 688
     */
638 689
     EWAHBoolArray & operator=(const EWAHBoolArray & x) {
639 690
         buffer = x.buffer;
640 691
         sizeinbits = x.sizeinbits;
641 692
         lastRLW = x.lastRLW;
642  
-        assert(buffer.size()<=1);// performance assert!
643 693
         return *this;
644 694
     }
645 695
 
646 696
     /**
  697
+     * This is equivalent to the operator =. It is used
  698
+     * to keep in mind that assignment can be expensive. 
  699
+     *
647 700
      *if you don't care to copy the bitmap (performance-wise), use this!
648 701
      */
649 702
     void expensive_copy(const EWAHBoolArray & x) {
@@ -652,8 +705,15 @@ class EWAHBoolArray {
652 705
         lastRLW = x.lastRLW;
653 706
     }
654 707
 
  708
+    /**
  709
+    * Write the logical not of this bitmap in the provided container.
  710
+    */
655 711
     void logicalnot(EWAHBoolArray & x) const;
656 712
     
  713
+    /**
  714
+    * Apply the logical not operation on this bitmap.
  715
+    * Running time complexity is proportional to the compressed size of the bitmap.
  716
+    */
657 717
     void inplace_logicalnot();
658 718
     
659 719
 
@@ -709,7 +769,7 @@ class EWAHBoolArraySparseIterator {
709 769
                 ++i.compressedwords;
710 770
                 returnvalue = EWAHBoolArrayIterator<uword>::notzero;
711 771
             } else {
712  
-                mPosition += i.rl;
  772
+                mPosition = static_cast<size_t>(mPosition + i.rl);
713 773
                 i.compressedwords = i.rl;
714 774
                 returnvalue = EWAHBoolArrayIterator<uword>::zero;//next();
715 775
             }
@@ -756,29 +816,29 @@ class EWAHBoolArraySetBitForwardIterator {
756 816
 	* Provides the location of the set bit.
757 817
 	*/
758 818
     size_t operator*() const {
759  
-    	return currentrunoffset+offsetofpreviousrun; 
  819
+	return currentrunoffset+offsetofpreviousrun; 
760 820
     }
761 821
     
762 822
     // this can be expensive
763 823
     difference_type operator-(const type_of_iterator& o) {
764  
-    	type_of_iterator& smaller = *this<o ? *this : o;
765  
-    	type_of_iterator& bigger = *this>=o ? *this : o;
766  
-    	if(smaller.mpointer==smaller.buffer.size())
767  
-    	  return 0;
768  
-    	difference_type absdiff = static_cast<difference_type>(0);
769  
-    	EWAHBoolArraySetBitForwardIterator<uword> buf(smaller);
770  
-    	while(buf!= bigger) {
771  
-    		++absdiff;
772  
-    		++buf;
773  
-    	}
774  
-    	if(*this<o) 
775  
-    		return absdiff;
776  
-    	else 
777  
-    		return - absdiff;
  824
+	type_of_iterator& smaller = *this<o ? *this : o;
  825
+	type_of_iterator& bigger = *this>=o ? *this : o;
  826
+	if(smaller.mpointer==smaller.buffer.size())
  827
+	  return 0;
  828
+	difference_type absdiff = static_cast<difference_type>(0);
  829
+	EWAHBoolArraySetBitForwardIterator<uword> buf(smaller);
  830
+	while(buf!= bigger) {
  831
+		++absdiff;
  832
+		++buf;
  833
+	}
  834
+	if(*this<o) 
  835
+		return absdiff;
  836
+	else 
  837
+		return - absdiff;
778 838
     }
779 839
     
780 840
     bool operator<(const type_of_iterator& o) {
781  
-    	if(buffer != o.buffer) return false;
  841
+	if(buffer != o.buffer) return false;
782 842
 		if(mpointer==buffer.size()) return false;
783 843
 		if(o.mpointer==o.buffer.size()) return true;
784 844
 		if(offsetofpreviousrun<o.offsetofpreviousrun)
@@ -790,42 +850,42 @@ class EWAHBoolArraySetBitForwardIterator {
790 850
 		return false;
791 851
     }
792 852
     bool operator<=(const type_of_iterator& o) {
793  
-    	return ( (*this) < o ) || ((*this) == o);
  853
+	return ( (*this) < o ) || ((*this) == o);
794 854
     }
795 855
     
796 856
     bool operator>(const type_of_iterator& o) {
797  
-    	return ! ((*this) <= o ) ;
  857
+	return ! ((*this) <= o ) ;
798 858
     }
799 859
     
800 860
     bool operator>=(const type_of_iterator& o) {
801  
-    	return ! ((*this) < o ) ;
  861
+	return ! ((*this) < o ) ;
802 862
     }
803 863
     
804 864
     EWAHBoolArraySetBitForwardIterator & operator++() {
805  
-    	++currentrunoffset;
806  
-    	advanceToNextSetBit();
807  
-    	return *this;
  865
+	++currentrunoffset;
  866
+	advanceToNextSetBit();
  867
+	return *this;
808 868
     }
809 869
     EWAHBoolArraySetBitForwardIterator  operator++(int) {
810  
-    	EWAHBoolArraySetBitForwardIterator old(*this);
811  
-    	++currentrunoffset;
812  
-    	advanceToNextSetBit();
813  
-    	return old;
  870
+	EWAHBoolArraySetBitForwardIterator old(*this);
  871
+	++currentrunoffset;
  872
+	advanceToNextSetBit();
  873
+	return old;
814 874
     }
815 875
     bool operator==(const EWAHBoolArraySetBitForwardIterator<uword> & o) {
816  
-    	// if they are both over, return true
817  
-    	if((mpointer==buffer.size()) && (o.mpointer==o.buffer.size()))
818  
-    	  return true;
819  
-    	return (buffer == o.buffer) && (mpointer == o.mpointer) && 
820  
-    	(offsetofpreviousrun == o.offsetofpreviousrun) && (currentrunoffset == o.currentrunoffset);
  876
+	// if they are both over, return true
  877
+	if((mpointer==buffer.size()) && (o.mpointer==o.buffer.size()))
  878
+	  return true;
  879
+	return (buffer == o.buffer) && (mpointer == o.mpointer) && 
  880
+	(offsetofpreviousrun == o.offsetofpreviousrun) && (currentrunoffset == o.currentrunoffset);
821 881
     }
822 882
 
823 883
     bool operator!=(const EWAHBoolArraySetBitForwardIterator<uword> & o) {
824  
-    	// if they are both over, return false
825  
-    	if((mpointer==buffer.size()) && (o.mpointer==o.buffer.size()))
826  
-    	  return false;
827  
-    	return (buffer != o.buffer) || (mpointer != o.mpointer) || 
828  
-    	(offsetofpreviousrun != o.offsetofpreviousrun) || (currentrunoffset != o.currentrunoffset);
  884
+	// if they are both over, return false
  885
+	if((mpointer==buffer.size()) && (o.mpointer==o.buffer.size()))
  886
+	  return false;
  887
+	return (buffer != o.buffer) || (mpointer != o.mpointer) || 
  888
+	(offsetofpreviousrun != o.offsetofpreviousrun) || (currentrunoffset != o.currentrunoffset);
829 889
     }
830 890
 
831 891
 
@@ -839,10 +899,10 @@ class EWAHBoolArraySetBitForwardIterator {
839 899
 		if (currentrunoffset<static_cast<size_t>(rlw.getRunningLength() * wordinbits)) {
840 900
 			if(rlw.getRunningBit())
841 901
 			  return true;// nothing to do
842  
-			currentrunoffset=rlw.getRunningLength() * wordinbits;//skipping
  902
+			currentrunoffset = static_cast<size_t>(rlw.getRunningLength() * wordinbits);//skipping
843 903
 		}
844 904
 		while(true) {
845  
-			const size_t indexoflitword = (currentrunoffset-rlw.getRunningLength() * wordinbits)/wordinbits;
  905
+			const size_t indexoflitword = static_cast<size_t>( (currentrunoffset-rlw.getRunningLength() * wordinbits)/wordinbits);
846 906
 			if(indexoflitword>= rlw.getNumberOfLiteralWords() ) {
847 907
 				if(advanceToNextRun())
848 908
 					return advanceToNextSetBit();
@@ -863,7 +923,7 @@ class EWAHBoolArraySetBitForwardIterator {
863 923
 	bool advanceToNextRun() {
864 924
 		offsetofpreviousrun += currentrunoffset;
865 925
 		currentrunoffset = 0;
866  
-		mpointer += 1 + rlw.getNumberOfLiteralWords();
  926
+		mpointer += static_cast<size_t>(1 + rlw.getNumberOfLiteralWords());
867 927
 		if(mpointer<buffer.size()) {
868 928
 		  rlw.mydata = buffer[mpointer];
869 929
 		} else {
@@ -875,10 +935,10 @@ class EWAHBoolArraySetBitForwardIterator {
875 935
 
876 936
     EWAHBoolArraySetBitForwardIterator(const vector<uword> & parent, size_t startpointer = 0) : buffer(parent), mpointer(startpointer), 
877 937
     offsetofpreviousrun(0), currentrunoffset(0), rlw(0)  {
878  
-    	if(mpointer<buffer.size()) {
879  
-    	  rlw.mydata = buffer[mpointer];
880  
-    	  advanceToNextSetBit();
881  
-    	}
  938
+	if(mpointer<buffer.size()) {
  939
+	  rlw.mydata = buffer[mpointer];
  940
+	  advanceToNextSetBit();
  941
+	}
882 942
     }
883 943
 
884 944
 
@@ -939,16 +999,16 @@ void EWAHBoolArray<uword>::set(size_t i) {
939 999
         RunningLengthWord<uword> lastRunningLengthWord(buffer[lastRLW]);
940 1000
         if(( lastRunningLengthWord.getNumberOfLiteralWords() == 0) || ((sizeinbits
941 1001
                 -1)/(8*sizeof(uword)) < i/(8*sizeof(uword))) ) {
942  
-            const uword newdata = static_cast<uword>(1)<<bittoflip;
  1002
+            const uword newdata = static_cast<uword>(static_cast<uword>(1)<<bittoflip);
943 1003
             addLiteralWord(newdata);
944 1004
         } else {
945  
-            buffer[buffer.size()-1] |= static_cast<uword>(1)<<bittoflip;
  1005
+            buffer[buffer.size()-1] |= static_cast<uword>(static_cast<uword>(1)<<bittoflip);
946 1006
             // check if we just completed a stream of 1s
947 1007
             if(buffer[buffer.size()-1] == static_cast<uword>(~0))  {
948 1008
                 // we remove the last dirty word
949 1009
                 buffer[buffer.size()-1] = 0;
950 1010
                 buffer.resize(buffer.size()-1);
951  
-                lastRunningLengthWord.setNumberOfLiteralWords(lastRunningLengthWord.getNumberOfLiteralWords()-1);
  1011
+                lastRunningLengthWord.setNumberOfLiteralWords(static_cast<uword>(lastRunningLengthWord.getNumberOfLiteralWords()-1));
952 1012
                 // next we add one clean word
953 1013
                 addEmptyWord(true);
954 1014
             }
@@ -1009,7 +1069,7 @@ size_t EWAHBoolArray<uword>::add(const uword  newdata, const uint bitsthatmatter
1009 1069
 template <class uword>
1010 1070
 inline void EWAHBoolArray<uword>::writeBuffer(ostream & out) const {
1011 1071
 	if(buffer.size()>0)
1012  
-	    out.write(reinterpret_cast<const char *>(& buffer[0]),sizeof(uword)*buffer.size());
  1072
+		out.write(reinterpret_cast<const char *>(& buffer[0]),sizeof(uword)*buffer.size());
1013 1073
 }
1014 1074
 
1015 1075
 
@@ -1017,7 +1077,7 @@ template <class uword>
1017 1077
 inline void EWAHBoolArray<uword>::readBuffer(istream & in, const size_t buffersize) {
1018 1078
     buffer.resize(buffersize);
1019 1079
     if(buffersize>0)
1020  
-	    in.read(reinterpret_cast<char *>(&buffer[0]),sizeof(uword)*buffersize);
  1080
+		in.read(reinterpret_cast<char *>(&buffer[0]),sizeof(uword)*buffersize);
1021 1081
 }
1022 1082
 
1023 1083
 
@@ -1027,7 +1087,7 @@ void EWAHBoolArray<uword>::write(ostream & out, const bool savesizeinbits) const
1027 1087
     const size_t buffersize = buffer.size();
1028 1088
     out.write(reinterpret_cast<const char *>(& buffersize),sizeof(buffersize));
1029 1089
     if(buffersize>0)
1030  
-	    out.write(reinterpret_cast<const char *>(& buffer[0]),sizeof(uword)*buffersize);
  1090
+		out.write(reinterpret_cast<const char *>(& buffer[0]),sizeof(uword)*buffersize);
1031 1091
 }
1032 1092
 
1033 1093
 
@@ -1039,7 +1099,7 @@ void EWAHBoolArray<uword>::read(istream & in, const bool savesizeinbits) {
1039 1099
     in.read(reinterpret_cast<char *>(&buffersize), sizeof(buffersize));
1040 1100
     buffer.resize(buffersize);
1041 1101
     if(buffersize>0)
1042  
-	    in.read(reinterpret_cast<char *>(&buffer[0]),sizeof(uword)*buffersize);
  1102
+		in.read(reinterpret_cast<char *>(&buffer[0]),sizeof(uword)*buffersize);
1043 1103
 }
1044 1104
 
1045 1105
 
@@ -1055,7 +1115,7 @@ size_t EWAHBoolArray<uword>::addLiteralWord(const uword  newdata) {
1055 1115
         buffer.push_back(newdata);
1056 1116
         return 2;
1057 1117
     }
1058  
-    lastRunningLengthWord.setNumberOfLiteralWords(numbersofar + 1);
  1118
+    lastRunningLengthWord.setNumberOfLiteralWords(static_cast<uword>(numbersofar + 1));
1059 1119
     assert(lastRunningLengthWord.getNumberOfLiteralWords()==numbersofar + 1);
1060 1120
     buffer.push_back(newdata);
1061 1121
     return 1;
@@ -1102,14 +1162,14 @@ class EWAHBoolArrayRawIterator {
1102 1162
     BufferedRunningLengthWord<uword> & next() {
1103 1163
         assert(pointer < myparent->size());
1104 1164
         rlw.read( (*myparent)[pointer]);
1105  
-        pointer += rlw.getNumberOfLiteralWords() + 1;
  1165
+        pointer = static_cast<size_t>(pointer + rlw.getNumberOfLiteralWords() + 1);
1106 1166
         return rlw;
1107 1167
     }
1108 1168
 
1109 1169
     const uword * dirtyWords()  const {
1110 1170
         assert(pointer>0);
1111 1171
         assert(pointer>=rlw.getNumberOfLiteralWords());
1112  
-        return & (myparent->at(pointer-rlw.getNumberOfLiteralWords()));
  1172
+        return & (myparent->at(static_cast<size_t>(pointer-rlw.getNumberOfLiteralWords())));
1113 1173
     }
1114 1174
 
1115 1175
     EWAHBoolArrayRawIterator & operator=(const EWAHBoolArrayRawIterator & other) {
@@ -1265,12 +1325,12 @@ void EWAHBoolArray<uword>::appendRowIDs(container & out, const size_t offset) co
1265 1325
                 out.push_back(currentoffset + x);
1266 1326
             }
1267 1327
         }
1268  
-        currentoffset+=rlw.getRunningLength()*wordinbits;
  1328
+        currentoffset = static_cast<size_t>(currentoffset + rlw.getRunningLength() * wordinbits);
1269 1329
         ++pointer;
1270 1330
         for(uword k = 0; k<rlw.getNumberOfLiteralWords(); ++k) {
1271 1331
             const uword currentword = buffer[pointer];
1272 1332
             for(uint kk = 0; kk < wordinbits; ++kk) {
1273  
-                if ( (currentword & (static_cast<uword>(1) << kk)) != 0) 
  1333
+                if ( ( currentword & static_cast<uword>(static_cast<uword>(1) << kk)) != 0) 
1274 1334
                     out.push_back(currentoffset + kk);
1275 1335
             }
1276 1336
             currentoffset+=wordinbits;
@@ -1314,9 +1374,9 @@ size_t EWAHBoolArray<uword>::addStreamOfEmptyWords(const bool v, const size_t nu
1314 1374
     if( ( noliteralword ) && (lastRunningLengthWord.getRunningBit() == v) && (runlen < RunningLengthWord<uword>::largestrunninglengthcount) ) {
1315 1375
         // that's the easy case, we are just continuing
1316 1376
         uword whatwecanadd = static_cast<uword>( number < static_cast<uword>(RunningLengthWord<uword>::largestrunninglengthcount-runlen) ? number : static_cast<size_t>(RunningLengthWord<uword>::largestrunninglengthcount-runlen) );
1317  
-        lastRunningLengthWord.setRunningLength(runlen+whatwecanadd);
1318  
-        sizeinbits += whatwecanadd*wordinbits;
1319  
-        if(number - whatwecanadd> 0 ) wordsadded += addStreamOfEmptyWords(v, number - whatwecanadd);
  1377
+        lastRunningLengthWord.setRunningLength(static_cast<uword>(runlen+whatwecanadd));
  1378
+        sizeinbits = static_cast<size_t>(sizeinbits + whatwecanadd * wordinbits);
  1379
+        if(number - whatwecanadd> 0 ) wordsadded = static_cast<size_t>(wordsadded + addStreamOfEmptyWords(v, static_cast<size_t>(number - whatwecanadd)));
1320 1380
     } else {
1321 1381
         buffer.push_back(0);
1322 1382
         ++wordsadded;
@@ -1325,8 +1385,8 @@ size_t EWAHBoolArray<uword>::addStreamOfEmptyWords(const bool v, const size_t nu
1325 1385
         uword whatwecanadd = static_cast<uword>( number < RunningLengthWord<uword>::largestrunninglengthcount ? number : static_cast<size_t>(RunningLengthWord<uword>::largestrunninglengthcount) );
1326 1386
         lastRunningLengthWord2.setRunningBit(v);
1327 1387
         lastRunningLengthWord2.setRunningLength(whatwecanadd);
1328  
-        sizeinbits += whatwecanadd*wordinbits;
1329  
-        if(number - whatwecanadd> 0 ) wordsadded += addStreamOfEmptyWords(v, number - whatwecanadd);
  1388
+        sizeinbits = static_cast<size_t>(sizeinbits +  whatwecanadd * wordinbits);
  1389
+        if(number - whatwecanadd> 0 ) wordsadded = static_cast<size_t>( wordsadded + addStreamOfEmptyWords(v, static_cast<size_t>(number - whatwecanadd)));
1330 1390
     }
1331 1391
     return wordsadded;
1332 1392
 }
@@ -1374,7 +1434,7 @@ size_t EWAHBoolArray<uword>::addEmptyWord(const bool v) {
1374 1434
         assert(lastRunningLengthWord.getRunningBit() == v);
1375 1435
     }
1376 1436
     if( ( noliteralword ) && (lastRunningLengthWord.getRunningBit() == v) && (runlen < RunningLengthWord<uword>::largestrunninglengthcount) ) {
1377  
-        lastRunningLengthWord.setRunningLength(runlen+1);
  1437
+        lastRunningLengthWord.setRunningLength(static_cast<uword>(runlen+1));
1378 1438
         assert(lastRunningLengthWord.getRunningLength() == runlen+1);
1379 1439
         return 0;
1380 1440
     } else {
@@ -1464,12 +1524,12 @@ void EWAHBoolArray<uword>::rawlogicalor(EWAHBoolArray &a, EWAHBoolArray &contain
1464 1524
             const uword preyrl (prey.getRunningLength());
1465 1525
             if(predatorrl >= preyrl) {
1466 1526
                 const uword tobediscarded =  preyrl ;
1467  
-                container.addStreamOfEmptyWords(predator.getRunningBit(), tobediscarded);
  1527
+                container.addStreamOfEmptyWords(predator.getRunningBit(), static_cast<size_t>(tobediscarded));
1468 1528
             } else {
1469 1529
                 const uword tobediscarded =   predatorrl ;
1470  
-                container.addStreamOfEmptyWords(predator.getRunningBit(), tobediscarded);
  1530
+                container.addStreamOfEmptyWords(predator.getRunningBit(), static_cast<size_t>(tobediscarded));
1471 1531
                 const uword * dw_predator (i_is_prey ? j.dirtyWords(): i.dirtyWords());
1472  
-                container.addStreamOfDirtyWords(dw_predator, preyrl - tobediscarded);
  1532
+                container.addStreamOfDirtyWords(dw_predator, static_cast<size_t>(preyrl - tobediscarded));
1473 1533
             }
1474 1534
             predator.discardFirstWords(preyrl);
1475 1535
             prey.discardFirstWords(preyrl);
@@ -1478,7 +1538,7 @@ void EWAHBoolArray<uword>::rawlogicalor(EWAHBoolArray &a, EWAHBoolArray &contain
1478 1538
             const uword preyrl (prey.getRunningLength());
1479 1539
             predator.discardFirstWords(preyrl);
1480 1540
             prey.discardFirstWords(preyrl);
1481  
-            container.addStreamOfEmptyWords(1, preyrl);
  1541
+            container.addStreamOfEmptyWords(1, static_cast<size_t>(preyrl));
1482 1542
         }
1483 1543
         const uword predatorrl (predator.getRunningLength());
1484 1544
         if(predatorrl>0) {
@@ -1486,7 +1546,7 @@ void EWAHBoolArray<uword>::rawlogicalor(EWAHBoolArray &a, EWAHBoolArray &contain
1486 1546
                 const uword nbre_dirty_prey(prey.getNumberOfLiteralWords());
1487 1547
                 const uword * dw_prey (i_is_prey ? i.dirtyWords(): j.dirtyWords());
1488 1548
                 const uword tobediscarded = (predatorrl >= nbre_dirty_prey) ? nbre_dirty_prey : predatorrl;
1489  
-                container.addStreamOfDirtyWords(dw_prey, tobediscarded);
  1549
+                container.addStreamOfDirtyWords(dw_prey, static_cast<size_t>(tobediscarded));
1490 1550
                 predator.discardFirstWords(tobediscarded);
1491 1551
                 prey.discardFirstWords(tobediscarded);
1492 1552
             } else {
@@ -1494,7 +1554,7 @@ void EWAHBoolArray<uword>::rawlogicalor(EWAHBoolArray &a, EWAHBoolArray &contain
1494 1554
                 const uword tobediscarded = (predatorrl >= nbre_dirty_prey) ? nbre_dirty_prey : predatorrl;
1495 1555
                 predator.discardFirstWords(tobediscarded);
1496 1556
                 prey.discardFirstWords(tobediscarded);
1497  
-                container.addStreamOfEmptyWords(1, tobediscarded);
  1557
+                container.addStreamOfEmptyWords(1, static_cast<size_t>(tobediscarded));
1498 1558
             }
1499 1559
         }
1500 1560
         assert(prey.getRunningLength() ==0);
@@ -1543,15 +1603,15 @@ void EWAHBoolArray<uword>::rawlogicaland(EWAHBoolArray &a, EWAHBoolArray &contai
1543 1603
             const uword preyrl (prey.getRunningLength());
1544 1604
             predator.discardFirstWords(preyrl);
1545 1605
             prey.discardFirstWords(preyrl);
1546  
-            container.addStreamOfEmptyWords(0, preyrl);
  1606
+            container.addStreamOfEmptyWords(0, static_cast<size_t>(preyrl));
1547 1607
         } else {
1548 1608
             // we have a stream of 1x11
1549 1609
             const uword predatorrl (predator.getRunningLength());
1550 1610
             const uword preyrl (prey.getRunningLength());
1551 1611
             const uword tobediscarded = (predatorrl >= preyrl) ?  preyrl : predatorrl;
1552  
-            container.addStreamOfEmptyWords(predator.getRunningBit(), tobediscarded);
  1612
+            container.addStreamOfEmptyWords(predator.getRunningBit(), static_cast<size_t>(tobediscarded));
1553 1613
             const uword * dw_predator (i_is_prey ? j.dirtyWords(): i.dirtyWords());
1554  
-            container.addStreamOfDirtyWords(dw_predator, preyrl - tobediscarded);
  1614
+            container.addStreamOfDirtyWords(dw_predator, static_cast<size_t>(preyrl - tobediscarded));
1555 1615
             predator.discardFirstWords(preyrl);
1556 1616
             prey.discardFirstWords(preyrl);
1557 1617
         }
@@ -1562,12 +1622,12 @@ void EWAHBoolArray<uword>::rawlogicaland(EWAHBoolArray &a, EWAHBoolArray &contai
1562 1622
                 const uword tobediscarded = (predatorrl >= nbre_dirty_prey) ? nbre_dirty_prey : predatorrl;
1563 1623
                 predator.discardFirstWords(tobediscarded);
1564 1624
                 prey.discardFirstWords(tobediscarded);
1565  
-                container.addStreamOfEmptyWords(0, tobediscarded);
  1625
+                container.addStreamOfEmptyWords(0, static_cast<size_t>(tobediscarded));
1566 1626
             } else {
1567 1627
                 const uword nbre_dirty_prey(prey.getNumberOfLiteralWords());
1568 1628
                 const uword * dw_prey (i_is_prey ? i.dirtyWords(): j.dirtyWords());
1569 1629
                 const uword tobediscarded = (predatorrl >= nbre_dirty_prey) ? nbre_dirty_prey : predatorrl;
1570  
-                container.addStreamOfDirtyWords(dw_prey, tobediscarded);
  1630
+                container.addStreamOfDirtyWords(dw_prey, static_cast<size_t>(tobediscarded));
1571 1631
                 predator.discardFirstWords(tobediscarded);
1572 1632
                 prey.discardFirstWords(tobediscarded);
1573 1633
             }
15  makefile
... ...
@@ -1,11 +1,15 @@
1 1
 VPATH = src:headers
2  
-CXXFLAGS=-Iheaders -O2 -Wall -Wextra -Weffc++ -Wshadow -Wcast-align -Wwrite-strings -Wstrict-overflow=5  -Wpointer-arith -Winit-self  
  2
+CXXFLAGS=-Iheaders -O2 -Wall -Wextra -Weffc++ -Wconversion -Wshadow -Wcast-align -Wwrite-strings -Wstrict-overflow=5  -Wpointer-arith -Winit-self  
3 3
 HEADERS=ewah.h boolarray.h
4 4
 
  5
+all: unit unit32bits example
5 6
 
6  
-unit: $(HEADERS) unit.cpp
7  
-	g++ $(CXXFLAGS) -o unit src/unit.cpp 
  7
+unit32bits: $(HEADERS) unit.cpp
  8
+	g++ $(CXXFLAGS) -m32 -o unit32bits src/unit.cpp 
8 9
 	
  10
+unit: $(HEADERS) unit.cpp 
  11
+	g++ $(CXXFLAGS) -o unit src/unit.cpp 
  12
+		
9 13
 example: $(HEADERS) example.cpp
10 14
 	g++ $(CXXFLAGS) -o example example.cpp
11 15
 
@@ -13,13 +17,10 @@ cppcheck:
13 17
 	cppcheck --enable=all headers/*.h src/*.cpp *.cpp
14 18
 
15 19
 
16  
-all: 
17  
-	unit 
18  
-
19 20
 doxygen: 
20 21
 	doxygen doxyconfig.txt
21 22
 
22 23
 package: 
23 24
 	zip -9 EWAHBoolArray_`date +%Y-%m-%d`.zip README makefile example.cpp headers/*.h src/*.cpp
24 25
 clean: 
25  
-	rm -f *.o unit example
  26
+	rm -f *.o unit example unit32bits
10  src/unit.cpp
@@ -24,7 +24,7 @@ bool testRunningLengthWord() {
24 24
         cout << "failed to set the running bit " << sizeof (uword) << endl;
25 25
         isOk = false;
26 26
     }
27  
-    for (uword myrl = 0; myrl <= RunningLengthWord<uword>::largestrunninglengthcount; myrl+=RunningLengthWord<uword>::largestrunninglengthcount/10) {
  27
+    for (uword myrl = 0; myrl <= RunningLengthWord<uword>::largestrunninglengthcount; myrl=static_cast<uword>( myrl + RunningLengthWord<uword>::largestrunninglengthcount/10)) {
28 28
         rlw.setRunningLength(myrl);
29 29
         if (rlw.getRunningBit() != true) {
30 30
             cout << "failed to set the running bit (2) " << sizeof (uword) << endl;
@@ -36,7 +36,7 @@ bool testRunningLengthWord() {
36 36
         }
37 37
     }
38 38
     rlw.setRunningLength(12);
39  
-    for (uword mylw = 0; mylw <= RunningLengthWord<uword>::largestliteralcount; mylw+=RunningLengthWord<uword>::largestliteralcount/10) {
  39
+    for (uword mylw = 0; mylw <= RunningLengthWord<uword>::largestliteralcount; mylw= static_cast<uword>(mylw+RunningLengthWord<uword>::largestliteralcount/10)) {
40 40
         rlw.setNumberOfLiteralWords(mylw);
41 41
         if (rlw.getRunningBit() != true) {
42 42
             cout << "failed to set the running bit (3) " << sizeof (uword) << endl;
@@ -76,7 +76,7 @@ bool testEWAHBoolArrayAppend() {
76 76
     bool isOk(true);
77 77
     uword zero = 0;
78 78
     uword specialval = 1UL + (1UL << 4)+(static_cast<uword>(1) << (sizeof(uword)*8-1));
79  
-    uword notzero = ~zero;
  79
+    uword notzero = static_cast<uword>(~zero);
80 80
     EWAHBoolArray<uword> myarray1;
81 81
     BoolArray<uword> ba1;
82 82
     myarray1.add(zero);
@@ -162,7 +162,7 @@ bool testJoergBukowski() {
162 162
     	ifstream in(indexfile.c_str(),ios::binary);
163 163
     	recovered.read(in);
164 164
     	in.close();
165  
-    	vector<uint> vals;
  165
+    	vector<size_t> vals;
166 166
     	recovered.appendSetBits(vals);
167 167
     	if(vals.size()!= static_cast<size_t>(i-positions.begin()+1)) {
168 168
     	  cout<<"failed to recover right number"<<endl; 
@@ -282,7 +282,7 @@ bool testEWAHBoolArray() {
282 282
     EWAHBoolArray<uword> myarray;
283 283
     BoolArray<uword> ba(10 * sizeof (uword) * 8);
284 284
     uword zero = 0;
285  
-    uword notzero = ~zero;
  285
+    uword notzero = static_cast<uword>(~zero);
286 286
     myarray.add(zero);
287 287
     ba.setWord(0, zero);
288 288
     myarray.add(zero);

0 notes on commit d7e2427

Please sign in to comment.
Something went wrong with that request. Please try again.