Skip to content

Commit

Permalink
convert aa.c to aarray.d
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Oct 15, 2018
1 parent 54b676b commit 6c3a60c
Show file tree
Hide file tree
Showing 13 changed files with 666 additions and 1,133 deletions.
509 changes: 0 additions & 509 deletions src/dmd/backend/aa.c

This file was deleted.

97 changes: 11 additions & 86 deletions src/dmd/backend/aa.h
Expand Up @@ -12,97 +12,22 @@
#ifndef AA_H
#define AA_H

#include <stdlib.h>
typedef size_t hash_t;

#include "tinfo.h"

struct aaA
struct AAchars
{
aaA *left;
aaA *right;
hash_t hash;
/* key */
/* value */
static AAchars* create();
static void destroy(AAchars*);
uint* get(const char *s, unsigned len);
uint length();
};

struct AArray
struct AApair
{
TypeInfo *keyti;
size_t valuesize;
size_t nodes;

aaA** buckets;
size_t buckets_length;

AArray(TypeInfo *keyti, size_t valuesize);

~AArray();

size_t length()
{
return nodes;
}

/*************************************************
* Get pointer to value in associative array indexed by key.
* Add entry for key if it is not already there.
*/

void* get(void *pkey);

void* get(char *string) { return get(&string); }

/*************************************************
* Determine if key is in aa.
* Returns:
* null not in aa
* !=null in aa, return pointer to value
*/

void* in(void *pkey);

void* in(char *string) { return in(&string); }

/*************************************************
* Delete key entry in aa[].
* If key is not in aa[], do nothing.
*/

void del(void *pkey);

/********************************************
* Produce array of keys from aa.
*/

void *keys();

/********************************************
* Produce array of values from aa.
*/

void *values();

/********************************************
* Rehash an array.
*/

void rehash();

/*********************************************
* For each element in the AArray,
* call dg(void *parameter, void *pkey, void *pvalue)
* If dg returns !=0, stop and return that value.
*/

typedef int (*dg2_t)(void *, void *, void *);

int apply(void *parameter, dg2_t dg);

private:
void *keys_x(aaA* e, void *p, size_t keysize);
void *values_x(aaA *e, void *p);
void rehash_x(aaA* olde, aaA** newbuckets, size_t newbuckets_length);
int apply_x(aaA* e, dg2_t dg, size_t keysize, void *parameter);
static AApair* create(unsigned char** pbase);
static void destroy(AApair*);
uint* get(uint start, uint end);
uint length();
};

#endif
Expand Down

0 comments on commit 6c3a60c

Please sign in to comment.