Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 24 additions & 26 deletions ee/erl/include/hashtab.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ This implements a hash table.
--------------------------------------------------------------------
*/

#ifndef STANDARD
#include "standard.h"
#endif
#ifndef HASHTAB_H
#define HASHTAB_H

#ifndef HASHTAB
#define HASHTAB
#include "standard.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -43,25 +41,25 @@ extern "C" {

struct hitem
{
ub1 *key; /* key that is hashed */
ub4 keyl; /* length of key */
void *stuff; /* stuff stored in this hitem */
ub4 hval; /* hash value */
struct hitem *next; /* next hitem in list */
const char *key; /* key that is hashed */
size_t keyl; /* length of key */
void *stuff; /* stuff stored in this hitem */
size_t hval; /* hash value */
struct hitem *next; /* next hitem in list */
};
typedef struct hitem hitem;


struct htab
{
struct hitem **table; /* hash table, array of size 2^logsize */
word logsize; /* log of size of table */
size_t mask; /* (hashval & mask) is position in table */
ub4 count; /* how many items in this hash table so far? */
ub4 apos; /* position in the array */
int logsize; /* log of size of table */
size_t mask; /* (hashval & mask) is position in table */
size_t count; /* how many items in this hash table so far? */
size_t apos; /* position in the array */
struct hitem *ipos; /* current item in the array */
struct reroot *space; /* space for the hitems */
ub4 bcount; /* # hitems useable in current block */
size_t bcount; /* # hitems useable in current block */
};
typedef struct htab htab;

Expand All @@ -77,7 +75,7 @@ typedef struct htab htab;
RETURNS:
the new table
*/
extern htab *hcreate(/*_ word logsize _*/);
extern htab *hcreate(int logsize);


/* hdestroy - destroy a hash table
Expand All @@ -88,16 +86,16 @@ extern htab *hcreate(/*_ word logsize _*/);
RETURNS:
nothing
*/
extern void hdestroy(/*_ htab *t _*/);
extern void hdestroy(htab *t);


/* hcount, hkey, hkeyl, hstuff
ARGUMENTS:
t - the hash table
RETURNS:
hcount - (ub4) The number of items in the hash table
hkey - (ub1 *) key for the current item
hkeyl - (ub4) key length for the current item
hcount - (size_t) The number of items in the hash table
hkey - (const char *) key for the current item
hkeyl - (size_t) key length for the current item
hstuff - (void *) stuff for the current item
NOTE:
The current position always has an item as long as there
Expand All @@ -121,7 +119,7 @@ extern void hdestroy(/*_ htab *t _*/);
TRUE if the item exists, FALSE if it does not.
If the item exists, moves the current position to that item.
*/
extern word hfind(/*_ htab *t, ub1 *key, ub4 keyl _*/);
extern int hfind(htab *t, const char *key, size_t keyl);


/* hadd - add a new item to the hash table
Expand All @@ -134,7 +132,7 @@ extern word hfind(/*_ htab *t, ub1 *key, ub4 keyl _*/);
RETURNS:
FALSE if the operation fails (because that key is already there).
*/
extern word hadd(/*_ htab *t, ub1 *key, ub4 keyl, void *stuff _*/);
extern int hadd(htab *t, const char *key, size_t keyl, void *stuff);


/* hdel - delete the item at the current position
Expand All @@ -153,7 +151,7 @@ extern word hadd(/*_ htab *t, ub1 *key, ub4 keyl, void *stuff _*/);
hdel(tab);
}
*/
extern word hdel(/* htab *t */);
extern int hdel(htab *t);


/* hfirst - move position to the first item in the table
Expand All @@ -163,7 +161,7 @@ extern word hdel(/* htab *t */);
FALSE if there is no current item (meaning the table is empty)
NOTE:
*/
extern word hfirst(/*_ htab *t _*/);
extern int hfirst(htab *t);


/* hnext - move position to the next item in the table
Expand Down Expand Up @@ -193,7 +191,7 @@ extern word hfirst(/*_ htab *t _*/);
NOTE:
This is private to hashtab; do not use it externally.
*/
extern word hnbucket(/*_ htab *t _*/);
extern int hnbucket(htab *t);


/* hstat - print statistics about the hash table
Expand All @@ -218,4 +216,4 @@ extern void hstat(/*_ htab *t _*/);
}
#endif

#endif /* HASHTAB */
#endif /* HASHTAB_H */
14 changes: 6 additions & 8 deletions ee/erl/include/lookupa.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@ Source is http://burtleburtle.net/bob/c/lookupa.h
------------------------------------------------------------------------------
*/

#ifndef STANDARD
#include "standard.h"
#endif
#ifndef LOOKUPA_H
#define LOOKUPA_H

#ifndef LOOKUPA
#define LOOKUPA
#include "standard.h"

#ifdef __cplusplus
extern "C" {
#endif

#define CHECKSTATE 8
#define hashsize(n) ((ub4)1<<(n))
#define hashsize(n) ((size_t)1<<(n))
#define hashmask(n) (hashsize(n)-1)

extern ub4 lookup(/*_ ub1 *k, ub4 length, ub4 level _*/);
extern void checksum(/*_ ub1 *k, ub4 length, ub4 *state _*/);
extern uint32_t lookup(const char *k, size_t length, uint32_t level);
extern void checksum(const char *k, size_t length, uint32_t *state);

#ifdef __cplusplus
}
Expand Down
20 changes: 9 additions & 11 deletions ee/erl/include/recycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ This also decreases memory fragmentation, and freeing all structures
--------------------------------------------------------------------
*/

#ifndef STANDARD
#include "standard.h"
#endif
#ifndef RECYCLE_H
#define RECYCLE_H

#ifndef RECYCLE
#define RECYCLE
#include "standard.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -39,21 +37,21 @@ struct reroot
struct recycle *trash; /* list of deleted items */
size_t size; /* size of an item */
size_t logsize; /* log_2 of number of items in a block */
word numleft; /* number of bytes left in this block */
int numleft; /* number of bytes left in this block */
};
typedef struct reroot reroot;

/* make a new recycling root */
extern reroot *remkroot(/*_ size_t mysize _*/);
extern reroot *remkroot(size_t mysize);

/* free a recycling root and all the items it has made */
extern void refree(/*_ struct reroot *r _*/);
extern void refree(struct reroot *r);

/* get a new (cleared) item from the root */
#define renew(r) ((r)->numleft ? \
(((char *)((r)->list+1))+((r)->numleft-=(r)->size)) : renewx(r))

extern char *renewx(/*_ struct reroot *r _*/);
extern char *renewx(struct reroot *r);

/* delete an item; let the root recycle it */
/* void redel(/o_ struct reroot *r, struct recycle *item _o/); */
Expand All @@ -64,10 +62,10 @@ extern char *renewx(/*_ struct reroot *r _*/);

/* malloc, but exit program if no joy */
/* use plain free() to free memory allocated by remalloc() */
extern char *remalloc(/*_ size_t len _*/);
extern char *remalloc(size_t len);

#ifdef __cplusplus
}
#endif

#endif /* RECYCLE */
#endif /* RECYCLE_H */
59 changes: 9 additions & 50 deletions ee/erl/include/standard.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
Standard definitions and types, Bob Jenkins
------------------------------------------------------------------------------
*/
#ifndef STANDARD
# define STANDARD
# ifndef STDIO
# include <stdio.h>
# define STDIO
# endif
# ifndef STDDEF
# include <stddef.h>
# define STDDEF
# endif
#ifndef STANDARD_H
#define STANDARD_H

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

#define UB8MAXVAL 0xffffffffffffffffLL
#define UB8BITS 64
#define SB8MAXVAL 0x7fffffffffffffffLL
Expand All @@ -25,45 +22,7 @@ Standard definitions and types, Bob Jenkins
#define UB1MAXVAL 0xff
#define UB1BITS 8
#define SB1MAXVAL 0x7f
#ifdef _EE
#include <tamtypes.h>
typedef u64 ub8;
typedef s64 sb8;
typedef u32 ub4;
typedef s32 sb4;
typedef u16 ub2;
typedef s16 sb2;
typedef u8 ub1;
typedef s8 sb1;
#else
typedef unsigned long long ub8;
typedef signed long long sb8;
typedef unsigned long int ub4; /* unsigned 4-byte quantities */
typedef signed long int sb4;
typedef unsigned short int ub2;
typedef signed short int sb2;
typedef unsigned char ub1;
typedef signed char sb1; /* signed 1-byte quantities */
#endif
typedef int word; /* fastest type available */

#define bis(target,mask) ((target) |= (mask))
#define bic(target,mask) ((target) &= ~(mask))
#define bit(target,mask) ((target) & (mask))
#ifndef min
# define min(a,b) (((a)<(b)) ? (a) : (b))
#endif /* min */
#ifndef max
# define max(a,b) (((a)<(b)) ? (b) : (a))
#endif /* max */
#ifndef align
# define align(a) (((ub4)a+(sizeof(void *)-1))&(~(sizeof(void *)-1)))
#endif /* align */
#ifndef abs
# define abs(a) (((a)>0) ? (a) : -(a))
#endif
#define TRUE 1
#define FALSE 0
#define SUCCESS 0 /* 1 on VAX */
#define align(a) (((uint32_t)a+(sizeof(void *)-1))&(~(sizeof(void *)-1)))

#endif /* STANDARD */
#endif /* STANDARD_H */
6 changes: 3 additions & 3 deletions ee/erl/src/erl.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ static void add_loosy(struct erl_record_t * erl, u8 * reloc, int type, const cha
l->next = hstuff(loosy_relocs);
hstuff(loosy_relocs) = l;
} else {
hkey(loosy_relocs) = (ub1 *)strdup(symbol);
hkey(loosy_relocs) = strdup(symbol);
}
}

Expand All @@ -530,7 +530,7 @@ static int fix_loosy(struct erl_record_t * provider, const char * symbol, u32 ad
count++;
}
r_destroy_loosy(hstuff(loosy_relocs));
free(hkey(loosy_relocs));
free((void *)hkey(loosy_relocs));
hdel(loosy_relocs);
}

Expand Down Expand Up @@ -1177,7 +1177,7 @@ void erl_flush_symbols(struct erl_record_t * erl) {

if (hfirst(erl->symbols)) do {
destroy_symbol((struct symbol_t *) hstuff(erl->symbols));
free(hkey(erl->symbols));
free((void *)hkey(erl->symbols));
hdel(erl->symbols);
} while (hcount(erl->symbols));

Expand Down
Loading
Loading