本文整理汇总了C++中Hash::add方法的典型用法代码示例。如果您正苦于以下问题:C++ Hash::add方法的具体用法?C++ Hash::add怎么用?C++ Hash::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hash
的用法示例。
在下文中一共展示了Hash::add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: check
inline bool check(int m, std::string& a, std::string& b)
{
std::set<Hash> s;
Hash hash;
for (int i = 0; i < m; ++i)
hash.add(a[i]);
s.insert(hash);
for (unsigned i = m, len = a.size(); i < len; ++i) {
hash.rem(a[i - m], m - 1);
hash.add(a[i]);
s.insert(hash);
}
hash = Hash();
for (int i = 0; i < m; ++i) {
hash.add(b[i]);
}
if (s.find(hash) != s.end()) {
return true;
}
for (unsigned i = m, len = b.size(); i < len; ++i) {
hash.rem(b[i - m], m - 1);
hash.add(b[i]);
if (s.find(hash) != s.end())
return true;
}
return false;
}
示例2: profilePush
void FW::profilePush(const char* id)
{
if (!s_profileStarted)
return;
if (!Thread::isMain())
fail("profilePush() can only be used in the main thread!");
// Find or create token.
S32 token;
S32* found = s_profilePointerToToken.search(id);
if (found)
token = *found;
else
{
found = s_profileStringToToken.search(id);
if (found)
token = *found;
else
{
token = s_profileStringToToken.getSize();
s_profileStringToToken.add(id, token);
}
s_profilePointerToToken.add(id, token);
}
// Find or create timer.
Vec2i timerKey(-1, token);
if (s_profileStack.getSize())
timerKey.x = s_profileStack.getLast();
S32 timerIdx;
found = s_profileTimerHash.search(timerKey);
if (found)
timerIdx = *found;
else
{
timerIdx = s_profileTimers.getSize();
s_profileTimerHash.add(timerKey, timerIdx);
ProfileTimer& timer = s_profileTimers.add();
timer.id = id;
timer.parent = timerKey.x;
if (timerKey.x != -1)
s_profileTimers[timerKey.x].children.add(timerIdx);
}
// Push timer.
if (s_profileStack.getSize() == 1)
s_profileTimers[s_profileStack[0]].timer.start();
s_profileStack.add(timerIdx);
if (s_profileStack.getSize() > 1)
s_profileTimers[timerIdx].timer.start();
}
示例3: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
Hash *h = new Hash;
h->init();
printf("Reading from file...\n");
FILE * fd = fopen("FILE.TXT", "r");
char str[100];
while(fscanf(fd, "%s", str) != EOF)
h->add(str);
fclose(fd);
/*printf("Input word which needs to find\n");
scanf("%s", str);
HashList *tmp = h->find(str);
if (tmp)
printf("words count is %d\n", tmp->count);
else
printf("There is no \"%s\"", str);
*/
h->printStats();
delete h;
scanf("%*s");
return 0;
}
示例4: main
int main()
{
cout << "Welcome to this awesome Phone Book\n" << endl;
Hash hash;
int choice;
string name;
string phone;
Node* entry;
do
{
menu();
cin >> choice;
switch (choice)
{
case 1:
getchar();
cout << "Name: ";
getline(cin, name);
cout << "Phone: ";
getline(cin, phone);
entry = new Node();
entry->name = name;
entry->phone = phone;
hash.add(entry);
break;
case 2:
getchar();
cout << "Enter full name: ";
getline(cin, name);
hash.search(name);
break;
case 3:
getchar();
cout << "Name: ";
getline(cin, name);
hash.remove(name);
break;
case 4:
hash.printAll();
break;
case 0:
hash.clearAll();
break;
default:
cout << "Invalid entry. Please try again" << endl;
break;
}
} while (choice != 0);
cout << "Have a good day!" << endl;
return 0;
}
示例5: hashFile
void hashFile(const boost::filesystem::path& path, Hash& algorithm)
{
std::ifstream fileStream(path.generic_string(), std::ios::binary);
if(fileStream.is_open()) {
while(!fileStream.eof()) {
char buffer[4096];
fileStream.read(buffer, 4096);
int bytesRead = fileStream.gcount();
algorithm.add(buffer, bytesRead);
}
}
}
示例6: printMemStats
void FW::printMemStats(void)
{
#if FW_MEM_DEBUG
// Create snapshot of the alloc list.
s_lock.enter();
AllocHeader* first = NULL;
for (AllocHeader* src = s_memAllocs.next; src != &s_memAllocs; src = src->next)
{
AllocHeader* alloc = (AllocHeader*)::malloc(sizeof(AllocHeader));
*alloc = *src;
alloc->next = first;
first = alloc;
}
s_lock.leave();
// Calculate total size per owner.
Hash<String, S64> owners;
for (AllocHeader* alloc = first; alloc;)
{
if (!owners.contains(alloc->ownerID))
owners.add(alloc->ownerID, 0);
owners[alloc->ownerID] += alloc->size;
AllocHeader* next = alloc->next;
::free(alloc);
alloc = next;
}
// Print.
printf("\n");
printf("%-32s%.2f\n", "Memory usage / megs", (F32)s_memoryUsed * exp2(-20));
for (int slot = owners.firstSlot(); slot != -1; slot = owners.nextSlot(slot))
{
const HashEntry<String, S64>& entry = owners.getSlot(slot);
printf(" %-30s%-12.2f%.0f%%\n",
entry.key.getPtr(),
(F32)entry.value * exp2(-20),
(F32)entry.value / (F32)s_memoryUsed * 100.0f);
}
printf("\n");
#endif
}
示例7: downscaleTextures
void App::downscaleTextures(MeshBase* mesh)
{
FW_ASSERT(mesh);
Hash<const Image*, Texture> hash;
for (int submeshIdx = 0; submeshIdx < mesh->numSubmeshes(); submeshIdx++)
for (int textureIdx = 0; textureIdx < MeshBase::TextureType_Max; textureIdx++)
{
Texture& tex = mesh->material(submeshIdx).textures[textureIdx];
if (tex.exists())
{
const Image* orig = tex.getImage();
if (!hash.contains(orig))
{
Image* scaled = orig->downscale2x();
hash.add(orig, (scaled) ? Texture(scaled, tex.getID()) : tex);
}
tex = hash.get(orig);
}
}
}
示例8: pushMemOwner
void FW::pushMemOwner(const char* id)
{
#if !FW_MEM_DEBUG
FW_UNREF(id);
#else
s_lock.enter();
s_memPushingOwner = true;
U32 threadID = Thread::getID();
Array<const char*>* stack = s_memOwnerStacks.search(threadID);
if (!stack)
{
stack = &s_memOwnerStacks.add(threadID);
stack->clear();
}
stack->add(id);
s_memPushingOwner = false;
s_lock.leave();
#endif
}
示例9: exportWavefrontMesh
//.........这里部分代码省略.........
stream.writef("f %d/%d/%d %d/%d/%d %d/%d/%d\n",
v.x, v.x, v.x,
v.y, v.y, v.y,
v.z, v.z, v.z);
}
}
// No base name => do not write materials.
if (!baseName.getLength())
return;
// Hash textures and determine file names.
Hash<const Image*, String> texImageHash;
Set<String> texNameSet;
for (int i = 0; i < pnt.numSubmeshes(); i++)
{
const MeshBase::Material& mat = pnt.material(i);
for (int j = 0; j < MeshBase::TextureType_Max; j++)
{
const Texture& tex = mat.textures[j];
if (!tex.exists() || texImageHash.contains(tex.getImage()))
continue;
// Extract name from ID.
String name = tex.getID().getFileName();
int idx = name.indexOf('.');
if (idx != -1)
name = name.substring(0, idx);
// No name => generate one.
if (!name.getLength())
name = sprintf("tex%d", texImageHash.getSize());
// Ensure that the name is unique.
String oldName = name;
for (int k = 0; texNameSet.contains(name); k++)
name = sprintf("%s_%d", oldName.getPtr(), k);
// Append format postfix.
name += ".png";
// Record.
texImageHash.add(tex.getImage(), name);
texNameSet.add(name);
}
}
// Write MTL file.
File mtlFile(dirName + '/' + baseName + ".mtl", File::Create);
BufferedOutputStream mtlOut(mtlFile);
for (int i = 0; i < pnt.numSubmeshes(); i++)
{
if (i)
mtlOut.writef("\n");
const MeshBase::Material& mat = pnt.material(i);
mtlOut.writef("newmtl %d\n", i);
mtlOut.writef("Ka 0 0 0\n");
mtlOut.writef("Kd %g %g %g\n", mat.diffuse.x, mat.diffuse.y, mat.diffuse.z);
mtlOut.writef("d %g\n", mat.diffuse.w);
mtlOut.writef("Ks %g %g %g\n", mat.specular.x, mat.specular.y, mat.specular.z);
mtlOut.writef("Ns %g\n", mat.glossiness);
if (texImageHash.contains(mat.textures[MeshBase::TextureType_Diffuse].getImage()))
mtlOut.writef("map_Kd %s\n", texImageHash[mat.textures[MeshBase::TextureType_Diffuse].getImage()].getPtr());
if (texImageHash.contains(mat.textures[MeshBase::TextureType_Alpha].getImage()))
mtlOut.writef("map_d %s\n", texImageHash[mat.textures[MeshBase::TextureType_Alpha].getImage()].getPtr());
if (texImageHash.contains(mat.textures[MeshBase::TextureType_Displacement].getImage()))
mtlOut.writef("disp -mm %g %g %s\n",
mat.displacementBias / mat.displacementCoef, mat.displacementCoef,
texImageHash[mat.textures[MeshBase::TextureType_Displacement].getImage()].getPtr());
if (texImageHash.contains(mat.textures[MeshBase::TextureType_Normal].getImage()))
mtlOut.writef("bump %s\n", texImageHash[mat.textures[MeshBase::TextureType_Normal].getImage()].getPtr());
if (texImageHash.contains(mat.textures[MeshBase::TextureType_Environment].getImage()))
mtlOut.writef("refl -type sphere %s\n", texImageHash[mat.textures[MeshBase::TextureType_Environment].getImage()].getPtr());
}
mtlOut.flush();
// Write textures.
for (int i = texImageHash.firstSlot(); i != -1; i = texImageHash.nextSlot(i))
{
const Image* texImage = texImageHash.getSlot(i).key;
const String& texName = texImageHash.getSlot(i).value;
exportImage(dirName + '/' + texName, texImage);
}
}
示例10: importTiffImage
Image* FW::importTiffImage(InputStream& stream)
{
// Detect endianess and check format.
U8 endianTag = stream.readU8();
Input in(stream, (endianTag == 'I'), 1);
if ((endianTag != 'I' && endianTag != 'M') || in.readU8() != endianTag || in.readU16() != 42)
setError("Not a TIFF file!");
// Read directory header.
U32 dirOfs = in.readU32();
in.seek(dirOfs);
int numEntries = in.readU16();
if (!dirOfs || !numEntries)
setError("Corrupt TIFF directory!");
// Read directory entries.
Hash<U32, Array<U32> > entries;
for (int i = 0; i < numEntries && !hasError(); i++)
{
U16 tag = in.readU16();
U16 type = in.readU16();
U32 count = in.readU32();
U32 ofs = in.readU32();
// Check type and count.
int typeSize;
switch (type)
{
case 1: typeSize = 1; break; // BYTE
case 3: typeSize = 2; break; // SHORT
case 4: typeSize = 4; break; // LONG
default: typeSize = 0; break;
}
if (!typeSize)
continue;
// Seek to the value.
U32 oldOfs = in.tell();
if (typeSize * count <= 4)
in.seek(oldOfs - 4);
else
in.seek(ofs);
// Read value.
Array<U32>& data = entries.add(tag);
data.resize(count);
for (int j = 0; j < (int)count; j++)
{
switch (typeSize)
{
case 1: data[j] = in.readU8(); break;
case 2: data[j] = in.readU16(); break;
case 4: data[j] = in.readU32(); break;
default: FW_ASSERT(false); break;
}
}
in.seek(oldOfs);
}
// Find relevant entries and check their sizes.
const Array<U32>* width = entries.search(256); // ImageWidth
const Array<U32>* height = entries.search(257); // ImageLength
const Array<U32>* numBits = entries.search(258); // BitsPerSample
const Array<U32>* compression = entries.search(259); // Compression
const Array<U32>* photometric = entries.search(262); // PhotometricInterpretation
const Array<U32>* stripOfs = entries.search(273); // StripOffsets
const Array<U32>* numChannels = entries.search(277); // SamplesPerPixel
const Array<U32>* stripBytes = entries.search(279); // StripByteCounts
const Array<U32>* predictor = entries.search(317); // Predictor
const Array<U32>* extraSamples = entries.search(338); // ExtraSamples
const Array<U32>* sampleFormat = entries.search(339); // SampleFormat
if (!width || width->getSize() != 1 ||
!height || height->getSize() != 1 ||
!numBits || numBits->getSize() == 0 ||
!compression || compression->getSize() != 1 ||
!photometric || photometric->getSize() != 1 ||
!stripOfs || stripOfs->getSize() == 0 ||
!numChannels || numChannels->getSize() != 1 ||
!stripBytes || stripBytes->getSize() != stripOfs->getSize() ||
(predictor && predictor->getSize() != 1) ||
(extraSamples && extraSamples->getSize() != 1) ||
(sampleFormat && sampleFormat->getSize() != 1))
{
setError("Corrupt TIFF directory!");
}
if (hasError())
return NULL;
// Interpret size.
//.........这里部分代码省略.........