/* Insert a row into the full-text index; set *piRowid to be the ID of the * new row. */ static int index_insert(fulltext_vtab *v, sqlite3_value *pRequestRowid, const char *zText, sqlite_int64 *piRowid){ Hash terms; /* maps term string -> PosList */ HashElem *e; int rc = content_insert(v, pRequestRowid, zText, -1); if( rc!=SQLITE_OK ) return rc; *piRowid = sqlite3_last_insert_rowid(v->db); if( !zText ) return SQLITE_OK; /* nothing to index */ rc = build_terms(&terms, v->pTokenizer, zText, *piRowid); if( rc!=SQLITE_OK ) return rc; for(e=HashFirst(&terms); e; e=HashNext(e)){ DocList *p = HashData(e); rc = index_insert_term(v, HashKey(e), HashKeysize(e), *piRowid, p); if( rc!=SQLITE_OK ) break; } for(e=HashFirst(&terms); e; e=HashNext(e)){ DocList *p = HashData(e); docListDelete(p); } HashClear(&terms); return rc; }
/*! お気に入りリストから削除する @param[in] pcConts AAの文字列 @param[in] rdLength バイト数 @return HRESULT 終了状態コード */ HRESULT AaItemsFavDelete( LPSTR pcConts, UINT rdLength ) { LPTSTR ptBaseName; DWORD dHash; ptBaseName = TreeBaseNameGet( ); // 一覧ベース名取得して // そのAAのハッシュ値を求めて HashData( (LPBYTE)pcConts, rdLength, (LPBYTE)(&(dHash)), 4 ); // お気に入りから削除する SqlFavDelete( ptBaseName, dHash ); return S_OK; }
/* main encoder */ void Encode (void) { unsigned int dictpos, deleteflag, sectorlen; unsigned long bytescompressed; InitEncode(); dictpos = deleteflag = 0; bytescompressed = 0; while (1) { /* delete old data from dictionary */ if (deleteflag) DeleteData(dictpos); /* grab more data to compress */ if ((sectorlen = LoadDict(dictpos)) == 0) break; /* hash the data */ HashData(dictpos, sectorlen); /* find dictionary matches */ DictSearch(dictpos, sectorlen); bytescompressed += sectorlen; printf("\r%ld", bytescompressed); dictpos += SECTORLEN; /* wrap back to beginning of dictionary when its full */ if (dictpos == DICTSIZE) { dictpos = 0; deleteflag = 1; /* ok to delete now */ } } /* Send EOF flag */ SendMatch(MAXMATCH + 1, 0); /* Flush bit buffer */ if (bitsin) SendBits(0, 8 - bitsin); return; }
/*! 使ったAAをお気に入りSQLにいれる @param[in] pcConts AAの文字列 @param[in] rdLength バイト数 @return HRESULT 終了状態コード */ HRESULT AaItemsFavUpload( LPSTR pcConts, UINT rdLength ) { LPTSTR ptBaseName; DWORD dHash; ptBaseName = TreeBaseNameGet( ); // 一覧ベース名取得して // ドロッピンオブジェクトなら無視するので? if( !( StrCmp( DROP_OBJ_NAME, ptBaseName ) ) ) return E_ABORT; // そのAAのハッシュ値を求めて HashData( (LPBYTE)pcConts, rdLength, (LPBYTE)(&(dHash)), 4 ); // お気に入りに記録する SqlFavUpload( ptBaseName, dHash, pcConts, rdLength ); return S_OK; }
HashResult BCryptHashImpl::Calculate(const ByteBuffer& toHash, const ByteBuffer& secret) { if(!IsValid()) { return HashResult(); } std::lock_guard<std::mutex> locker(m_algorithmMutex); BCryptHashContext context(m_algorithmHandle, m_hashObject, m_hashObjectLength, secret); if (!context.IsValid()) { AWS_LOG_ERROR(BCRYPT_LOG_TAG, "Error creating hash handle."); return HashResult(); } return HashData(context, static_cast<PBYTE>(toHash.GetUnderlyingData()), static_cast<ULONG>(toHash.GetLength())); }
HashResult BCryptHashImpl::Calculate(const Aws::String& str) { if(!IsValid()) { return HashResult(); } std::lock_guard<std::mutex> locker(m_algorithmMutex); BCryptHashContext context(m_algorithmHandle, m_hashObject, m_hashObjectLength); if (!context.IsValid()) { AWS_LOG_ERROR(BCRYPT_LOG_TAG, "Error creating hash handle."); return HashResult(); } return HashData(context, (PBYTE)str.c_str(), static_cast<ULONG>(str.length())); }
/* Delete a row from the full-text index. */ static int index_delete(fulltext_vtab *v, sqlite_int64 iRow){ char *zText; Hash terms; HashElem *e; int rc = content_select(v, iRow, &zText); if( rc!=SQLITE_OK ) return rc; rc = build_terms(&terms, v->pTokenizer, zText, iRow); free(zText); if( rc!=SQLITE_OK ) return rc; for(e=HashFirst(&terms); e; e=HashNext(e)){ rc = index_delete_term(v, HashKey(e), HashKeysize(e), iRow); if( rc!=SQLITE_OK ) break; } for(e=HashFirst(&terms); e; e=HashNext(e)){ DocList *p = HashData(e); docListDelete(p); } HashClear(&terms); return content_delete(v, iRow); }
void Authentication_GetKeyHash( char *_sourceKey, char *_destKey, int _hashToken ) { HashData( _sourceKey, _hashToken, _destKey ); }
int main( int argc, char** argv ) { const char* in; uint32_t hashCheck = 1; uint64_t hashValue, hashValue2; uint32_t compressedSize, uncompressedSize; uint8_t* uncompressed; uint8_t* workMem; uint8_t* compressed; if( argc < 2 ) { printf( "Usage: wflz input_file" ); return 0; } in = argv[1]; printf( "\nwfLZ[%s]\n", in ); { FILE* fh = fopen( in, "rb" ); if( fh == NULL ) { printf( "Error: Could not read input file '%s'.\n", in ); return 0; } fseek( fh, 0, SEEK_END ); uncompressedSize = (uint32_t)ftell( fh ); uncompressed = (uint8_t*)Malloc( uncompressedSize ); if( uncompressed == NULL ) { fclose( fh ); printf( "Error: Allocation failed.\n" ); return 0; } fseek( fh, 0, SEEK_SET ); if( fread( uncompressed, 1, uncompressedSize, fh ) != uncompressedSize ) { fclose( fh ); printf( "Error: File read failed.\n" ); return 0; } fclose( fh ); } workMem = (uint8_t*)Malloc( wfLZ_GetWorkMemSize() ); if( workMem == NULL ) { printf( "Error: Allocation failed.\n" ); return 0; } compressed = (uint8_t*)Malloc( wfLZ_GetMaxCompressedSize( uncompressedSize ) ); hashValue = hashCheck ? HashData( uncompressed, uncompressedSize ) : 0 ; //#define CAPTURING_PROFILE #ifdef CAPTURING_PROFILE { uint32_t i; for( i = 0; i != 10000; ++i ) { #endif compressedSize = wfLZ_CompressFast( uncompressed, uncompressedSize, compressed, workMem, 0 ); if( hashCheck ) { memset( uncompressed, 0, uncompressedSize ); } wfLZ_Decompress( compressed, uncompressed ); #ifdef CAPTURING_PROFILE } } #endif free( workMem ); free( compressed ); hashValue2 = hashCheck ? HashData( uncompressed, uncompressedSize ) : 0 ; free( uncompressed ); printf( "Compression Ratio: %.2f\n", ((float)compressedSize)/((float)uncompressedSize) ); if( hashCheck && hashValue != hashValue2 ) { printf( "Error: Hash check mismatch!\n" ); return -1; } return 0; }