vcglib/apps/nexus/mfhash.h

95 lines
3.3 KiB
C
Raw Normal View History

2004-06-24 16:32:45 +02:00
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
* Copyright(C) 2004 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
/****************************************************************************
History
$Log: not supported by cvs2svn $
2004-11-18 19:30:15 +01:00
Revision 1.4 2004/07/02 17:40:30 ponchio
Debug.
2004-07-02 19:42:43 +02:00
Revision 1.3 2004/07/02 13:08:43 ponchio
*** empty log message ***
2004-07-02 15:09:57 +02:00
Revision 1.2 2004/07/01 21:34:29 ponchio
*** empty log message ***
2004-07-01 23:36:54 +02:00
Revision 1.1 2004/06/24 14:32:45 ponchio
Moved from wrap/nexus
2004-06-24 16:32:45 +02:00
Revision 1.1 2004/06/24 14:18:58 ponchio
Created
****************************************************************************/
#ifndef NXS_MFHASH_H
#define NXS_MFHASH_H
#include "vfile.h"
#include <stdio.h>
namespace nxs {
class MFHash {
public:
struct Bucket {
unsigned int key;
unsigned int value;
Bucket(): key(0xffffffff) {}
Bucket(unsigned int k, unsigned int v): key(k), value(v) {}
bool Empty() { return key == 0xffffffff; }
};
MFHash() {}
bool Create(const std::string &file, unsigned int reserved = 32);
bool Load(const std::string &file, unsigned int used = 0xffffffff);
2004-11-18 19:30:15 +01:00
void Delete();
2004-06-24 16:32:45 +02:00
void Resize(unsigned int n);
void Insert(unsigned int key, unsigned int value, bool rehash = true);
template <class C> void GetValues(unsigned int key, C &container) {
container.clear();
unsigned int hash_size = buffer.Size();
unsigned int j = key % hash_size;
while(!buffer[j].Empty()) {
if(buffer[j].key == key) {
2004-07-02 19:42:43 +02:00
//container.push_back(buffer[j].value);
container.insert(buffer[j].value);
2004-06-24 16:32:45 +02:00
}
j++;
if(j >= hash_size) j = 0;
}
}
unsigned int Count(unsigned int key);
void Clear();
unsigned int Size();
void Close();
2004-07-02 15:09:57 +02:00
2004-06-24 16:32:45 +02:00
VFile<Bucket> buffer;
unsigned int space;
};
}//namespace
#endif