Example #1
0
IStream* FileStorage::WriteFileHelper(FileEntry& file, FileOpenMode openMode /*= FileOpenMode::ReadOnly*/, FileDataType dataType /*= FileDataType::Binary*/)
{
	IStream* resultStream = OnWriteFile(file, openMode, dataType);;

	const CoderChain* coderChain = GetFileCoderChain(file);
	if (coderChain != nullptr)
	{
		if (IsWholeFileCoding())
		{
			resultStream = new FileCodeWriteStream(*resultStream, *coderChain, file);
		}
		else
		{
			resultStream = new BlockCodeWriteStream(*resultStream, BlockSize(), *coderChain, file);
		}
	}

	if (Hasher() != HasherType::None)
	{
		resultStream = new HashStream(*resultStream, Hasher(), [&file](StringRef result) {file.SetSignature(result); });

	}

	return resultStream;
}
void TestVector(const Hasher &h, const In &in, const Out &out) {
    Out hash;
    BOOST_CHECK(out.size() == h.OUTPUT_SIZE);
    hash.resize(out.size());
    {
        // Test that writing the whole input string at once works.
        Hasher(h).Write((unsigned char*)&in[0], in.size()).Finalize(&hash[0]);
        BOOST_CHECK(hash == out);
    }
    for (int i=0; i<32; i++) {
        // Test that writing the string broken up in random pieces works.
        Hasher hasher(h);
        size_t pos = 0;
        while (pos < in.size()) {
            size_t len = insecure_rand() % ((in.size() - pos + 1) / 2 + 1);
            hasher.Write((unsigned char*)&in[pos], len);
            pos += len;
            if (pos > 0 && pos + 2 * out.size() > in.size() && pos < in.size()) {
                // Test that writing the rest at once to a copy of a hasher works.
                Hasher(hasher).Write((unsigned char*)&in[pos], in.size() - pos).Finalize(&hash[0]);
                BOOST_CHECK(hash == out);
            }
        }
        hasher.Finalize(&hash[0]);
        BOOST_CHECK(hash == out);
    }
}
            const PatternListType* LookupPatterns(const CharType* const FormatStart, const SizeType Length, SizeType HashKey = 0)
            {
                if (0 == HashKey)
                {
                    HashKey = Hasher(FormatStart, Length);
                }

                // First, Find in the cache
                {
                    ScopedLockerType Locker(CriticalSectionValue);

                    const PatternListType* PatternList = TPolicy::FindByHashKey(Storage, HashKey);

                    if (NULL != PatternList)
                    {
                        return PatternList;
                    }
                }

                PatternListType Patterns;
                TPolicy::ReserveList(Patterns, 8);

                if (Parser(FormatStart, Length, Patterns))
                {
                    ScopedLockerType Locker(CriticalSectionValue);

                    return TPolicy::Emplace(Storage, HashKey, FL_MOVE_SEMANTIC(Patterns));
                }

                assert(false && "invalid format expression!");

                throw ExceptionType("invalid format expression!");

                return NULL;
            }
Example #4
0
void IdbOrderBy::initialize(const RowGroup& rg)
{
	// initialize rows
	IdbCompare::initialize(rg);

	uint64_t newSize = fRowsPerRG * rg.getRowSize();
	if (!fRm->getMemory(newSize))
	{
		cerr << IDBErrorInfo::instance()->errorMsg(fErrorCode)
			 << " @" << __FILE__ << ":" << __LINE__;
		throw IDBExcept(fErrorCode);
	}
	fMemSize += newSize;
	fData.reinit(fRowGroup, fRowsPerRG);
	fRowGroup.setData(&fData);
	fRowGroup.resetRowGroup(0);
	fRowGroup.initRow(&fRow0);
	fRowGroup.getRow(0, &fRow0);

	// set compare functors
	fRule.compileRules(fOrderByCond, fRowGroup);

	fRowGroup.initRow(&row1);
	fRowGroup.initRow(&row2);
	if (fDistinct)
	{
		fDistinctMap.reset(new DistinctMap_t(10, Hasher(this, getKeyLength()), Eq(this, getKeyLength())));
	}
}
Example #5
0
File: hashmap.cpp Project: kayw/mnb
HashMap<Key, T, Hasher, EqualKey, Alloc>::HashMap(size_type n=default_bucket_num,
                const Hasher& hf=Hasher(),
                const EqualKey& eq=EqualKey())
    :bucket_list_(nullptr)
    ,bucket_count_(0)
    ,size_(0)
    ,mlf_(1.0f)
    ,hash_function_pred_(hf, eq){
    rehash(n);
  }
Example #6
0
		// Constructor
		// Pre-condition: type ('g' or 'b') and crp ('d' or 'q') is provided
		//                filename is the location of a file that comply with the desired format
		// Post-condition: An hash-table with type and crp of size 100 and as many TableEntry
		//                 inserted as possible;
    Hasher(char type, char crp, char* filename)  
    {
			Hasher(type, crp);

			std::ifstream infile(filename);
			std::string line;

			while (getline(infile, line))
			{
				std::string key = line.substr(0, 8);
				std::string num = line.substr(8, line.size());
				int value = atoi(num.c_str());
				insert(key, value);
				if (is_full) break;   // stop insertion if table is full
			}
		}
Example #7
0
MOVELIST *GenerateMoves (POSITION position)
{
	MOVELIST *moves = NULL;
	int i, j, k, di, dj;
	char board[BOARD_SIZE];
	int player = generic_hash_turn(position);
	BOOLEAN canProcessDir = FALSE;

	generic_hash_unhash (position, board);
	/* Use CreateMovelistNode(move, next) to 'cons' together a linked list */
	for (i = 0; i < BOARD_ROWS; i++) {
		for (j = 0; j < BOARD_COLS; j++) {
			if (((player==1) && (board[Index(i,j)] == PLAYER1_PIECE)) ||
			    ((player==2) && (board[Index(i,j)] == PLAYER2_PIECE)))
			{
				for (k = 0; k < NUM_OF_DIRS; k++) {
					// for every possible movement as specified in dir_increments
					// except 5 and the diagonals when !CAN_MOVE_DIAGONALLY
					if (k == 4)
						canProcessDir = FALSE;
					else if ((k == 0) || (k == 2) || (k == 6) || (k == 8))
						canProcessDir = CAN_MOVE_DIAGONALLY;
					else
						canProcessDir = TRUE;
					if (canProcessDir) {
						di = i + dir_increments[k][0];
						dj = j + dir_increments[k][1];
						if ((di >= 0) && (dj >= 0) &&
						    (di < BOARD_ROWS) && (dj < BOARD_COLS) &&
						    (board[Index(di,dj)] == EMPTY_PIECE)) {
							moves = CreateMovelistNode(Hasher(i,j,k),moves);
						}
					}
				}
			}
		}
	}
	return moves;
}
Example #8
0
 inline unsigned Hash<face>::operator()(const face& t, unsigned seed) const
 {
     return Hasher(t.cdata(),t.size()*sizeof(label), seed);
 }
Example #9
0
		// Constructor
		// Pre-condition: type ('g' or 'b') and crp ('d' or 'q') and loadFactor is provided
		//                filename is the location of a file that comply with the desired format
		// Post-condition: An hash-table with type and crp of size determined by capacity
		//                 and as many TableEntry inserted as possible;
    Hasher(char type, char crp, double loadFactor, std::string filename)  
    {
			Hasher(type, crp, loadFactor, filename.c_str());
		}
Example #10
0
 // Concatenation
 friend Hasher operator+(const Hasher &a, const Hasher &b) { return Hasher((1LL * a.h * getPow(b.sz) + b.h) % MOD, a.sz + b.sz); }