diff options
author | chatty | 2000-11-28 14:19:34 +0000 |
---|---|---|
committer | chatty | 2000-11-28 14:19:34 +0000 |
commit | 09f57c8dffd9a8ba0983cce13381aef716f43801 (patch) | |
tree | 49c5faa7cd1b76eea36169b5ecce09411b2802c2 /utils/testhash.cc | |
parent | 2575756ec6f41bd05bf4505ccc0253fad0ed77c4 (diff) | |
download | ivy-league-09f57c8dffd9a8ba0983cce13381aef716f43801.zip ivy-league-09f57c8dffd9a8ba0983cce13381aef716f43801.tar.gz ivy-league-09f57c8dffd9a8ba0983cce13381aef716f43801.tar.bz2 ivy-league-09f57c8dffd9a8ba0983cce13381aef716f43801.tar.xz |
*** empty log message ***
Diffstat (limited to 'utils/testhash.cc')
-rw-r--r-- | utils/testhash.cc | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/utils/testhash.cc b/utils/testhash.cc new file mode 100644 index 0000000..ccc5bab --- /dev/null +++ b/utils/testhash.cc @@ -0,0 +1,197 @@ +#include "HashTable.h" +#include <stdio.h> +#include <string.h> + + +CcuDictionnary dict (16); + +main () +{ + char line [256]; + char *s; + int i = 0; + + printf ("? to get help\n"); + + for (;;) { + s = gets (line); + if (! s) + break; + if (strcmp (s, ".") == 0) + break; + + /* help */ + if (strcmp (s, "?") == 0) { + printf ("name add name\n"); + printf ("-name delete name\n"); + printf ("# dump table\n"); +#ifdef TUNE + printf ("%% statistics\n"); +#endif + printf ("> rehash into smaller\n"); + printf ("< rehash into larger\n"); + printf (". quit\n"); + + continue; + } + +#ifdef TUNE + /* stats */ + if (strcmp (s, "%") == 0) { + dict.CollStats (); + continue; + } +#endif + if (strcmp (s, "#") == 0) { + CcuDictionnary dictbis (dict); + CcuHashCellIter hi (dictbis); + while (++hi) + printf ("%s\n", (*hi)->GetKey()); + continue; + } + + /* resizing */ + if (strcmp (s, ">") == 0) { + int s; + + s = dict.GetSize() / 2; + if (s < 1) { + printf ("too small\n"); + continue; + } + printf ("rehashing into smaller table : size %d\n", s); + dict.Resize (s); + continue; + } + + if (strcmp (s, "<") == 0) { + int s; + + s = dict.GetSize() * 2; + printf ("rehashing into larger table : size %d\n", s); + dict.Resize (s); + continue; + } + + /* delete */ + if (*s == '-') { + int found; + void* p = dict.Remove (++s, &found); + if (! found) + printf ("%s not found\n", s); + else + printf ("%s had info %d\n", s, (int) p); + continue; + } + + /* add */ +// BasicHashCell* h = dict.Add (s, &found); +// int found; +// if (found) +// printf ("%s duplicate\n", s); +// else +// h->SetInfo ((void*) i++); + dict[s] = (void*) i++; + } + +} + +#if 0 + +static char strout[200]; +static char *ptout; + +static h_strlen (char *str) +{ + int i = 0; + char *pt = str; + + while (*pt++) ; + + return (pt - str); +} + +static decimal(int i) +{ + int tmp = 0; + char buff[15]; + char *pbuff = buff; + + do { + tmp = i % 10; + *pbuff ++ = tmp + '0'; + i /= 10; + } while (i) ; + while (pbuff - buff) + *ptout++ = *--pbuff; +} + +static hexa(int i) +{ + + int tmp = 0; + char buff[15]; + char *pbuff = buff; + + do { + tmp = i % 16; + *pbuff ++ = "0123456789abcdef"[tmp]; + i /= 16; + } while (i) ; + while (pbuff - buff) + *ptout++ = *--pbuff; + +} + +static h_write(int fd, char *buff, int n) +{ + write(fd, buff, n); + +} + +print(char *fmt, int a1, int a2, int a3, int a4, int a5, int a6) +{ + char *pt = fmt; + char c; + int arg[6]; + int i = 0; + + ptout = strout; + arg[0] = a1; + arg[1] = a2; + arg[2] = a3; + arg[3] = a4; + arg[4] = a5; + arg[5] = a6; + + + for (c = *pt; c = *pt; pt++) { + if(c != '%'){ + *ptout++ = c; + continue; + } + switch (c = *++pt) { + default: + *ptout++ = c; + break; + case 'd': + decimal((int)arg[i++]); + break; + case 'x': + hexa((int)arg[i++]); + break; + case 'c': + *ptout++ = arg[i++]; + break; + case 's':{ + char *p; + for (p = (char *)arg[i++]; *p; p++) + *ptout++ = *p; + } + } + } + *ptout = 0; + h_write(1, strout, h_strlen(strout)); +} + +#endif |