summaryrefslogtreecommitdiff
path: root/appl/lib/tcl_modhash.b
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
commit37da2899f40661e3e9631e497da8dc59b971cbd0 (patch)
treecbc6d4680e347d906f5fa7fca73214418741df72 /appl/lib/tcl_modhash.b
parent54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff)
20060303a
Diffstat (limited to 'appl/lib/tcl_modhash.b')
-rw-r--r--appl/lib/tcl_modhash.b114
1 files changed, 114 insertions, 0 deletions
diff --git a/appl/lib/tcl_modhash.b b/appl/lib/tcl_modhash.b
new file mode 100644
index 00000000..ebb85146
--- /dev/null
+++ b/appl/lib/tcl_modhash.b
@@ -0,0 +1,114 @@
+implement Mod_Hashtab;
+
+include "sys.m";
+include "draw.m";
+include "tk.m";
+include "tcl.m";
+include "tcllib.m";
+
+include "utils.m";
+
+
+hashasu(key : string,n : int): int{
+ i, h : int;
+ h=0;
+ i=0;
+ while(i<len key){
+ h = 10*h + key[i];
+ h = h%n;
+ i++;
+ }
+ return h%n;
+}
+
+alloc(size : int) : ref MHash {
+ h : MHash;
+ t : list of H_link;
+ t=nil;
+ h.size= size;
+ h.tab = array[size] of {* => t};
+ return ref h;
+}
+
+MHash.dump(h : self ref MHash) : string {
+ retval :string;
+ for (i:=0;i<h.size;i++){
+ tmp:=(h.tab)[i];
+ for(;tmp!=nil;tmp = tl tmp){
+ if ((hd tmp).name!=nil){
+ retval+=(hd tmp).name;
+ retval[len retval]=' ';
+ }
+ }
+ }
+ if (retval!=nil)
+ retval=retval[0:len retval-1];
+ return retval;
+}
+
+
+
+MHash.insert(h : self ref MHash,name: string, val:TclLib) : int {
+ link : H_link;
+ hash,found : int;
+ nlist : list of H_link;
+ nlist=nil;
+ found=0;
+ hash = hashasu(name,h.size);
+ tmp:=(h.tab)[hash];
+ for(;tmp!=nil;tmp = tl tmp){
+ link=hd tmp;
+ if (link.name==name){
+ found=1;
+ link.val = val;
+ }
+ nlist = link :: nlist;
+ }
+ if (!found){
+ link.name=name;
+ link.val=val;
+ (h.tab)[hash]= link :: (h.tab)[hash];
+ }else
+ (h.tab)[hash]=nlist;
+ return 1;
+}
+
+MHash.find(h : self ref MHash,name : string) : (int, TclLib){
+ hash,flag : int;
+ nlist : list of H_link;
+ retval : TclLib;
+ retval=nil;
+ flag=0;
+ nlist=nil;
+ hash = hashasu(name,h.size);
+ tmp:=(h.tab)[hash];
+ for(;tmp!=nil;tmp = tl tmp){
+ link:=hd tmp;
+ if ((hd tmp).name==name){
+ flag = 1;
+ retval = (hd tmp).val;
+ }
+ nlist = link :: nlist;
+ }
+ (h.tab)[hash]=nlist;
+ return (flag,retval);
+}
+
+MHash.delete(h : self ref MHash,name : string) : int {
+ hash,flag : int;
+ nlist : list of H_link;
+ flag=0;
+ nlist=nil;
+ hash = hashasu(name,h.size);
+ tmp:=(h.tab)[hash];
+ for(;tmp!=nil;tmp = tl tmp){
+ link:=hd tmp;
+ if (link.name==name)
+ flag = 1;
+ else
+ nlist = link :: nlist;
+ }
+ (h.tab)[hash]=nlist;
+ return flag;
+}
+