[BACK]Return to compat_ohash.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/compat_ohash.c between version 1.3 and 1.7

version 1.3, 2014/06/20 02:10:05 version 1.7, 2020/06/15 01:37:15
Line 1 
Line 1 
 #ifdef HAVE_CONFIG_H  /* $Id$ */
 #include "config.h"  
 #endif  
   
 #ifdef HAVE_OHASH  
   
 int dummy;  
   
 #else  
   
 /* $OpenBSD$ */  /* $OpenBSD$ */
   
 /* Copyright (c) 1999, 2004 Marc Espie <espie@openbsd.org>  /* Copyright (c) 1999, 2004 Marc Espie <espie@openbsd.org>
Line 24  int dummy;
Line 15  int dummy;
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */   */
   #include "config.h"
   
   #include <sys/types.h>
 #include <stddef.h>  #include <stddef.h>
 #include <stdint.h>  #include <stdint.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   #include <limits.h>
 #include "compat_ohash.h"  #include "compat_ohash.h"
   
 struct _ohash_record {  struct _ohash_record {
Line 69  ohash_create_entry(struct ohash_info *i, const char *s
Line 63  ohash_create_entry(struct ohash_info *i, const char *s
 void  void
 ohash_delete(struct ohash *h)  ohash_delete(struct ohash *h)
 {  {
         (h->info.hfree)(h->t, sizeof(struct _ohash_record) * h->size,          (h->info.free)(h->t, h->info.data);
                 h->info.data);  
 #ifndef NDEBUG  #ifndef NDEBUG
         h->t = NULL;          h->t = NULL;
 #endif  #endif
Line 80  static void
Line 73  static void
 ohash_resize(struct ohash *h)  ohash_resize(struct ohash *h)
 {  {
         struct _ohash_record *n;          struct _ohash_record *n;
         unsigned int    ns, j;          size_t ns;
           unsigned int    j;
         unsigned int    i, incr;          unsigned int    i, incr;
   
         if (4 * h->deleted < h->total)          if (4 * h->deleted < h->total) {
                 ns = h->size << 1;                  if (h->size >= (UINT_MAX >> 1U))
         else if (3 * h->deleted > 2 * h->total)                          ns = UINT_MAX;
                 ns = h->size >> 1;                  else
                           ns = h->size << 1U;
           } else if (3 * h->deleted > 2 * h->total)
                   ns = h->size >> 1U;
         else          else
                 ns = h->size;                  ns = h->size;
         if (ns < MINSIZE)          if (ns < MINSIZE)
Line 95  ohash_resize(struct ohash *h)
Line 92  ohash_resize(struct ohash *h)
         STAT_HASH_EXPAND++;          STAT_HASH_EXPAND++;
         STAT_HASH_SIZE += ns - h->size;          STAT_HASH_SIZE += ns - h->size;
 #endif  #endif
         n = (h->info.halloc)(sizeof(struct _ohash_record) * ns, h->info.data);  
           n = (h->info.calloc)(ns, sizeof(struct _ohash_record), h->info.data);
         if (!n)          if (!n)
                 return;                  return;
   
Line 112  ohash_resize(struct ohash *h)
Line 110  ohash_resize(struct ohash *h)
                         n[i].p = h->t[j].p;                          n[i].p = h->t[j].p;
                 }                  }
         }          }
         (h->info.hfree)(h->t, sizeof(struct _ohash_record) * h->size,          (h->info.free)(h->t, h->info.data);
                 h->info.data);  
         h->t = n;          h->t = n;
         h->size = ns;          h->size = ns;
         h->total -= h->deleted;          h->total -= h->deleted;
Line 199  ohash_init(struct ohash *h, unsigned int size, struct 
Line 196  ohash_init(struct ohash *h, unsigned int size, struct 
 #endif  #endif
         /* Copy info so that caller may free it.  */          /* Copy info so that caller may free it.  */
         h->info.key_offset = info->key_offset;          h->info.key_offset = info->key_offset;
         h->info.halloc = info->halloc;          h->info.calloc = info->calloc;
         h->info.hfree = info->hfree;          h->info.free = info->free;
         h->info.alloc = info->alloc;          h->info.alloc = info->alloc;
         h->info.data = info->data;          h->info.data = info->data;
         h->t = (h->info.halloc)(sizeof(struct _ohash_record) * h->size,          h->t = (h->info.calloc)(h->size, sizeof(struct _ohash_record),
             h->info.data);                      h->info.data);
         h->total = h->deleted = 0;          h->total = h->deleted = 0;
 }  }
   
Line 331  ohash_qlookupi(struct ohash *h, const char *s, const c
Line 328  ohash_qlookupi(struct ohash *h, const char *s, const c
         hv = ohash_interval(s, e);          hv = ohash_interval(s, e);
         return ohash_lookup_interval(h, s, *e, hv);          return ohash_lookup_interval(h, s, *e, hv);
 }  }
   
 #endif /*!HAVE_OHASH*/  

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.7

CVSweb