Exemplo n.º 1
0
std::size_t FSBloomFilter::containsAll(const unsigned char *keys,
		const std::size_t count) const {
	uint64_t hashes[count * this->functionCount_];
	for (std::size_t i = 0; i < count; i++) {
		for (std::size_t j = 0; j < this->functionCount_; j++) {
			hashes[i * this->functionCount_ + j]
					= this->hashFunction_->operator ()(
							keys
									+ (this->cryptoHashFunction_.getHashSize()
											* i),
							this->cryptoHashFunction_.getHashSize(), j)
							% this->filterSize_;
		}
	}
	std::sort(hashes, hashes + (count * this->functionCount_));
	std::size_t bit_index = 0;
	std::size_t bit = 0;
	for (std::size_t i = 0; i < count * this->functionCount_; i++) {
		compute_indices(hashes[i], bit_index, bit);
		if ((this->bitArray_[bit_index] & bit_mask[bit]) != bit_mask[bit]) {
			return i == 0 ? 1 : i;
		}
	}
	return true;
}
Exemplo n.º 2
0
void FSBloomFilter::addAll(const unsigned char* keys, const std::size_t count) {
	if (this->hardMaximum_ && this->itemCount_ + count > maxElements_)
		throw std::runtime_error("Maximum of Elements reached, adding failed");
	uint64_t hashes[count * this->functionCount_];
	for (std::size_t i = 0; i < count; i++) {
		for (std::size_t j = 0; j < this->functionCount_; j++) {
			hashes[i * this->functionCount_ + j]
					= this->hashFunction_->operator ()(
							keys
									+ (this->cryptoHashFunction_.getHashSize()
											* i),
							this->cryptoHashFunction_.getHashSize(), j);
		}
	}
	std::sort(hashes, hashes + (count * this->functionCount_));
	std::size_t bit_index = 0;
	std::size_t bit = 0;
	for (std::size_t i = 0; i < count * this->functionCount_; i++) {
		compute_indices(hashes[i], bit_index, bit);
		this->bitArray_[bit_index] |= bit_mask[bit];
	}
	if (this->itemCount_ + count < std::numeric_limits<uint64_t>::max()) {
		this->itemCount_ += count;
	} else {
		this->itemCount_ = std::numeric_limits<uint64_t>::max();
	}
}
Exemplo n.º 3
0
 /**
  * @brief Inserts a given value into the bloom filter.
  *
  * @param key_begin A pointer to the value being inserted.
  * @param length Size of the value being inserted in bytes.
  */
 inline void insert(const std::uint8_t *key_begin, const std::size_t &length) {
   std::size_t bit_index = 0;
   std::size_t bit = 0;
   for (std::size_t i = 0; i < hash_fn_count_; ++i) {
     compute_indices(hash_ap(key_begin, length, hash_fn_[i]), &bit_index, &bit);
     bit_array_[bit_index / kNumBitsPerByte] |= (1 << bit);
   }
   ++inserted_element_count_;
 }
Exemplo n.º 4
0
 inline void insert(const integer key) 
 {
    std::size_t bit_index = 0;
    std::size_t bit = 0;
    for(std::size_t i = 0;i < hash_count_; ++i)
    {
      compute_indices((hash_[i]).GetHashValue(key),bit_index,bit);
      bit_table_[bit_index / bits_per_char] |= bit_mask[bit];
    }
    ++inserted_element_count_;  
 }
Exemplo n.º 5
0
 /**
  * @brief Test membership of a given value in the bloom filter.
  *        If true is returned, then a value may or may not be present in the bloom filter.
  *        If false is returned, a value is certainly not present in the bloom filter.
  *
  * @param key_begin A pointer to the value being tested for membership.
  * @param length Size of the value being inserted in bytes.
  */
 inline bool contains(const std::uint8_t *key_begin, const std::size_t length) const {
   std::size_t bit_index = 0;
   std::size_t bit = 0;
   for (std::size_t i = 0; i < hash_fn_count_; ++i) {
     compute_indices(hash_ap(key_begin, length, hash_fn_[i]), &bit_index, &bit);
     if ((bit_array_[bit_index / kNumBitsPerByte] & (1 << bit)) != (1 << bit)) {
       return false;
     }
   }
   return true;
 }
Exemplo n.º 6
0
bool FSBloomFilter::contains(const unsigned char *key) const {
	std::size_t bit_index = 0;
	std::size_t bit = 0;

	for (std::size_t i = 0; i < this->functionCount_; i++) {
		uint64_t pos = this->hashFunction_->operator ()(key,
				this->cryptoHashFunction_.getHashSize(), i) % this->filterSize_;
		compute_indices(pos, bit_index, bit);
		if ((this->bitArray_[bit_index] & bit_mask[bit]) != bit_mask[bit]) {
			return false;
		}
	}
	return true;
}
Exemplo n.º 7
0
void FSBloomFilter::add(const unsigned char *key) {
	if (this->hardMaximum_ && this->itemCount_ >= maxElements_)
		throw std::runtime_error("Maximum of Elements reached, adding failed");
	std::size_t bit_index = 0;
	std::size_t bit = 0;
	for (std::size_t i = 0; i < this->functionCount_; i++) {
		uint64_t pos = this->hashFunction_->operator ()(key,
				this->cryptoHashFunction_.getHashSize(), i) % this->filterSize_;
		compute_indices(pos, bit_index, bit);
		this->bitArray_[bit_index] |= bit_mask[bit];
	}
	if (this->itemCount_ < std::numeric_limits<uint64_t>::max())
		this->itemCount_++;
}
Exemplo n.º 8
0
 inline virtual bool contains(const integer key) const
 {
    std::size_t bit_index = 0;
    std::size_t bit = 0;
    for (std::size_t i = 0; i < hash_count_; ++i)
    {
       compute_indices((hash_[i]).GetHashValue(key),bit_index,bit);
       if ((bit_table_[bit_index / bits_per_char] & bit_mask[bit]) != bit_mask[bit])
       {
          return false;
       }
    }
    return true;
   
 }
Exemplo n.º 9
0
int C2F(intihm)()
{
    /*
        une routine d'insertion pour hypermatrice : cas le plus
        simple :   A( vi1, ..., vik ) = B

          ihm ( vi1, vi2, ..., vik, B, A )

        avec des vecteurs d'indices classiques vi1, vi2, ....
        et B une hypermatrice ou bien une matrice
     */

    HyperMat A, B;
    int i, k,/* l, li, m, n,*/ ntot, mn,/* err_neg,*/ iconf, ind_max;
    int nb_index_vectors, B_is_scalar;
    int *j,/* nd,*/ one = 1, ltot, il, dec/*, Top_save*/;
    int *PA, *PB;
    short int *siPA, *siPB;
    char *cPA, *cPB;
    int ilp, topk;

    /*   CheckLhs(minlhs,maxlhs); */

    if ( Rhs < 3 )
    {
        Scierror(999, _("%s: Wrong number of input arguments: at least %d expected.\n"), "hmops", 3);
        return 0;
    };
    nb_index_vectors = Rhs - 2;

    if ( ! get_hmat(Rhs, &A) )
    {
        Scierror(999, _("%s: Wrong type for input argument(s): An hypermatrix expected.\n"), "hmops");
        return 0;
    }
    else if ( A.type == NOT_REAL_or_CMPLX_or_BOOL_or_INT  || A.type == OLD_HYPERMAT )
    {
        /* do the job by the %x_i_hm macro family */
        Fin = -Fin;
        return 0;
    }

    if ( ! get_hmat(Rhs - 1, &B) ) /* B is not an hypermat => try if it is a matrix */
        if ( ! get_mat_as_hmat(Rhs - 1, &B) ) /* it is not a matrix of type 1, 4 or 8 */
        {
            /* it stays some authorized possibilities like A(....) = B with B a polynomial
                 * matrix and A a real hypermatrix => try the %x_i_hm macro family
                 */
            Fin = -Fin;
            return 0;
        }


    if ( A.type !=  B.type || A.it != B.it || B.size == 0  || A.dimsize <  nb_index_vectors )
    {
        /*  do the job by the %x_i_hm macro family */
        Fin = -Fin;
        return 0;
    }

    if ( B.size == 1 )
    {
        B_is_scalar = 1;
    }
    else
    {
        B_is_scalar = 0;
    }


    if ( A.dimsize > nb_index_vectors )
    {
        ReshapeHMat(Rhs + 1, &A, nb_index_vectors);
        dec = Rhs + 1;
    }
    else
    {
        dec = Rhs;
    }


    /* get the index vectors */
    ntot = 1;
    iconf = 0;
    for ( i = 1 ; i <= nb_index_vectors ; i++ )
    {
        if (! create_index_vector(i, dec + i, &mn, A.dims[i - 1], &ind_max))
        {
            return 0;
        }
        if ( mn == 0 )   /* the i th index vector is [] */
        {
            if ( B_is_scalar )
                /* nothing append (strange but reproduces the Matlab behavior) */
            {
                goto the_end;
            }
            else   /* B have at least 2 elts */
            {
                Scierror(999, _("%s: Bad hypermatrix insertion.\n"), "hmops");
                return 0;
            }
        }
        else if ( ind_max > A.dims[i - 1] )
        {
            /* we have to enlarge the hypermat : do the job by the %x_i_hm macro family */
            Fin = -Fin;
            return 0;
        }
        else if ( !B_is_scalar  &&  mn != 1 )  /* do the conformity test */
        {
            while ( iconf < B.dimsize  &&  B.dims[iconf] == 1 )
            {
                iconf++;
            }
            if ( iconf >= B.dimsize  ||  B.dims[iconf] != mn )
            {
                Scierror(999, _("%s: Bad hypermatrix insertion.\n"), "hmops");
                return 0;
            }
            iconf++;
        }
        ntot *= mn;
    }
    /* to finish the conformity test */
    if ( !B_is_scalar &&  ntot != B.size )
    {
        Scierror(999, _("%s: Bad hypermatrix insertion.\n"), "hmops");
        return 0;
    }

    /* indices computing */
    ltot = 4;
    CreateVar(dec + Rhs - 1, MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE, &ntot, &one, &ltot);
    j = istk(ltot);
    compute_indices(dec, nb_index_vectors, A.dims, j);


    /*   modify in place the hypermatrix A  */
    switch ( A.type )
    {
        case (sci_matrix) :
            if ( B_is_scalar )
            {
                for ( k = 0 ; k < ntot ; k++ )
                {
                    A.R[j[k]] = B.R[0];
                }
                if (A.it == 1)
                    for ( k = 0 ; k < ntot ; k++ )
                    {
                        A.I[j[k]] = B.I[0];
                    }
            }
            else
            {
                for ( k = 0 ; k < ntot ; k++ )
                {
                    A.R[j[k]] = B.R[k];
                }
                if (A.it == 1)
                    for ( k = 0 ; k < ntot ; k++ )
                    {
                        A.I[j[k]] = B.I[k];
                    }
            }
            break;

        case (sci_boolean) :
            PA = (int *) A.P ;
            PB = (int *) B.P;
            if ( B_is_scalar )
                for ( k = 0 ; k < ntot ; k++ )
                {
                    PA[j[k]] = PB[0];
                }
            else
                for ( k = 0 ; k < ntot ; k++ )
                {
                    PA[j[k]] = PB[k];
                }
            break;

        case (sci_ints) :
            if ( A.it == I_INT32  ||  A.it == I_UINT32 )
            {
                PA = (int *) A.P ;
                PB = (int *) B.P;
                if ( B_is_scalar )
                    for ( k = 0 ; k < ntot ; k++ )
                    {
                        PA[j[k]] = PB[0];
                    }
                else
                    for ( k = 0 ; k < ntot ; k++ )
                    {
                        PA[j[k]] = PB[k];
                    }
            }
            else if ( A.it == I_INT16  ||  A.it == I_UINT16 )
            {
                siPA = (short int *) A.P;
                siPB = (short int *) B.P;
                if ( B_is_scalar )
                    for ( k = 0 ; k < ntot ; k++ )
                    {
                        siPA[j[k]] = siPB[0];
                    }
                else
                    for ( k = 0 ; k < ntot ; k++ )
                    {
                        siPA[j[k]] = siPB[k];
                    }
            }
            else   /* 1 Byte int */
            {
                cPA = (char *) A.P;
                cPB = (char *) B.P;
                if ( B_is_scalar )
                    for ( k = 0 ; k < ntot ; k++ )
                    {
                        cPA[j[k]] = cPB[0];
                    }
                else
                    for ( k = 0 ; k < ntot ; k++ )
                    {
                        cPA[j[k]] = cPB[k];
                    }
            }
            break;
    }

    /*
     *  ici j'essaie de faire le boulot de putlhsvar
     *  le code se base sur  setref (SCI/system/createref.f)
     *  on met une variable speciale "en Top" (le nouveau
     *  Top = Top-Rhs+1) qui indique en fait que l'on a
     *  modifi� "en place" la variable topk.
     *  Les instructions  LhsVar(1) = 0; et Nbvars = 0;
     *  permettent a priori de sortir "convenablement"
     *  de putlhsvar.
     */
the_end:
    il = iadr(*Lstk(Top));
    topk = *istk(il + 2);
    Top = Top - Rhs + 1;
    ilp = iadr(*Lstk(Top));
    *istk(ilp) = -1;
    *istk(ilp + 1) = -1;
    *istk(ilp + 2) = topk;
    if ( topk > 0 )
    {
        *istk(ilp + 3) = *Lstk(topk + 1) - *Lstk(topk);
    }
    else
    {
        *istk(ilp + 3) = 0;
    }
    *Lstk(Top + 1) = sadr(ilp + 4);

    LhsVar(1) = 0;
    Nbvars = 0;

    return 0;
}
Exemplo n.º 10
0
int C2F(intehm)()
{
    /*
     *  Extraction routine for an hypermatrix of type REAL_OR_COMPLEX, BOOLEAN
     *  and INTEGER (the 6 types of scilab ints)
     *
     *    He = ehm ( v_1, v_2, ..., v_nb_iv, H )
     *
     */
    HyperMat H, He;
    int dec, i, k, l, m, n, mn, ntot, ind_max;
    int *j, ier, one = 1, zero = 0, ltot, nb_index_vectors, final_dimsize, lr, lc;
    int *P, *Pe;
    short int *siP, *siPe;
    char  *cP, *cPe;

    /*   CheckLhs(minlhs,maxlhs); */

    if ( Rhs < 2 )
    {
        Scierror(999, _("%s: Wrong number of input arguments: at least %d expected.\n"), "hmops", 2);
        return(0);
    };

    if ( ! get_hmat(Rhs, &H) )
    {
        Scierror(999, _("%s: Wrong type for input argument(s): An hypermatrix expected.\n"), "hmops");
        return 0;
    }
    else if ( H.type == NOT_REAL_or_CMPLX_or_BOOL_or_INT  || H.type == OLD_HYPERMAT )
    {
        /*  do the extraction with the macro %hm_e  */
        Fin = -Fin;
        return 0;
    }

    nb_index_vectors = Rhs - 1;
    if ( H.dimsize <  nb_index_vectors )
    {
        Scierror(999, _("%s: Wrong number of input arguments: at most %d expected.\n"), "hmops", H.dimsize);
        return 0;
    }
    else if ( H.dimsize > nb_index_vectors )  /* reshape H */
    {
        ReshapeHMat(Rhs + 1, &H, nb_index_vectors );
        dec = Rhs + 1;
    }
    else
    {
        dec = Rhs;
    }

    if ( H.size == 0 )   /* the hypermat is empty => return an empty matrix ? */
    {
        CreateVar(dec + 1, MATRIX_OF_DOUBLE_DATATYPE, &zero, &zero, &l);
        LhsVar(1) = dec + 1;
        PutLhsVar();
        return 0;
    }


    ntot = 1;   /* will be the nb of elts of the extracted hmat or mat */
    for ( i = 1 ; i <= nb_index_vectors ; i++ )
    {
        ier = create_index_vector(i, dec + i, &mn, H.dims[i - 1], &ind_max);
        if ( ier == 0  ||  ind_max > H.dims[i - 1] )
        {
            Scierror(999, _("%s: Bad index #%d in hypermatrix extraction. "), "hmops", i);
            return 0;
        }
        if ( mn == 0 )   /* the vector index is [] => we return an empty matrix */
        {
            CreateVar(dec + i + 1, MATRIX_OF_DOUBLE_DATATYPE, &zero, &zero, &l);
            LhsVar(1) = dec + i + 1;
            PutLhsVar();
            return 0;
        }
        ntot *= mn;
    }

    /*  For the Matlab compatibility : an hypermatrix of profil n1 x ... x nj x ... x nk
     *  with  nj > 1 and nj+1 = ... = nk = 1 becomes an hypermatrix of profil n1 x ... x nj
     *  Moreover, in scilab, if nj <= 2, we get in fact a matrix.
     */
    final_dimsize = nb_index_vectors;
    while (final_dimsize > 1 && get_length(dec + final_dimsize) == 1)
    {
        final_dimsize--;
    }
    if ( final_dimsize > 2 )   /* we create an hypermatrix for the extraction result */
    {
        He.dimsize = final_dimsize;
        He.size = ntot;
        He.it = H.it;
        He.type = H.type;
        CreateHMat(dec + Rhs, &He);
        for ( k = 0 ; k < final_dimsize ; k++ )
        {
            He.dims[k] = get_length(dec + k + 1);
        }
    }
    else                /* we create a matrix  for the extraction result */
    {
        m = get_length(dec + 1);
        if (final_dimsize > 1)
        {
            n = get_length(dec + 2);
        }
        else
        {
            n = 1;
        }
        switch (H.type)
        {
            case (sci_matrix):
                CreateCVar(dec + Rhs, MATRIX_OF_DOUBLE_DATATYPE, &(H.it), &m, &n, &lr, &lc);
                He.R = stk(lr);
                if ( H.it == 1 )
                {
                    He.I = stk(lc);
                }
                break;
            case (sci_boolean):
                CreateVar(dec + Rhs, MATRIX_OF_BOOLEAN_DATATYPE, &m, &n, &lr);
                He.P = (void *) istk(lr);
                break;
            case (sci_ints):
                lr = H.it;
                CreateVar(dec + Rhs, MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE, &m, &n, &lr);
                He.P = (void *) istk(lr);
                break;
        }
    }

    /* indices computing */
    ltot = 4;
    CreateVar(dec + Rhs + 1, MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE, &ntot, &one, &ltot);
    j = istk(ltot);
    compute_indices(dec, nb_index_vectors, H.dims, j);

    /*  fill the resulting hypermatrix or matrix  */
    switch ( H.type )
    {
        case (sci_matrix) :
            for ( k = 0 ; k < ntot ; k++ )
            {
                He.R[k] = H.R[j[k]];
            }
            if (H.it == 1)
                for ( k = 0 ; k < ntot ; k++ )
                {
                    He.I[k] = H.I[j[k]];
                }
            break;

        case (sci_boolean) :     /* (sci_boolean stored with 4 bytes) */
            Pe = (int *) He.P ;
            P = (int *) H.P;
            for ( k = 0 ; k < ntot ; k++ )
            {
                Pe[k] = P[j[k]];
            }
            break;

        case (sci_ints) :
            if ( H.it == I_INT32  ||  H.it == I_UINT32 )
            {
                Pe = (int *) He.P;
                P = (int *) H.P;
                for ( k = 0 ; k < ntot ; k++ )
                {
                    Pe[k] = P[j[k]];
                }
            }
            else if ( H.it == I_INT16  ||  H.it == I_UINT16 )
            {
                siPe = (short int *) He.P;
                siP = (short int *) H.P;
                for ( k = 0 ; k < ntot ; k++ )
                {
                    siPe[k] = siP[j[k]];
                }
            }
            else    /* SCI_INT8 and SCI_UINT8 : 1 Byte int */
            {
                cPe = (char *) He.P;
                cP = (char *) H.P;
                for ( k = 0 ; k < ntot ; k++ )
                {
                    cPe[k] = cP[j[k]];
                }
            }
            break;
    }

    LhsVar(1) = dec + Rhs;
    PutLhsVar();
    return 0;
}