| 1 |
/*************************************************************************** |
| 2 |
hash.cpp - description |
| 3 |
------------------- |
| 4 |
begin : Thu Aug 17 2000 |
| 5 |
copyright : (C) 2000 by Waldemar Baraldi |
| 6 |
email : [email protected] |
| 7 |
***************************************************************************/ |
| 8 |
|
| 9 |
/*************************************************************************** |
| 10 |
* * |
| 11 |
* This program is free software; you can redistribute it and/or modify * |
| 12 |
* it under the terms of the GNU General Public License as published by * |
| 13 |
* the Free Software Foundation; either version 2 of the License, or * |
| 14 |
* (at your option) any later version. * |
| 15 |
* * |
| 16 |
***************************************************************************/ |
| 17 |
|
| 18 |
#include <stdlib.h> |
| 19 |
#include <string.h> |
| 20 |
#include "hash.h"cxx . . $ `<file>/src/hash.h`/ |
| 21 |
#include <stdio.h> |
| 22 |
|
| 23 |
Hashcxx . . $ Hash#::Bucketcxx . . $ Hash#Bucket#::Bucketcxx . . $ Hash#Bucket#Bucket(935fba82db1c2b9a).(Strcxx . . $ Str# * str, Objectcxx . . $ Object# * obj){ |
| 24 |
this->strcxx . . $ Hash#Bucket#str.=str; |
| 25 |
this->objcxx . . $ Hash#Bucket#obj.=obj; |
| 26 |
} |
| 27 |
|
| 28 |
Hashcxx . . $ Hash#::Bucketcxx . . $ Hash#Bucket#::~cxx . . $ Hash#Bucket#`~Bucket`(ced63f7c635d850d).Bucketcxx . . $ Hash#Bucket#(){ |
| 29 |
delete strcxx . . $ Hash#Bucket#str.; |
| 30 |
} |
| 31 |
|
| 32 |
void Hashcxx . . $ Hash#::Bucketcxx . . $ Hash#Bucket#::setStrcxx . . $ Hash#Bucket#setStr(954ae62f9fac4410).(Strcxx . . $ Str# * str){ |
| 33 |
if (this->strcxx . . $ Hash#Bucket#str.) delete this->strcxx . . $ Hash#Bucket#str.; |
| 34 |
this->strcxx . . $ Hash#Bucket#str.=str; |
| 35 |
} |
| 36 |
|
| 37 |
void Hashcxx . . $ Hash#::Bucketcxx . . $ Hash#Bucket#::setObjectcxx . . $ Hash#Bucket#setObject(54356f361f029d36).(Objectcxx . . $ Object# * obj){ |
| 38 |
this->objcxx . . $ Hash#Bucket#obj.=obj; |
| 39 |
} |
| 40 |
|
| 41 |
Strcxx . . $ Str# * Hashcxx . . $ Hash#::Bucketcxx . . $ Hash#Bucket#::getStrcxx . . $ Hash#Bucket#getStr(cd0a777ac117067e).(){ |
| 42 |
return strcxx . . $ Hash#Bucket#str.; |
| 43 |
} |
| 44 |
|
| 45 |
Objectcxx . . $ Object# * Hashcxx . . $ Hash#::Bucketcxx . . $ Hash#Bucket#::getObjectcxx . . $ Hash#Bucket#getObject(87a4b0700fd0f820).(){ |
| 46 |
return objcxx . . $ Hash#Bucket#obj.; |
| 47 |
} |
| 48 |
|
| 49 |
int Hashcxx . . $ Hash#::functioncxx . . $ Hash#function(bc877168d52585ba).(Strcxx . . $ Str# * str){ |
| 50 |
int i=0, sum=0; |
| 51 |
const char * aux=str->getcxx . . $ Str#get(33a1f659e94feb42).(); |
| 52 |
|
| 53 |
while (aux[i]!='\0') sum+=aux[i++]; |
| 54 |
|
| 55 |
return(sum % nbucketscxx . . $ Hash#nbuckets.); |
| 56 |
} |
| 57 |
|
| •58 |
Hashcxx . . $ Hash#::Hashcxx . . $ Hash#Hash(d4f767463ce0a6b3).(int bs){ |
| 59 |
int i; |
| 60 |
nbucketscxx . . $ Hash#nbuckets.=bs; |
| •61 |
lbucketscxx . . $ Hash#lbuckets.=new Listcxx . . $ List# *[nbucketscxx . . $ Hash#nbuckets.]; |
| 62 |
|
| 63 |
for (i=0;i<nbucketscxx . . $ Hash#nbuckets.;i++) |
| 64 |
lbucketscxx . . $ Hash#lbuckets.[i]=new Listcxx . . $ List#(); |
| 65 |
} |
| 66 |
|
| 67 |
Hashcxx . . $ Hash#::~cxx . . $ Hash#`~Hash`(ced63f7c635d850d).Hashcxx . . $ Hash#(){ |
| 68 |
int i; |
| 69 |
Listcxx . . $ List# * list; |
| 70 |
for (i=0;i<nbucketscxx . . $ Hash#nbuckets.;i++){ |
| 71 |
list=lbucketscxx . . $ Hash#lbuckets.[i]; |
| 72 |
list->emptycxx . . $ List#empty(b45ddcbc8423892c).(false); |
| 73 |
delete list; |
| 74 |
} |
| 75 |
delete[] lbucketscxx . . $ Hash#lbuckets.; |
| 76 |
} |
| 77 |
|
| 78 |
Hashcxx . . $ Hash#::Resultcxx . . $ Hash#Result# Hashcxx . . $ Hash#::addcxx . . $ Hash#add(ca71450385f5dd99).(Strcxx . . $ Str# * str, Objectcxx . . $ Object# * obj){ |
| 79 |
if (str){ |
| 80 |
// Index * i; |
| 81 |
Listcxx . . $ List# * list; |
| 82 |
list=lbucketscxx . . $ Hash#lbuckets.[functioncxx . . $ Hash#function(bc877168d52585ba).(str)]; |
| 83 |
if (list->nObjectscxx . . $ List#nObjects(b126dc7c1de90089).()>0){ |
| 84 |
/* |
| 85 |
for (i=list->getFirst();i!=list->getEnd();i=list->getNext(i)){ |
| 86 |
if (((Bucket*)list->getObject(i))->getStr()->isEqual(str)){ |
| 87 |
((Bucket*)list->getObject(i))->setObject(obj); |
| 88 |
return AddedOverwrite; |
| 89 |
} |
| 90 |
} |
| 91 |
*/ |
| 92 |
list->insertcxx . . $ List#insert(77801c3fa529a778).(list->getFirstcxx . . $ List#getFirst(614bd0134ee89c3a).(), new Bucketcxx . . $ Hash#Bucket#(str, obj)); |
| 93 |
return AddedCollisioncxx . . $ Hash#AddedCollision.; |
| 94 |
}else{ |
| 95 |
list->insertcxx . . $ List#insert(77801c3fa529a778).(list->getFirstcxx . . $ List#getFirst(614bd0134ee89c3a).(), new Bucketcxx . . $ Hash#Bucket#(str, obj)); |
| 96 |
return AddedNoCollisioncxx . . $ Hash#AddedNoCollision.; |
| 97 |
} |
| 98 |
} |
| 99 |
return NotAddedcxx . . $ Hash#NotAdded.; |
| 100 |
} |
| 101 |
|
| •102 |
Hashcxx . . $ Hash#::Resultcxx . . $ Hash#Result# Hashcxx . . $ Hash#::removecxx . . $ Hash#remove(c11a20fe447b61a8).(Strcxx . . $ Str# * str, bool del){ |
| 103 |
if (str){ |
| 104 |
Indexcxx . . $ Index# * i; |
| 105 |
Listcxx . . $ List# * list=lbucketscxx . . $ Hash#lbuckets.[functioncxx . . $ Hash#function(bc877168d52585ba).(str)]; |
| 106 |
|
| 107 |
for (i=list->getFirstcxx . . $ List#getFirst(614bd0134ee89c3a).();i!=list->getEndcxx . . $ List#getEnd(614bd0134ee89c3a).();i=list->getNextcxx . . $ List#getNext(72af0511b327ff3e).(i)) |
| 108 |
if (((Bucketcxx . . $ Hash#Bucket# *)list->getObjectcxx . . $ List#getObject(a6ae6972207746c4).(i))->getStrcxx . . $ Hash#Bucket#getStr(cd0a777ac117067e).()->isEqualcxx . . $ Str#isEqual(4ada0eb6abe2b819).(str)){ |
| 109 |
if (del) |
| 110 |
delete ((Bucketcxx . . $ Hash#Bucket# *)list->getObjectcxx . . $ List#getObject(a6ae6972207746c4).(i))->getObjectcxx . . $ Hash#Bucket#getObject(87a4b0700fd0f820).(); |
| 111 |
list->removecxx . . $ List#remove(da900e49d65ef0fc).(i, true); |
| 112 |
delete str; |
| 113 |
return Removedcxx . . $ Hash#Removed.; |
| 114 |
} |
| 115 |
delete str; |
| 116 |
} |
| 117 |
return NotFoundcxx . . $ Hash#NotFound.; |
| 118 |
} |
| 119 |
|
| 120 |
Objectcxx . . $ Object# * Hashcxx . . $ Hash#::findcxx . . $ Hash#find(d78ca412e9ee47b6).(Strcxx . . $ Str# * str){ |
| 121 |
if (str){ |
| 122 |
Indexcxx . . $ Index# * i; |
| 123 |
Listcxx . . $ List# * list=lbucketscxx . . $ Hash#lbuckets.[functioncxx . . $ Hash#function(bc877168d52585ba).(str)]; |
| 124 |
|
| 125 |
i=list->getFirstcxx . . $ List#getFirst(614bd0134ee89c3a).(); |
| 126 |
while (i!=list->getEndcxx . . $ List#getEnd(614bd0134ee89c3a).()){ |
| 127 |
if (((Bucketcxx . . $ Hash#Bucket# *)list->getObjectcxx . . $ List#getObject(a6ae6972207746c4).(i))->getStrcxx . . $ Hash#Bucket#getStr(cd0a777ac117067e).()->isEqualcxx . . $ Str#isEqual(4ada0eb6abe2b819).(str)){ |
| 128 |
delete str; |
| 129 |
return ((Bucketcxx . . $ Hash#Bucket# *)list->getObjectcxx . . $ List#getObject(a6ae6972207746c4).(i))->getObjectcxx . . $ Hash#Bucket#getObject(87a4b0700fd0f820).(); |
| 130 |
} |
| 131 |
i=list->getNextcxx . . $ List#getNext(72af0511b327ff3e).(i); |
| 132 |
} |
| 133 |
delete str; |
| 134 |
} |
| 135 |
return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 136 |
} |
| 137 |
|
| •138 |
void Hashcxx . . $ Hash#::emptycxx . . $ Hash#empty(b45ddcbc8423892c).(bool del){ |
| 139 |
int i; |
| 140 |
Listcxx . . $ List# * list; |
| 141 |
for (i=0;i<nbucketscxx . . $ Hash#nbuckets.;i++){ |
| 142 |
list=lbucketscxx . . $ Hash#lbuckets.[i]; |
| 143 |
if (del){ |
| 144 |
Indexcxx . . $ Index# * idx=list->getFirstcxx . . $ List#getFirst(614bd0134ee89c3a).(); |
| 145 |
while (idx!=list->getEndcxx . . $ List#getEnd(614bd0134ee89c3a).()){ |
| 146 |
delete ((Bucketcxx . . $ Hash#Bucket#*)list->getObjectcxx . . $ List#getObject(a6ae6972207746c4).(idx))->getObjectcxx . . $ Hash#Bucket#getObject(87a4b0700fd0f820).(); |
| 147 |
idx=list->getNextcxx . . $ List#getNext(72af0511b327ff3e).(idx); |
| 148 |
} |
| 149 |
} |
| 150 |
list->emptycxx . . $ List#empty(b45ddcbc8423892c).(del); |
| 151 |
} |
| 152 |
} |
| 153 |
|