"Fossies" - the Fresh Open Source Software Archive

Member "xdelta3-3.0.11/testing/sizes.h" (24 Mar 2015, 2217 Bytes) of package /linux/misc/xdelta3-3.0.11.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // -*- Mode: C++ -*-
    2 template <typename T, typename U>
    3 class SizeIterator {
    4  public:
    5   SizeIterator(MTRandom *rand, size_t howmany)
    6     : rand_(rand),
    7       count_(0),
    8       fixed_(U::sizes),
    9       fixed_size_(SIZEOF_ARRAY(U::sizes)),
   10       howmany_(howmany) { }
   11 
   12   T Get() {
   13     if (count_ < fixed_size_) {
   14       return fixed_[count_];
   15     }
   16     return rand_->Rand<T>() % U::max_value;
   17   }
   18 
   19   bool Done() {
   20     return count_ >= fixed_size_ && count_ >= howmany_;
   21   }
   22 
   23   void Next() {
   24     count_++;
   25   }
   26 
   27  private:
   28   MTRandom *rand_;
   29   size_t count_;
   30   T* fixed_;
   31   size_t fixed_size_;
   32   size_t howmany_;
   33 };
   34 
   35 // Small sizes
   36 class SmallSizes {
   37 public:
   38   static size_t sizes[];
   39   static size_t max_value;
   40 };
   41 
   42 size_t SmallSizes::sizes[] = {
   43   0, 1, 128 / 4, 3333, 
   44   128 - (128 / 3),
   45   128,
   46   128 + (128 / 3),
   47   2 * 128 - (128 / 3),
   48   2 * 128,
   49   2 * 128 + (128 / 3),
   50 };
   51 
   52 size_t SmallSizes::max_value = 128 * 3;
   53 
   54 // Large sizes
   55 class LargeSizes {
   56 public:
   57   static size_t sizes[];
   58   static size_t max_value;
   59 };
   60 
   61 size_t LargeSizes::sizes[] = {
   62   1 << 20,
   63   1 << 18,
   64   1 << 16,
   65 };
   66 
   67 size_t LargeSizes::max_value = 1<<20;
   68 
   69 // Base constants
   70 struct BaseConstants {
   71   static const size_t TEST_ROUNDS;
   72 };
   73 
   74 const size_t BaseConstants::TEST_ROUNDS = 10;
   75 
   76 // Regtest<> arguments
   77 struct SmallBlock : public BaseConstants {
   78   static const xoff_t BLOCK_SIZE;
   79   static const size_t WINDOW_SIZE;
   80   typedef SmallSizes Sizes;
   81 };
   82 
   83 const xoff_t SmallBlock::BLOCK_SIZE = 1<<7;
   84 const size_t SmallBlock::WINDOW_SIZE = 1<<7;
   85 
   86 struct LargeBlock : public BaseConstants {
   87   static const xoff_t BLOCK_SIZE;
   88   static const size_t WINDOW_SIZE;
   89   typedef LargeSizes Sizes;
   90 };
   91 
   92 const xoff_t LargeBlock::BLOCK_SIZE = (1 << 13);
   93 const size_t LargeBlock::WINDOW_SIZE = (1 << 13);
   94 
   95 struct MixedBlock : public BaseConstants {
   96   static const xoff_t BLOCK_SIZE;
   97   static const size_t WINDOW_SIZE;
   98   typedef SmallSizes Sizes;
   99 };
  100 
  101 const xoff_t MixedBlock::BLOCK_SIZE = 1<<7;
  102 const size_t MixedBlock::WINDOW_SIZE = 1<<8;
  103 
  104 struct OversizeBlock : public BaseConstants {
  105   static const xoff_t BLOCK_SIZE;
  106   static const size_t WINDOW_SIZE;
  107   typedef SmallSizes Sizes;
  108 };
  109 
  110 const xoff_t OversizeBlock::BLOCK_SIZE = 1<<8;
  111 const size_t OversizeBlock::WINDOW_SIZE = 1<<7;