bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] libihash


From: Neal H Walfield
Subject: [PATCH] libihash
Date: Tue, 27 Feb 2001 16:11:31 +0100
User-agent: Mutt/1.3.12i

This patch allows users of the ihash library to include the ihash
structure directly in user structures, i.e.:

struct foo
{
  struct ihash;
};

Whereas before, this was not possible.

-Neal


Only in hurd-20010115/libihash: .primes.c.swp
diff -ur hurd-20010115-snapshot/libihash/ChangeLog 
hurd-20010115/libihash/ChangeLog
--- hurd-20010115-snapshot/libihash/ChangeLog   Sun Mar  7 16:45:15 1999
+++ hurd-20010115/libihash/ChangeLog    Sun Feb 25 05:27:11 2001
@@ -1,3 +1,16 @@
+2001-02-14  Neal H Walfield  <neal@cs.uml.edu>
+
+       * ihash.h (ihash_init): Declare it.
+       (ihash_destroy): Declare it.
+       * ihash.c (ihash_init): New function.  Similar to ihash_create,
+       however, it does not malloc the ihash structure.
+       (ihash_create): Use ihash_create.
+       (ihash_destory): New function.  Similar to ihash_free, however,
+       does not free the ihash structure.
+       (ihash_free): Use ihash_destroy.
+
+       * primes.c (_ihash_nextprime): bzero -> memset.
+
 1999-03-07  Roland McGrath  <roland@baalperazim.frob.com>
 
        * primes.c: Fix last change.
diff -ur hurd-20010115-snapshot/libihash/ihash.c hurd-20010115/libihash/ihash.c
--- hurd-20010115-snapshot/libihash/ihash.c     Fri Jun 20 00:56:28 1997
+++ hurd-20010115/libihash/ihash.c      Sun Feb 25 05:27:39 2001
@@ -1,6 +1,6 @@
 /* Integer-keyed hash table functions.
 
-   Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1993, 1994, 1995, 1996, 1997, 2001 Free Software Foundation, 
Inc.
    
    This file is part of the GNU Hurd.
 
@@ -76,6 +76,15 @@
 
 /* ---------------------------------------------------------------- */
 
+/* Like ihash_create, however, the memory is already allocated.  */
+error_t ihash_init(struct ihash *ht)
+{
+  ht->size = 0;
+  ht->cleanup = 0;
+  ht->cleanup_arg = 0;
+  return 0;
+}
+
 /* Create an integer hash table and return it in HT.  If a memory allocation
    error occurs, ENOMEM is returned, otherwise 0.  */
 error_t
@@ -84,15 +93,11 @@
   *ht = malloc(sizeof(struct ihash));
   if (*ht == NULL)
     return ENOMEM;
-  (*ht)->size = 0;
-  (*ht)->cleanup = 0;
-  (*ht)->cleanup_arg = 0;
-  return 0;
+  return ihash_init (*ht);
 }
 
-/* Free HT and all resources it consumes.  */
-void 
-ihash_free(ihash_t ht)
+/* Like ihash_free, however, the ihash data structure itself if not freed.  */
+void ihash_destroy(struct ihash *ht)
 {
   void (*cleanup)(void *value, void *arg) = ht->cleanup;
 
@@ -111,6 +116,13 @@
       free(ht->ids);
       free(ht->locps);
     }
+}
+
+/* Free HT and all resources it consumes.  */
+void 
+ihash_free(ihash_t ht)
+{
+  ihash_destroy (ht);
 
   free(ht);
 }
diff -ur hurd-20010115-snapshot/libihash/ihash.h hurd-20010115/libihash/ihash.h
--- hurd-20010115-snapshot/libihash/ihash.h     Thu Apr 25 01:01:46 1996
+++ hurd-20010115/libihash/ihash.h      Sun Feb 25 05:27:47 2001
@@ -1,6 +1,6 @@
 /* Integer-keyed hash table functions.
 
-   Copyright (C) 1995 Free Software Foundation, Inc.
+   Copyright (C) 1995, 2001 Free Software Foundation, Inc.
 
    Written by Miles Bader <miles@gnu.ai.mit.edu>
 
@@ -54,8 +54,14 @@
    error occurs, ENOMEM is returned, otherwise 0.  */
 error_t ihash_create(ihash_t *ht);
 
+/* Like ihash_create, however, the memory is already allocated.  */
+error_t ihash_init(struct ihash *ht);
+
 /* Free HT and all resources it consumes.  */
 void ihash_free(ihash_t ht);
+
+/* Like ihash_free, however, the ihash data structure itself if not freed.  */
+void ihash_destroy(struct ihash *ht);
 
 /* Sets HT's element cleanup function to CLEANUP, and its second argument to
    ARG.  CLEANUP will be called on the value of any element to be
diff -ur hurd-20010115-snapshot/libihash/primes.c 
hurd-20010115/libihash/primes.c
--- hurd-20010115-snapshot/libihash/primes.c    Sun Mar  7 16:45:03 1999
+++ hurd-20010115/libihash/primes.c     Sun Feb 25 05:27:57 2001
@@ -1,5 +1,5 @@
 /* Prime number generation
-   Copyright (C) 1994, 1996, 1999 Free Software Foundation
+   Copyright (C) 1994, 1996, 1999, 2001 Free Software Foundation
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -75,7 +75,7 @@
       char sieve[end - start];
       int i;
 
-      bzero (sieve, (end - start) * sizeof (*sieve));
+      memset (sieve, 0, (end - start) * sizeof (*sieve));
 
       /* Make the sieve indexed by prime number, rather than
         distance-from-start-to-the-prime-number.  When we're done,

Attachment: pgpXZJxb1y3Mv.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]