DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T b

⟦0028f2de5⟧ TextFile

    Length: 2546 (0x9f2)
    Types: TextFile
    Names: »bucket.c«

Derivation

└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89
    └─⟦0befd2614⟧ »./gdbm-0.8.tar.Z« 
        └─⟦b993d2893⟧ 
            └─⟦this⟧ »gdbm/bucket.c« 

TextFile

/* bucket.c - The routines for playing with hash buckets. */

/*  GNU DBM  - DataBase Manager (database subroutines) by Philip A. Nelson
    Copyright (C) 1989  Free Software Foundation, Inc.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    You may contact the author by:
       e-mail:  phil@wwu.edu
      us-mail:  Philip A. Nelson
                Computer Science Department
                Western Washington University
                Bellingham, WA 98226
        phone:  (206) 676-3035
       
*************************************************************************/


#include <stdio.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "gdbm.h"


/* Initializing a new hash buckets sets all bucket entries to -1 hash value. */
_dbm_new_bucket (dbf, bucket, bits)
     dbm_file_info *dbf;
     hash_bucket *bucket;
     int bits;
{
  int index;

  /* Set the information fields first. */
  bucket->bucket_bits = bits;
  bucket->count = 0;

  
  /* Initialize all bucket elements. */
  for (index = 0; index < dbf->header.bucket_elems; index++)
    bucket->h_table[index].hash_value = -1;
}



/* Get a hash bucket into memory.  The top bits of HASH_VALUE are used to
   index the hash directory.  If it is already there, do no read. */
int
_dbm_get_bucket (dbf, hash_value)
     dbm_file_info *dbf;
     int hash_value;
{
  int  bucket_adr;	/* The address of the correct hash bucket.  */
  int  num_bytes;	/* The number of bytes read. */

  dbf->bucket_dir = hash_value >> (31-dbf->header.dir_bits);
  bucket_adr = dbf->dir [dbf->bucket_dir];
  if (dbf->bucket_adr != bucket_adr)
    {
      num_bytes = lseek (dbf->desc, bucket_adr, L_SET);
      if (num_bytes != bucket_adr) _dbm_fatal (dbf, "lseek error");
      num_bytes = read (dbf->desc, dbf->bucket, dbf->header.bucket_size);
      if (num_bytes != dbf->header.bucket_size) _dbm_fatal (dbf, "read error");
      dbf->bucket_adr = bucket_adr;
    }

  return TRUE;
}