本文整理汇总了C++中Hash类的典型用法代码示例。如果您正苦于以下问题:C++ Hash类的具体用法?C++ Hash怎么用?C++ Hash使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Hash类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getHash
static Hash getHash(const char* &ptr)
{
std::string res = getNext(ptr);
Hash h;
if(res != "") h.fromString(res);
return h;
}
示例2: t2
void t2(){
// string key checks
printf("test 1, strings----\n");
Hash h;
Value v,w;
char keys[HCOUNT][32];
char vals[HCOUNT][32];
for(int i=0;i<HCOUNT;i++){
sprintf(keys[i],"foo%x",i*31);
Types::tString->set(&v,keys[i]);
sprintf(vals[i],"bar%d",rand()%100000);
Types::tString->set(&w,vals[i]);
// printf("%s %s\n",keys[i],vals[i]);
h.set(&v,&w);
}
for(int i=0;i<HCOUNT;i++){
Types::tString->set(&v,keys[i]);
if(h.find(&v)){
w.copy(h.getval());
if(w.t != Types::tString)
die("value not an int");
const StringBuffer& buf = w.toString();
if(strcmp(buf.get(),vals[i])){
printf("%s != %s\n",buf.get(),vals[i]);
die("value mismatch");
}
} else
die("key not found");
}
}
示例3: memcpy
Hash Hasher::getResult()
{
Hash result;
result.newData();
memcpy(result.data->hash, this->cryptographicHash.result().constData(), Hash::HASH_SIZE);
return result;
}
示例4: toHash
Attachment::Hash Attachment::toHash(const Attachment::List &list)
{
Hash hash;
foreach (auto attachment, list)
hash.insert(attachment.type(), attachment);
return hash;
}
示例5: size
/* Directly sum an entire stream. The stream is read in increments,
to avoid loading large files into memory. You can specify the
buffer size as the second parameter, the default is 16 Kb.
The algorithm does not depend on size() for non-pointer streams.
Pointer streams are hashed in one go, and do not advance the file
pointer.
Since the position of the file pointer after this operation
depends on the type of stream given, it is considered undefined.
*/
static Hash sum(Mangle::Stream::Stream &str, int bufsize = DEFSIZE)
{
assert(str.isReadable);
// Is this a memory stream?
if(str.hasPtr)
{
assert(str.hasSize);
// Pointer streams makes life easy
return Hash(str.getPtr(), str.size());
}
// No pointers today. Create a buffer and hash in increments.
char *buf = new char[bufsize];
Hash result;
// We do not depend on the stream size, only on eof().
while(!str.eof())
{
size_t num = str.read(buf, bufsize);
// If we read less than expected, we should be at the
// end of the stream
assert(num == bufsize || (num < bufsize && str.eof()));
// Hash the data
result.update(buf, num);
}
// Clean up and return
delete[] buf;
return result.finish();
}
示例6: Hash
Hash* Parser::readHash() {
Tokenizer::TokenType tok = tokenizer->nextToken();
if (tok != Tokenizer::TokenBeginGroup) {
tokenizer->pushBack();
return NULL;
}
Hash* hash = new Hash();
tok = tokenizer->nextToken();
while (tok != Tokenizer::TokenEndGroup) {
if (tok != Tokenizer::TokenName) {
tokenizer->pushBack();
delete hash;
return NULL;
}
string name = tokenizer->getNameValue();
Value* value = readValue();
if (value == NULL) {
delete hash;
return NULL;
}
hash->addValue(name, *value);
tok = tokenizer->nextToken();
}
return hash;
}
示例7: t1
void t1(){
printf("test 1, integers----\n");
int keys[HCOUNT];
int vals[HCOUNT];
Hash h;
Value v,w;
for(int i=0;i<HCOUNT;i++){
keys[i]=i*31;
Types::tInteger->set(&v,keys[i]);
vals[i]=rand()%100000;
Types::tInteger->set(&w,vals[i]);
h.set(&v,&w);
}
for(int i=0;i<HCOUNT;i++){
Types::tInteger->set(&v,keys[i]);
if(h.find(&v)){
w.copy(h.getval());
if(w.t != Types::tInteger)
die("value not an int");
else if(w.toInt() != vals[i]){
printf("%d != %d\n",w.toInt(),vals[i]);
die("value mismatch");
}
} else
die("key not found");
}
}
示例8: main
int main(int argc, char *argv[])
{
string lineBuffer;
ifstream file;
file.open(argv[1]);
int count=0;
Hash strHash;
vector<string> wordArray;
//insert strings into vector
int g=0;
while (!file.eof()){
getline(file, lineBuffer);
string str=new char[lineBuffer.length()]();
if (lineBuffer.length() != 0)
wordArray.push_back(lineBuffer);
}
for(int i=0;i<wordArray.size();i++)
strHash.insert((char*)&wordArray.at(i)[0]);
//sort vector by string length
sort(wordArray.begin(),wordArray.end());
sort(wordArray.begin(),wordArray.end(), stringCompare);
for(int i=0;i<wordArray.size();i++){
//check whether this word is made up of other words
if(buildWord(wordArray.at(i), true, strHash)){
count++;
//only print first 2 longest word made up of other words
if(count<3)
cout<<wordArray.at(i)<<endl;
}
}
//printf how many of the words in the list can be constructed of other words in the list
cout<<"There are "<<count<<" words that can be constructed of other words in the list"<<endl;
return 0;
}
示例9: hashLoc
/**
* A search has been completed. Store the information in the hash.
*
* Currently overwrites existing hash entry regardless of depth.
*/
void HashTable::storeHash(u64 mover, u64 enemy, int alpha, int beta, int score) {
Hash* entry = hashLoc(mover, enemy);
if (entry->mover != mover ||entry->enemy != enemy) {
entry->init(mover, enemy);
}
entry->store(alpha, beta, score);
}
示例10: cs
/* returns false if checksum matched and true if failed */
void
RecordSetInBase::checksum() const
{
int const cs(check_size(check_type_));
if (cs > 0) /* checksum records */
{
Hash check;
check.append (head_ + begin_, size_ - begin_); /* records */
check.append (head_, begin_ - cs); /* header */
assert(cs <= MAX_CHECKSUM_SIZE);
byte_t result[MAX_CHECKSUM_SIZE];
check.gather<sizeof(result)>(result);
const byte_t* const stored_checksum(head_ + begin_ - cs);
if (gu_unlikely(memcmp (result, stored_checksum, cs)))
{
gu_throw_error(EINVAL)
<< "RecordSet checksum does not match:"
<< "\ncomputed: " << gu::Hexdump(result, cs)
<< "\nfound: " << gu::Hexdump(stored_checksum, cs);
}
}
}
示例11: GetDescriptors
QByteArray BulkRound::ProcessMessage(int des_idx, int msg_index)
{
int count = _messages.size();
const Descriptor &des = GetDescriptors()[des_idx];
int length = des.Length();
QByteArray msg(length, 0);
Hash hashalgo;
bool good = true;
for(int idx = 0; idx < count; idx++) {
const char *tmsg = _messages[idx].constData() + msg_index;
QByteArray xor_msg(QByteArray::fromRawData(tmsg, length));
if(des.XorMessageHashes()[idx] != hashalgo.ComputeHash(xor_msg)) {
qWarning() << "Xor message does not hash properly";
_bad_message_hash.append(BadHash(des_idx, idx));
good = false;
}
if(good) {
Xor(msg, msg, xor_msg);
}
}
if(good) {
return msg;
} else {
return QByteArray();
}
}
示例12: xor_message
void BulkRound::CreateDescriptor(const QByteArray &data)
{
int length = data.size();
Hash hashalgo;
QByteArray xor_message(length, 0);
QVector<QByteArray> hashes;
int my_idx = GetGroup().GetIndex(GetLocalId());
foreach(const PublicIdentity &gc, GetGroup().GetRoster()) {
QByteArray seed = _anon_dh.GetSharedSecret(gc.GetDhKey());
if(hashes.size() == my_idx) {
hashes.append(QByteArray());
continue;
}
QByteArray msg(length, 0);
CryptoRandom(seed).GenerateBlock(msg);
hashes.append(hashalgo.ComputeHash(msg));
Xor(xor_message, xor_message, msg);
}
QByteArray my_xor_message = QByteArray(length, 0);
Xor(my_xor_message, xor_message, data);
SetMyXorMessage(my_xor_message);
hashes[my_idx] = hashalgo.ComputeHash(my_xor_message);
QByteArray hash = hashalgo.ComputeHash(data);
Descriptor descriptor(length, _anon_dh.GetPublicComponent(), hashes, hash);
SetMyDescriptor(descriptor);
}
示例13: NAN_METHOD
static
NAN_METHOD(Copy) {
Hash *src = Nan::ObjectWrap::Unwrap<Hash>(info.This());
const unsigned argc = 1;
v8::Local<v8::Value> argv[argc] = { Nan::New<v8::String>("bypass").ToLocalChecked() };
v8::Local<v8::FunctionTemplate> construct = Nan::New<v8::FunctionTemplate>(hash_constructor);
v8::Local<v8::Object> inst = construct->GetFunction()->NewInstance(argc, argv);
// Construction may fail with a JS exception, in which case we just need
// to return.
if(inst.IsEmpty()) {
return;
}
Hash *dest = new Hash();
dest->Wrap(inst);
dest->initialized_ = src->initialized_;
dest->any_blake2_update = src->any_blake2_update;
dest->any_blake2_final = src->any_blake2_final;
dest->outbytes = src->outbytes;
dest->state = src->state;
info.GetReturnValue().Set(inst);
}
示例14: LCA
void LCA(int u, int d)
{
p[u] = u;
dist[u] = d;
int k;
visit[u] = true;
for (k = head[u]; k != 0; k = edge[k].next)
{
if (!visit[edge[k].to])
{
LCA(edge[k].to, d + 1);
p[edge[k].to] = u;
}
}
for (k = qhead[qhead_hash.findHash(id_to_name[u])]; k != 0; k = qedge[k].next)
{
std::vector<int>::iterator j, j_first, j_last;
j_first = name_to_id[surnames.findHash(qedge[k].to)].begin();
j_last = name_to_id[surnames.findHash(qedge[k].to)].end();
for (j = j_first; j != j_last; ++j)
{
if (visit[*j])
{
int lca = find(*j);
int query1 = qmap_hash.findHash(make_pair(id_to_name[u], qedge[k].to));
int query2 = qmap_hash.findHash(make_pair(qedge[k].to, id_to_name[u]));
qmap[query1] = max(qmap[query1], dist[u] + dist[*j] - 2 * dist[lca]);
qmap[query2] = max(qmap[query2], dist[u] + dist[*j] - 2 * dist[lca]);
}
}
}
}
示例15: Parametros
void Servicios::agregarAlHash(string nombreHash, string clavePasada, unsigned int idNueva)
{
string pathHash = Parametros().getParametro(CARPETA_DATOS);
pathHash += nombreHash;
Hash *hash = new Hash(pathHash);
Registro* registro= hash->buscar(clavePasada);
unsigned int offset;
//si ya existe la lista//
if (registro){
//cout << "lista ya existente" << endl;
offset = registro->getAtributosEnteros()->front();
ListasIds().agregarIdDeLibro(&offset,idNueva,false);
}
//no existe la lista de ids
else{
//cout << "lista nueva" << endl;
ListasIds().agregarIdDeLibro(&offset, idNueva,true);
registro = new Registro();
registro->setString(clavePasada);
registro->agregarAtribEntero(offset);
hash->insertar(registro);
}
delete registro;
delete hash;
}