Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert aa.c to aarray.d #8831

Merged
merged 1 commit into from Oct 17, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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