266 lines
9.9 KiB
Diff
266 lines
9.9 KiB
Diff
diff --git a/src/GHash.hh b/src/GHash.hh
|
|
index 5122e1d..df613d0 100644
|
|
--- a/src/GHash.hh
|
|
+++ b/src/GHash.hh
|
|
@@ -88,7 +88,7 @@ public:
|
|
//nextkey is SET to the corresponding key
|
|
GHashEntry* NextEntry() { //returns a pointer to a GHashEntry
|
|
register int pos=fCurrentEntry;
|
|
- while (pos<fCapacity && hash[pos].hash<0) pos++;
|
|
+ while (pos<fCapacity && (hash[pos].hash)<0) pos++;
|
|
if (pos==fCapacity) {
|
|
fCurrentEntry=fCapacity;
|
|
return NULL;
|
|
@@ -146,7 +146,7 @@ template <class OBJ> GHash<OBJ>::GHash(GFreeProc* freeProc) {
|
|
fFreeProc=freeProc;
|
|
lastkeyptr=NULL;
|
|
for (uint i=0; i<DEF_HASH_SIZE; i++)
|
|
- hash[i].hash=-1; //this will be an indicator for 'empty' entries
|
|
+ (hash[i].hash)=-1; //this will be an indicator for 'empty' entries
|
|
fCapacity=DEF_HASH_SIZE;
|
|
fCount=0;
|
|
}
|
|
@@ -157,7 +157,7 @@ template <class OBJ> GHash<OBJ>::GHash(bool doFree) {
|
|
lastkeyptr=NULL;
|
|
fFreeProc = (doFree)?&DefaultFreeProc : NULL;
|
|
for (uint i=0; i<DEF_HASH_SIZE; i++)
|
|
- hash[i].hash=-1; //this will be an indicator for 'empty' entries
|
|
+ (hash[i].hash)=-1; //this will be an indicator for 'empty' entries
|
|
fCapacity=DEF_HASH_SIZE;
|
|
fCount=0;
|
|
}
|
|
@@ -177,16 +177,16 @@ template <class OBJ> void GHash<OBJ>::Resize(int m){
|
|
if(n!=fCapacity){
|
|
GASSERT(m<=n);
|
|
GMALLOC(k, sizeof(GHashEntry)*n);
|
|
- for(i=0; i<n; i++) k[i].hash=-1;
|
|
+ for(i=0; i<n; i++) (k[i].hash)=-1;
|
|
for(i=0; i<fCapacity; i++){
|
|
- h=hash[i].hash;
|
|
+ h=(hash[i].hash);
|
|
if(0<=h){
|
|
p=HASH1(h,n);
|
|
GASSERT(0<=p && p<n);
|
|
x=HASH2(h,n);
|
|
GASSERT(1<=x && x<n);
|
|
- while(k[p].hash!=-1) p=(p+x)%n;
|
|
- GASSERT(k[p].hash<0);
|
|
+ while((k[p].hash)!=-1) p=(p+x)%n;
|
|
+ GASSERT((k[p].hash)<0);
|
|
k[p]=hash[i];
|
|
}
|
|
}
|
|
@@ -210,9 +210,9 @@ template <class OBJ> const OBJ* GHash<OBJ>::Add(const char* ky,
|
|
GASSERT(1<=x && x<fCapacity);
|
|
i=-1;
|
|
n=fCapacity;
|
|
- while(n && hash[p].hash!=-1){
|
|
- if ((i==-1)&&(hash[p].hash==-2)) i=p;
|
|
- if (hash[p].hash==h && strcmp(hash[p].key,ky)==0) {
|
|
+ while(n && (hash[p].hash)!=-1){
|
|
+ if ((i==-1)&&((hash[p].hash)==-2)) i=p;
|
|
+ if ((hash[p].hash)==h && strcmp(hash[p].key,ky)==0) {
|
|
//replace hash data for this key!
|
|
lastkeyptr=hash[p].key;
|
|
hash[p].data = (void*) pdata;
|
|
@@ -225,8 +225,8 @@ template <class OBJ> const OBJ* GHash<OBJ>::Add(const char* ky,
|
|
GTRACE(("GHash::insert: key=\"%s\"\n",ky));
|
|
//GMessage("GHash::insert: key=\"%s\"\n",ky);
|
|
GASSERT(0<=i && i<fCapacity);
|
|
- GASSERT(hash[i].hash<0);
|
|
- hash[i].hash=h;
|
|
+ GASSERT((hash[i].hash)<0);
|
|
+ (hash[i].hash)=h;
|
|
hash[i].mark=mrk;
|
|
hash[i].key=Gstrdup(ky);
|
|
hash[i].keyalloc=true;
|
|
@@ -251,9 +251,9 @@ template <class OBJ> const OBJ* GHash<OBJ>::shkAdd(const char* ky,
|
|
GASSERT(1<=x && x<fCapacity);
|
|
i=-1;
|
|
n=fCapacity;
|
|
- while(n && hash[p].hash!=-1){
|
|
- if((i==-1)&&(hash[p].hash==-2)) i=p;
|
|
- if(hash[p].hash==h && strcmp(hash[p].key,ky)==0){
|
|
+ while(n && (hash[p].hash)!=-1){
|
|
+ if((i==-1)&&((hash[p].hash)==-2)) i=p;
|
|
+ if((hash[p].hash)==h && strcmp(hash[p].key,ky)==0){
|
|
//replace hash data for this key!
|
|
lastkeyptr=hash[p].key;
|
|
hash[p].data = (void*) pdata;
|
|
@@ -266,8 +266,8 @@ template <class OBJ> const OBJ* GHash<OBJ>::shkAdd(const char* ky,
|
|
GTRACE(("GHash::insert: key=\"%s\"\n",ky));
|
|
//GMessage("GHash::insert: key=\"%s\"\n",ky);
|
|
GASSERT(0<=i && i<fCapacity);
|
|
- GASSERT(hash[i].hash<0);
|
|
- hash[i].hash=h;
|
|
+ GASSERT((hash[i].hash)<0);
|
|
+ (hash[i].hash)=h;
|
|
hash[i].mark=mrk;
|
|
hash[i].key=(char *)ky;
|
|
lastkeyptr=hash[i].key;
|
|
@@ -293,9 +293,9 @@ template <class OBJ> OBJ* GHash<OBJ>::Replace(const char* ky,const OBJ* pdata,
|
|
GASSERT(1<=x && x<fCapacity);
|
|
i=-1;
|
|
n=fCapacity;
|
|
- while(n && hash[p].hash!=-1){
|
|
- if((i==-1)&&(hash[p].hash==-2)) i=p;
|
|
- if(hash[p].hash==h && strcmp(hash[p].key,ky)==0){
|
|
+ while(n && (hash[p].hash)!=-1){
|
|
+ if((i==-1)&&((hash[p].hash)==-2)) i=p;
|
|
+ if((hash[p].hash)==h && strcmp(hash[p].key,ky)==0){
|
|
if(hash[p].mark<=mrk){
|
|
GTRACE(("GHash::replace: %08x: replacing: \"%s\"\n",this,ky));
|
|
if (FREEDATA) (*fFreeProc)(hash[p].data);
|
|
@@ -310,8 +310,8 @@ template <class OBJ> OBJ* GHash<OBJ>::Replace(const char* ky,const OBJ* pdata,
|
|
if(i==-1) i=p;
|
|
GTRACE(("GHash::replace: %08x: inserting: \"%s\"\n",this,ky));
|
|
GASSERT(0<=i && i<fCapacity);
|
|
- GASSERT(hash[i].hash<0);
|
|
- hash[i].hash=h;
|
|
+ GASSERT((hash[i].hash)<0);
|
|
+ (hash[i].hash)=h;
|
|
hash[i].mark=mrk;
|
|
hash[i].key=Gstrdup(ky);
|
|
hash[i].data=pdata;
|
|
@@ -335,10 +335,10 @@ template <class OBJ> OBJ* GHash<OBJ>::Remove(const char* ky){
|
|
GASSERT(1<=x && x<fCapacity);
|
|
GASSERT(fCount<fCapacity);
|
|
n=fCapacity;
|
|
- while(n && hash[p].hash!=-1){
|
|
- if(hash[p].hash==h && strcmp(hash[p].key,ky)==0){
|
|
+ while(n && (hash[p].hash)!=-1){
|
|
+ if((hash[p].hash)==h && strcmp(hash[p].key,ky)==0){
|
|
GTRACE(("GHash::remove: %08x removing: \"%s\"\n",this,ky));
|
|
- hash[p].hash=-2;
|
|
+ (hash[p].hash)=-2;
|
|
hash[p].mark=false;
|
|
if (hash[p].keyalloc) GFREE((hash[p].key));
|
|
if (FREEDATA) (*fFreeProc)(hash[p].data);
|
|
@@ -370,8 +370,8 @@ template <class OBJ> bool GHash<OBJ>::hasKey(const char* ky) {
|
|
GASSERT(1<=x && x<fCapacity);
|
|
GASSERT(fCount<fCapacity);
|
|
n=fCapacity;
|
|
- while(n && hash[p].hash!=-1){
|
|
- if(hash[p].hash==h && strcmp(hash[p].key,ky)==0){
|
|
+ while(n && (hash[p].hash)!=-1){
|
|
+ if((hash[p].hash)==h && strcmp(hash[p].key,ky)==0){
|
|
return true;
|
|
}
|
|
p=(p+x)%fCapacity;
|
|
@@ -393,8 +393,8 @@ template <class OBJ> OBJ* GHash<OBJ>::Find(const char* ky, char** keyptr){
|
|
GASSERT(1<=x && x<fCapacity);
|
|
GASSERT(fCount<fCapacity);
|
|
n=fCapacity;
|
|
- while(n && hash[p].hash!=-1){
|
|
- if(hash[p].hash==h && strcmp(hash[p].key,ky)==0){
|
|
+ while(n && (hash[p].hash)!=-1){
|
|
+ if((hash[p].hash)==h && strcmp(hash[p].key,ky)==0){
|
|
if (keyptr!=NULL) *keyptr = hash[p].key;
|
|
return (OBJ*)hash[p].data;
|
|
}
|
|
@@ -412,7 +412,7 @@ template <class OBJ> void GHash<OBJ>::startIterate() {// initialize a key iterat
|
|
|
|
template <class OBJ> char* GHash<OBJ>::NextKey() {
|
|
register int pos=fCurrentEntry;
|
|
- while (pos<fCapacity && hash[pos].hash<0) pos++;
|
|
+ while (pos<fCapacity && (hash[pos].hash)<0) pos++;
|
|
if (pos==fCapacity) {
|
|
fCurrentEntry=fCapacity;
|
|
return NULL;
|
|
@@ -425,7 +425,7 @@ template <class OBJ> char* GHash<OBJ>::NextKey() {
|
|
|
|
template <class OBJ> OBJ* GHash<OBJ>::NextData() {
|
|
register int pos=fCurrentEntry;
|
|
- while (pos<fCapacity && hash[pos].hash<0) pos++;
|
|
+ while (pos<fCapacity && (hash[pos].hash)<0) pos++;
|
|
if (pos==fCapacity) {
|
|
fCurrentEntry=fCapacity;
|
|
return NULL;
|
|
@@ -439,7 +439,7 @@ template <class OBJ> OBJ* GHash<OBJ>::NextData() {
|
|
|
|
template <class OBJ> OBJ* GHash<OBJ>::NextData(char* &nextkey) {
|
|
register int pos=fCurrentEntry;
|
|
- while (pos<fCapacity && hash[pos].hash<0) pos++;
|
|
+ while (pos<fCapacity && (hash[pos].hash)<0) pos++;
|
|
if (pos==fCapacity) {
|
|
fCurrentEntry=fCapacity;
|
|
nextkey=NULL;
|
|
@@ -457,8 +457,8 @@ template <class OBJ> OBJ* GHash<OBJ>::NextData(char* &nextkey) {
|
|
// Get first non-empty entry
|
|
template <class OBJ> int GHash<OBJ>::First() const {
|
|
register int pos=0;
|
|
- while(pos<fCapacity){ if(0<=hash[pos].hash) break; pos++; }
|
|
- GASSERT(fCapacity<=pos || 0<=hash[pos].hash);
|
|
+ while(pos<fCapacity){ if(0<=(hash[pos].hash)) break; pos++; }
|
|
+ GASSERT(fCapacity<=pos || 0<=(hash[pos].hash));
|
|
return pos;
|
|
}
|
|
|
|
@@ -474,8 +474,8 @@ template <class OBJ> int GHash<OBJ>::Last() const {
|
|
// Find next valid entry
|
|
template <class OBJ> int GHash<OBJ>::Next(int pos) const {
|
|
GASSERT(0<=pos && pos<fCapacity);
|
|
- while(++pos <= fCapacity-1){ if(0<=hash[pos].hash) break; }
|
|
- GASSERT(fCapacity<=pos || 0<=hash[pos].hash);
|
|
+ while(++pos <= fCapacity-1){ if(0<=(hash[pos].hash)) break; }
|
|
+ GASSERT(fCapacity<=pos || 0<=(hash[pos].hash));
|
|
return pos;
|
|
}
|
|
|
|
@@ -483,8 +483,8 @@ template <class OBJ> int GHash<OBJ>::Next(int pos) const {
|
|
// Find previous valid entry
|
|
template <class OBJ> int GHash<OBJ>::Prev(int pos) const {
|
|
GASSERT(0<=pos && pos<fCapacity);
|
|
- while(--pos >= 0){ if(0<=hash[pos].hash) break; }
|
|
- GASSERT(pos<0 || 0<=hash[pos].hash);
|
|
+ while(--pos >= 0){ if(0<=(hash[pos].hash)) break; }
|
|
+ GASSERT(pos<0 || 0<=(hash[pos].hash));
|
|
return pos;
|
|
}
|
|
|
|
@@ -493,7 +493,7 @@ template <class OBJ> int GHash<OBJ>::Prev(int pos) const {
|
|
template <class OBJ> void GHash<OBJ>::Clear(){
|
|
register int i;
|
|
for(i=0; i<fCapacity; i++){
|
|
- if(hash[i].hash>=0){
|
|
+ if((hash[i].hash)>=0){
|
|
if (hash[i].keyalloc) GFREE((hash[i].key));
|
|
if (FREEDATA)
|
|
(*fFreeProc)(hash[i].data);
|
|
@@ -503,7 +503,7 @@ template <class OBJ> void GHash<OBJ>::Clear(){
|
|
GMALLOC(hash, sizeof(GHashEntry)*DEF_HASH_SIZE);
|
|
//reinitialize it
|
|
for (i=0; i<DEF_HASH_SIZE; i++)
|
|
- hash[i].hash=-1; //this will be an indicator for 'empty' entries
|
|
+ (hash[i].hash)=-1; //this will be an indicator for 'empty' entries
|
|
fCapacity=DEF_HASH_SIZE;
|
|
fCount=0;
|
|
}
|
|
@@ -517,7 +517,7 @@ void GHash::Save(Stream& store) const {
|
|
store << fCount;
|
|
for(int i=0; i<fCapacity; i++){
|
|
store << hash[i].hash;
|
|
- if(hash[i].hash>=0){
|
|
+ if((hash[i].hash)>=0){
|
|
uint len=strlen(hash[i].key);
|
|
store << len;
|
|
store << hash[i].mark;
|
|
@@ -534,7 +534,7 @@ void GHash::Load(Stream& store){
|
|
store >> fCount;
|
|
for(int i=0; i<fCapacity; i++){
|
|
store >> hash[i].hash;
|
|
- if(hash[i].hash>=0){
|
|
+ if((hash[i].hash)>=0){
|
|
uint len;
|
|
store >> len;
|
|
store >> hash[i].mark;
|
|
@@ -550,7 +550,7 @@ void GHash::Load(Stream& store){
|
|
template <class OBJ> GHash<OBJ>::~GHash(){
|
|
register int i;
|
|
for(i=0; i<fCapacity; i++){
|
|
- if(hash[i].hash>=0){
|
|
+ if((hash[i].hash)>=0){
|
|
if (hash[i].keyalloc) GFREE((hash[i].key));
|
|
if (FREEDATA) (*fFreeProc)(hash[i].data);
|
|
}
|