RawSection::RawSection(PebilClassTypes classType, char* rawPtr, uint32_t size, uint16_t scnIdx, ElfFile* elf)
    : Base(classType),rawDataPtr(rawPtr),sectionIndex(scnIdx),elfFile(elf)
{ 
    sizeInBytes = size; 

    hashCode = HashCode((uint32_t)sectionIndex);
    PRINT_DEBUG_HASHCODE("Section %d Hashcode: 0x%04llx", (uint32_t)sectionIndex, hashCode.getValue());

    verify();
}
Beispiel #2
0
std::size_t
Expression::HashCode(std::vector<Expression::Pointer>& array)
{
  if (array.size() == 0) {
    return 0;
  }
  std::size_t hashCode = Poco::hash("std::vector<Expression::Pointer>");
  for (unsigned int i= 0; i < array.size(); i++) {
    hashCode = hashCode * HASH_FACTOR + HashCode(array[i]);
  }
  return hashCode;
}
Beispiel #3
0
uint
Expression::HashCode(const QList<Expression::Pointer>& array)
{
  if (array.size() == 0)
  {
    return 0;
  }
  uint hashCode = qHash("QList<Expression::Pointer>");
  for (int i= 0; i < array.size(); i++)
  {
    hashCode = hashCode * HASH_FACTOR + HashCode(array[i]);
  }
  return hashCode;
}
Beispiel #4
0
int HashAdd(Hash *hash, char *key, char *value) {
    int code;
    code = HashCode(hash, key);

    if(hash->table[code].state == EMPTY) {
        strcpy(hash->table[code].key, key);
        strcpy(hash->table[code].value, value);
        hash->table[code].state = FULL;
        return(TRUE);
    }
    else{
        return(FALSE);
    }

}
Beispiel #5
0
int HashDelete(Hash *hash, char *key) {
    int code = HashCode(hash,key);
    if(hash->table[code].state == 0){
        return(FALSE);
    }
    else {
        int i = 0;
        while(hash->table[code].key[i] != NULL || hash->table[code].value[i]!= NULL){
            hash->table[code].key[i] = '\0'; 
            hash->table[code].value[i] = '\0';
            i++;
        }
        hash->table[code].state = 0;
        return(TRUE);
    }
}
void HashTableInsert ( HashTable & _ht, int _key, int _value )
{
    if ( ( _ht.m_numOccupied << 1 ) >= _ht.m_tableSize )
        HashTableDoubleSize( _ht );

    unsigned int hashCode = HashCode( _key );
    int bucketNr = hashCode % _ht.m_tableSize;

    for ( int i = bucketNr; i < _ht.m_tableSize; i++ )
        if ( HashTableTryInsertElement( _ht, i, _key, _value ) )
            return;

    for ( int i = 0; i < bucketNr; i++ )
        if ( HashTableTryInsertElement( _ht, i, _key, _value ) )
            return;
}
Beispiel #7
0
// Функция хеширования данных
void CDHash::Hash(char *prgbSourceData, int sourceLen)
{
    int cRounds;

    iSubkey = 0;
	nTry1 = 0;
	nTry2 = 0;
	
	// Переносим исходные данные в массив int (он и будет хешироваться)
	for (int i = 0; i < sourceLen; i++)
	{
		prgSourceData[i] = (unsigned char)prgbSourceData[i];
	}

	// Инициализируем структуру, содержащую массив контрольных сумм
	// и входящую в объединение Subkey
	InitSubkey();

	// Подготовка исх.данн.: циклическое копирование его в prgHash
  	PrepareSourceData(sourceLen);
          
	// Хеширование блока исходных данных
	for (cRounds = 0; cRounds < hashGammaLen; cRounds++)	
	{     
		// Вычисление подключа
		CalculateSubkey();

		// Кодирование хеш-гаммы XOR-подобной операцией
		HashCode();

		// Наложение гаммы подключа
		ImposeSubkeyGamma();        

		// Обновляем прогресс
		if (UpdateProgress != NULL)
		{
			UpdateProgress(cRounds);
		}
	}

	// Записываем результат в "целевой" массив
	for (int i = 0; i < hashGammaLen; i++)
	{
		prgbSourceData[i] = (char)prgHash[i];
	}
}
Beispiel #8
0
// Get the def location of a given variable.
RangeCheck::Location* RangeCheck::GetDef(unsigned lclNum, unsigned ssaNum)
{
    Location* loc = nullptr;
    if (ssaNum == SsaConfig::RESERVED_SSA_NUM)
    {
        return nullptr;
    }
    if (!m_fMappedDefs)
    {
        MapMethodDefs();
    }
    // No defs.
    if (m_pDefTable == nullptr)
    {
        return nullptr;
    }
    m_pDefTable->Lookup(HashCode(lclNum, ssaNum), &loc);
    return loc;
}
int HashTableGet ( const HashTable & _ht, int _key )
{
    unsigned int hashCode = HashCode( _key );
    int bucketNr = hashCode % _ht.m_tableSize;

    for ( int i = bucketNr; i < _ht.m_tableSize; i++ )
        if ( _ht.m_pData[ i ].m_status == HashTable::Element::NOT_OCCUPIED )
            break;
        else if ( _ht.m_pData[ i ].m_status == HashTable::Element::OCCUPIED &&
                  _ht.m_pData[ i ].m_key == _key )
            return _ht.m_pData[ i ].m_value;

    for ( int i = 0; i < bucketNr; i++ )
        if ( _ht.m_pData[ i ].m_status == HashTable::Element::NOT_OCCUPIED )
            break;
        else if ( _ht.m_pData[ i ].m_status == HashTable::Element::OCCUPIED &&
                  _ht.m_pData[ i ].m_key == _key )
            return _ht.m_pData[ i ].m_value;

    return -1;
}
void HashTableRemoveKey ( HashTable & _ht, int _key )
{
    unsigned int hashCode = HashCode( _key );
    int bucketNr = hashCode % _ht.m_tableSize;

    for ( int i = bucketNr; i < _ht.m_tableSize; i++ )
        if ( _ht.m_pData[ i ].m_key == _key )
        {
            _ht.m_pData[ i ].m_status = HashTable::Element::DELETED;
            --_ht.m_numOccupied;
            return;
        }

    for ( int i = 0; i < bucketNr; i++ )
        if ( _ht.m_pData[ i ].m_key == _key )
        {
            _ht.m_pData[ i ].m_status = HashTable::Element::DELETED;
            --_ht.m_numOccupied;
            return;
        }

    assert( !"key not found" );
}
Beispiel #11
0
int HashGet(Hash *hash, char *key, char *value) {
    int code;
    code = HashCode(hash, key);
    return(TRUE);
}
Beispiel #12
0
int main(void) {
    int size = 0, h;
    char cmd, key[1024], value[1024], buf[1024];
    Hash *hash;

    // ハッシュテーブルの生成
                 
    printf("ハッシュテーブルの大きさを入力して下さい: ");
    scanf("%d", &size);
    
    if (size < 1) return -1;// 入力数エラー
    hash = HashAlloc(size);
    if (hash == NULL) return -1;    // メモリ確保失敗

    puts("* ハッシュテーブルを操作するコマンドを入力して下さい.");
    puts("* データを格納:a");
    puts("* キーを削除:x");
    puts("* キーに対応するデータの取得:g");
    puts("* ハッシュテーブルを表示:d");
    puts("* ハッシュ値の表示:h");
    puts("* ハッシュテーブルをクリア:c");
    puts("* 終了:q");
                                
    do {
        printf(": ");
        scanf("%s", buf);
        cmd = buf[0];

        switch (cmd) {
            case 'a':   /* データを格納 */
                printf("名前を入力して下さい:");
                scanf("%s", key);
                printf("血液型を入力して下さい:");
                scanf("%s", value);

                if (HashAdd(hash, key, value) == TRUE) {  // hash, name, blood-type
                    printf("%s=%sを格納しました.\n", key, value);
                } else {    /* 衝突 */
                    printf("既に同じキーを持つデータが存在します.\n");
                }
                break;
            case 'd':   /* データを表示 */
                HashDump(hash);
                break;
            case 'c':   /* ハッシュテーブルをクリア */
                HashClear(hash);
                break;
            case 'x':   /* キーを削除 */
                printf("誰を削除しますか?:");
                scanf("%s", key);
                if(HashDelete(hash, key) == TRUE) {
                    printf("%sを削除しました.\n", key);
                }
                else {
                    printf("%sは登録されていません.\n", key);
                }
                break;
            case 'g':   /* キーに対応するデータを取得 */
                printf("名前を入力して下さい:");
                scanf("%s", key);
                if (HashGet(hash, key, value) == TRUE) {
                    printf("%sの血液型は%sです.\n", key, value);
                } else {
                    printf("%sは登録されていません.\n", key);
                }
                break;
            case 'h':   /* キーに対応するデータを取得 */
                printf("名前を入力して下さい:");
                scanf("%s", key);
                h = HashCode(hash, key);
                printf("%sのハッシュ値は%dです.", key, h);
                break;
            case 'q':   /* 終了 */
                puts("プログラムを終了します.");
                break;
            case '\n':  /* 改行 */
            case '\r':  /* 復帰 */
                break;
            default:    /* 入力エラー */
                puts("コマンドが正しくありません.");
                break;
        }
    } while (cmd != 'q');

    HashDump(hash); // 解放前の出力
    HashFree(hash); // メモリ解放

    return 0;
}
Beispiel #13
0
size_t Tuple::HashCode() const {
  size_t seed = 0;
  return HashCode(seed);
}