Esempio n. 1
0
S4Err  testZbase32()
{
    S4Err     err = kS4Err_NoErr;

    katvector kat_vector_array[] =
    {
        { 1,   (uint8_t*)"\x00",               "y"		},
        { 1,   (uint8_t*)"\x80",               "o"		},
        { 2,   (uint8_t*)"\x40",               "e"		},
        { 2,   (uint8_t*)"\xC0",               "a"		},
        { 10,  (uint8_t*)"\x00\x00",           "yy"	},
        { 10,  (uint8_t*)"\x80\x80",           "on"	},
        { 20,  (uint8_t*)"\x8B\x88\x80",       "tqre"	},

        { 24,  (uint8_t*)"\xF0\xBF\xC7",       "6n9hq"	},
        { 24,  (uint8_t*)"\xD4\x7A\x04",     	"4t7ye"	},

        { 30,  (uint8_t*)"\xF5\x57\xBD\x0C", "6im54d"	},  // the spec says "6im5sd" but I think it is wrong
        { 64,  (uint8_t*)"\x28\x6F\x20\x29\x28\x20\x6F\x29",               "fbz1ykjerbz11" },

        { 128,  (uint8_t*)"\x00\x01\x02\x03\x05\x06\x07\x08\x0A\x0B\x0C\x0D\x0F\x10\x11\x12",   "yyyoryafyadoonombogo6rytne" },
        {   160,  (uint8_t*) "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2\x6C"
            "\x9C\xD0\xD8\x9D",  "igcuhp18y4ysiqt6riazowgnp1qpbsr7"
        }
    };

    int i;

    for (i = 0; i < sizeof(kat_vector_array)/ sizeof(katvector) ; i++)
    {
        katvector* kat = &kat_vector_array[i];

        uint8_t  encoded[64]  = {0};
        uint8_t  decoded[64]  = {0};

        int len, len2;

        char* binString[128] = {0};

        bin_to_chars((uint8_t*)kat->base2, kat->bits, 24, (char*)binString);

        OPTESTLogVerbose("\t\t%4lu %2d %-30s %-32s\n",  kat->bits, INT_CEIL(kat->bits, 8), binString,  kat->zbase32);

        len = zbase32_encode((uint8_t*)encoded, (uint8_t*)kat->base2, kat->bits);

        /* check against encoded  */
        err = compareResults( kat->zbase32, encoded, len , kResultFormat_Byte, "Encoded");
        CKERR;

        len2 = zbase32_decode((uint8_t*) decoded, (uint8_t*)encoded, kat->bits);

        err = compareResults(decoded, kat->base2, len/8  , kResultFormat_Byte, "Decoded");
        CKERR;

    };
done:
    return err;

}
Esempio n. 2
0
/**
 * Computes the bytes required for a HLL of the
 * given precision.
 * @arg prec The precision to use
 * @return The bytes required or 0 on error.
 */
uint64_t hll_bytes_for_precision(int prec) {
    // Check that the error bound is sane
    if (prec < HLL_MIN_PRECISION || prec > HLL_MAX_PRECISION)
        return 0;

    // Determine how many registers are needed
    int reg = NUM_REG(prec);

    // Get the full words required
    int words = INT_CEIL(reg, REG_PER_WORD);

    // Convert to byte size
    return words * sizeof(uint32_t);
}
Esempio n. 3
0
/**
 * Initializes a new HLL
 * @arg precision The digits of precision to use
 * @arg h The HLL to initialize
 * @return 0 on success
 */
int hll_init(unsigned char precision, hll_t *h) {
    // Ensure the precision is somewhat sane
    if (precision < HLL_MIN_PRECISION || precision > HLL_MAX_PRECISION)
        return -1;

    // Store precision
    h->precision = precision;

    // Determine how many registers are needed
    int reg = NUM_REG(precision);

    // Get the full words required
    int words = INT_CEIL(reg, REG_PER_WORD);

    // Allocate and zero out the registers
    h->bm = NULL;
    h->registers = calloc(words, sizeof(uint32_t));
    if (!h->registers) return -1;
    return 0;
}
Esempio n. 4
0
void
winnow(
  int		tid,			/* own ID */
  int2D		matrix,			/* point values */
  bool2D	mask,			/* suitable points */
  int		nr,			/* row size */
  int		nc,			/* column size */
  pt1D		pt,			/* points to create */
  int		npt			/* number of points */
){
  int		i, j;			/* loop indices */
  int		sum, tmp;		/* for scanning */
#if GRAPHICS
  int		gfxCount = 0;
#endif

#if GRAPHICS
  if (MASTER(tid)){
    gfx_winnow(gfxCount++, matrix, mask, pt, nr, nc, npt);
  }
  thr_bar(tid);
#endif

  /* pack points into temporary storage */
  winnow_count(tid, mask, nr, nc);
  i = scanIntSum(tid, Totals, nr);
  if (MASTER(tid)){
    Len = i;
  }
  thr_bar(tid);
  /* set slice sizes */
  if (MASTER(tid)){
    NumSamples   = ParWidth * (ParWidth - 1);
    ParWidth_1   = ParWidth - 1;
    SectionSize  = INT_CEIL(Len, ParWidth);
    IntervalSize = INT_CEIL(SectionSize, ParWidth_1);
  }
  ASSERT(Len >= npt);
  winnow_copy(tid, matrix, mask, nr, nc);

  /* sort */
  if ((ParWidth == 1) || (Len < NumSamples)){
    if (MASTER(tid)){
      ptSort(TmpPt, Len);
      winnow_pack(pt, npt, TmpPt, Len, 1, 0);
    }
    thr_bar(tid);
  } else {
    /* sort sections and select P-1 pivot values */
    winnow_psrs_1(tid);
    if (MASTER(tid)){
      intSort(Pivots, NumSamples);
    }
    thr_bar(tid);
    /* select P-1 pivot values from P*(P-1) pivot values */
    if (MASTER(tid)){
      for (i=0, j=ParWidth_1/2; j<NumSamples; i++, j+=ParWidth){
	Pivots[i] = Pivots[j];
      }
      ASSERT(i == ParWidth_1);
    }
    thr_bar(tid);
    /* count elements in processor intervals that belong in pivot intervals */
    winnow_psrs_2(tid);
    /* scan number of elements in pivot intervals */
    if (MASTER(tid)){
      sum = 0;
      for (i=0; i<ParWidth; i++){
	for (j=0; j<ParWidth*ParWidth; j+=ParWidth){
	  tmp = Counts[i+j];
	  Starts[i+j] = sum;
	  sum += tmp;
	}
      }
    }
    thr_bar(tid);
    /* copy values into pivot intervals */
    winnow_psrs_3(tid);
    /* sort pivot intervals */
    winnow_psrs_4(tid);
    /* copy selected points */
    winnow_pack(pt, npt, TmpPt2, Len, ParWidth, tid);
  }

#if GRAPHICS
  if (MASTER(tid)){
    gfx_winnow(gfxCount++, matrix, mask, pt, nr, nc, npt);
  }
#endif

  /* return */
}