Changeset 6141 for trunk/ARBDB/adhash.c

Show
Ignore:
Timestamp:
14/08/09 16:29:27 (3 years ago)
Author:
westram
Message:
  • spellchecked all (phew)
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ARBDB/adhash.c

    r5907 r6141  
    8080static unsigned char bit_val[8] = { 1, 2, 4, 8, 16, 32, 64, 128 }; 
    8181 
    82 static int bit_value(const unsigned char *erastothenes, long num) { // 'num' is odd and lowest 'num' is 3 
     82static int bit_value(const unsigned char *eratosthenes, long num) { // 'num' is odd and lowest 'num' is 3 
    8383    long bit_num  = ((num-1) >> 1)-1; // 3->0 5->1 7->2 etc. 
    8484    long byte_num = bit_num >> 3; // div 8 
    85     char byte     = erastothenes[byte_num]; 
     85    char byte     = eratosthenes[byte_num]; 
    8686 
    8787    gb_assert(bit_num >= 0); 
     
    9292    return (byte & bit_val[bit_num]) ? 1 : 0; 
    9393} 
    94 static void set_bit_value(unsigned char *erastothenes, long num, int val) { // 'num' is odd and lowest 'num' is 3; val is 0 or 1 
     94static void set_bit_value(unsigned char *eratosthenes, long num, int val) { // 'num' is odd and lowest 'num' is 3; val is 0 or 1 
    9595    long bit_num  = ((num-1) >> 1)-1; // 3->0 5->1 7->2 etc. 
    9696    long byte_num = bit_num >> 3; // div 8 
    97     char byte     = erastothenes[byte_num]; 
     97    char byte     = eratosthenes[byte_num]; 
    9898 
    9999    gb_assert(bit_num >= 0); 
     
    108108        byte &= (0xff - bit_val[bit_num]); 
    109109    } 
    110     erastothenes[byte_num] = byte; 
     110    eratosthenes[byte_num] = byte; 
    111111} 
    112112 
     
    115115        long           bits_needed  = CALC_PRIMES_UP_TO/2+1; // only need bits for odd numbers 
    116116        long           bytes_needed = (bits_needed/8)+1; 
    117         unsigned char *erastothenes = GB_calloc(bytes_needed, 1); // bit = 1 means "is not a prime" 
     117        unsigned char *eratosthenes = GB_calloc(bytes_needed, 1); // bit = 1 means "is not a prime" 
    118118        long           prime_count  = 0; 
    119119        long           num; 
    120120 
    121         printf("erastothenes' size = %li\n", bytes_needed); 
    122  
    123         if (!erastothenes) { 
     121        printf("eratosthenes' size = %li\n", bytes_needed); 
     122 
     123        if (!eratosthenes) { 
    124124            GB_internal_error("out of memory"); 
    125125            return; 
     
    127127 
    128128        for (num = 3; num <= CALC_PRIMES_UP_TO; num += 2) { 
    129             if (bit_value(erastothenes, num) == 0) { // is a prime number 
     129            if (bit_value(eratosthenes, num) == 0) { // is a prime number 
    130130                long num2; 
    131131                prime_count++; 
    132132                for (num2 = num*2; num2 <= CALC_PRIMES_UP_TO; num2 += num) { // with all multiples 
    133133                    if ((num2&1) == 1) { // skip even numbers 
    134                         set_bit_value(erastothenes, num2, 1); 
     134                        set_bit_value(eratosthenes, num2, 1); 
    135135                    } 
    136136                } 
     
    147147 
    148148            for (num = 3; num <= CALC_PRIMES_UP_TO; num += 2) { 
    149                 if (bit_value(erastothenes, num) == 0) { // is a prime number 
     149                if (bit_value(eratosthenes, num) == 0) { // is a prime number 
    150150                    long diff = num-last_prime; 
    151151                    if ((diff*PRIME_UNDENSITY)<num) { 
    152                         set_bit_value(erastothenes, num, 1); // delete unneeded prime 
     152                        set_bit_value(eratosthenes, num, 1); // delete unneeded prime 
    153153                    } 
    154154                    else { 
     
    166166            index = 0; 
    167167            for (num = 3; num <= CALC_PRIMES_UP_TO; num += 2) { 
    168                 if (bit_value(erastothenes, num) == 0) { // is a prime number 
     168                if (bit_value(eratosthenes, num) == 0) { // is a prime number 
    169169                    if (printed>128) { 
    170170                        printf("\n    "); 
     
    182182        } 
    183183 
    184         free(erastothenes); 
     184        free(eratosthenes); 
    185185    } 
    186186    fflush(stdout); 
     
    263263 
    264264GB_HASH *GBS_create_dynaval_hash(long user_size, GB_CASE case_sens, void (*freefun)(long)) { 
    265     /* like GBS_create_hash, but values stored in hash get free'd using 'freefun' 
     265    /* like GBS_create_hash, but values stored in hash get freed using 'freefun' 
    266266     */ 
    267267    GB_HASH *hs = GBS_create_hash(user_size, case_sens); 
     
    447447        else      e->val = val; 
    448448 
    449         if (!copyKey) free(key); // already had an entry -> delete usused mem 
     449        if (!copyKey) free(key); // already had an entry -> delete unused mem 
    450450    } 
    451451    else if (val != 0) {        // don't store 0 
     
    460460    } 
    461461    else { 
    462         if (!copyKey) free(key); // don't need an entry -> delete usused mem 
     462        if (!copyKey) free(key); // don't need an entry -> delete unused mem 
    463463    } 
    464464    return oldval; 
     
    814814    long x; 
    815815    x = (key * (long long)97)%size;     // make one multiplier a (long long) to avoid 
    816     if (x<0) x+= size;                  // int overflow and abort if compield with -ftrapv 
     816    if (x<0) x+= size;                  // int overflow and abort if compiled with -ftrapv 
    817817    return x; 
    818818} 
     
    997997        cs->entries[i].next = cs->firstfree_entry; 
    998998        cs->firstfree_entry = i; 
    999         /* delete all unused memorys */ 
     999        /* delete all unused memory */ 
    10001000        if (data || ( needed_size != cs->entries[i].sizeof_data)  ) { 
    10011001            free(cs->entries[i].data);