head 1.5; access; symbols act_first:1.1.1.1 act:1.1.1; locks; strict; comment @ * @; 1.5 date 2003.01.06.12.10.58; author rse; state Exp; branches; next 1.4; 1.4 date 2002.01.17.20.19.57; author rse; state Exp; branches; next 1.3; 1.3 date 2000.08.20.13.57.53; author rse; state Exp; branches; next 1.2; 1.2 date 99.11.12.20.43.09; author rse; state Exp; branches; next 1.1; 1.1 date 99.11.12.20.37.19; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 99.11.12.20.37.19; author rse; state Exp; branches; next ; desc @@ 1.5 log @cleanup source tree @ text @/* ** OSSP act - Abstract Container Types ** Copyright (c) 1999-2003 Ralf S. Engelschall ** Copyright (c) 1999-2003 The OSSP Project ** ** This file is part of OSSP act, an abstract container type library ** which can be found at http://www.ossp.org/pkg/lib/act/. ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** ** act_test.c: test suite */ #include #include #include "act_p.h" #include "act_hash.h" struct kd { char *k; char *d; }; #define act_hash_insert_str(h,k,v,o) \ act_hash_insert((h),(k),strlen((k)),(v),strlen((v))+1,(o)) #define act_hash_lookup_str(h,k,v) \ act_hash_lookup((h),(k),strlen((k)),(v),NULL) #define act_hash_delete_str(h,k) \ act_hash_delete((h),(k),strlen((k))) int main(int argc, char *argv[]) { act_hash_t *h; char buf[1024]; char buf2[1024]; long i; FILE *fp; act_ctx_t *ctx; char s[1024]; char *cp; act_init(); ctx = act_ctx_dup(act_ctx_default, NULL); act_ctx_set(ctx, ACT_HASH_FUNC, act_hash_fct(cdt)); if ((h = act_hash_new(ctx)) == NULL) { perror("act_hash_new"); exit(1); } act_ctx_free(ctx); act_hash_status(h, s, sizeof s); fprintf(stderr, "%s\n", s); fprintf(stderr, "\n**INSERT**\n\n"); fp = fopen("../data/words", "r"); i = 1; while (fgets(buf, sizeof(buf), fp) != NULL) { buf[strlen(buf)-1] = '\0'; sprintf(buf2, "%ld", i); act_hash_insert_str(h, buf, buf2, FALSE); if ( (i < 100 && i % 10 == 0) || (i < 1000 && i % 100 == 0) || (i < 10000 && i % 1000 == 0) || (i < 100000 && i % 10000 == 0) || (i < 1000000 && i % 100000 == 0)) { act_hash_status(h, s, sizeof s); fprintf(stderr, "%s\n", s); } i++; } fclose(fp); act_hash_status(h, s, sizeof s); fprintf(stderr, "%s\n", s); fprintf(stderr, "\n**LOOKUP**\n\n"); fp = fopen("../data/words", "r"); i = 1; while (fgets(buf, sizeof(buf), fp) != NULL) { buf[strlen(buf)-1] = '\0'; sprintf(buf2, "%ld", i); if (!act_hash_lookup_str(h, buf, (void **)&cp)) fprintf(stderr, "failed to lookup `%s'\n", buf); else { if (strcmp(cp, buf2) != 0) fprintf(stderr, "value failed for `%s': %s <-> %s\n", buf, buf2, cp); } i++; } fclose(fp); act_hash_status(h, s, sizeof s); fprintf(stderr, "%s\n", s); fprintf(stderr, "\n**DELETE**\n\n"); fp = fopen("../data/words", "r"); while (fgets(buf, sizeof(buf), fp) != NULL) { buf[strlen(buf)-1] = '\0'; if ( (i < 100 && i % 10 == 0) || (i < 1000 && i % 100 == 0) || (i < 10000 && i % 1000 == 0) || (i < 100000 && i % 10000 == 0) || (i < 1000000 && i % 100000 == 0)) { act_hash_status(h, s, sizeof s); fprintf(stderr, "%s\n", s); } if (!act_hash_delete_str(h, buf)) fprintf(stderr, "failed to delete `%s'\n", buf); i--; } fclose(fp); act_hash_status(h, s, sizeof s); fprintf(stderr, "%s\n", s); if (!act_hash_free(h)) { perror("act_hash_free"); exit(1); } exit(0); } @ 1.4 log @- use devtool - remove generated files - upgrade to Autoconf 2.52 @ text @d1 28 d48 1 a48 1 int main(int argc, char *argv[]) d104 1 a104 1 if (!act_hash_lookup_str(h, buf, (void **)&cp)) d130 1 a130 1 if (!act_hash_delete_str(h, buf)) @ 1.3 log @*** empty log message *** @ text @d3 1 @ 1.2 log @*** empty log message *** @ text @a21 1 long b, e; d26 2 a28 1 act_ctx_t *ctx; d33 1 a33 1 act_ctx_set(ctx, ACT_HASH_FUNC, act_hash_fct(djbx33a)); d42 2 a43 2 act_hash_size(h, &b, &e); fprintf(stderr, "bytes=%ld elements=%ld\n", b, e); d53 7 a59 3 if (i % 100000 == 0) { act_hash_size(h, &b, &e); fprintf(stderr, "i=%ld b=%ld e=%ld\n", i, b, e); d65 2 a66 2 act_hash_size(h, &b, &e); fprintf(stderr, "bytes=%ld elements=%ld\n", b, e); d85 2 a86 2 act_hash_size(h, &b, &e); fprintf(stderr, "bytes=%ld elements=%ld\n", b, e); a90 1 i = 1; d93 7 a99 3 if (i % 100000 == 0) { act_hash_size(h, &b, &e); fprintf(stderr, "i=%ld b=%ld e=%ld\n", i, b, e); d103 1 a103 1 i++; d107 2 a108 2 act_hash_size(h, &b, &e); fprintf(stderr, "bytes=%ld elements=%ld\n", b, e); @ 1.1 log @Initial revision @ text @d47 1 a47 1 fp = fopen("DATA/words", "r"); d66 1 a66 1 fp = fopen("DATA/words", "r"); d86 1 a86 1 fp = fopen("DATA/words", "r"); @ 1.1.1.1 log @ @ text @@