Here's the fuzzy problem: I'm slowly writing an interpreter for the X16, and I therefore need a symbol table. HOWEVER, I can't really guarantee that I'll have much system RAM for neat data structures. So I'm looking at the banked RAM to store my hashtable. ALL of it if possible.
THAT has implications ... for example I don't think malloc() and free() are really going to work in banked RAM.
SO:
***
I'm trying a "cheap" banked string map implementation using a list. The idea is to have a small, slow, symbol table (less than 1000 entries, spanning several RAM banks) with a minimum of management code (and a minimum of system RAM). It doesn't even hash.
I understand that it will be slow and linear. That's OK.
My thoughts go like this:
RAM bank memory can be chopped up into 256 segments like this:
typedef struct {
unsigned char header;
char data[31];
} BANK_LIST_SEGMENT;
BANK_LIST_SEGMENT* bank_list[256]; // = 8192 bytes = 1 bank.
Key:Value entries are segment-aligned: the shortest mapping is 32 bytes, and the increment is 32 bytes, to a max of 288 bytes. I'll try ways to optimize this -- for example, reducing the segment length to 24 bytes. Or scrapping it for dynamic memory management, since this is a solved problem... especially if code size doesn't really change....
I can run through the list and check the first byte of each segment.
If it's a zero, then that hunk of 32 bytes is unallocated.
If it's a printable PETSCII, then it's allocated and part of the current pair.
If it's 1 thru 31, then it's a new pair, and the key length is given (1-31 characters), so I know where the value string starts. (Or I can limit it to 30 chars, with a "31" indicating the start of the value string of the current pair for convenience.)
Keeping the key length known AND under 32 characters lets me do strncmp's safely (?). I may have a problem with values if they don't end in zeros -- so I have to make sure then end in zero. This may have length implications, especially if the zero intersects with byte zero of the next segment. That means I'll have to store the length of the value string, which OK FINE.
Maybe this has already been done in a better way already. I know hashes have been done-to-death in various ways. Thoughts?