19-Section-Handout - CS107 Spring 2007 Handout 19 Section...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS107 Handout 19 Spring 2007 April 25, 2007 Section Handout The multitable allows a client to associate keys (of any type) with one or more values (of any type). It operates somewhat like the C++ map class, except that it’s written in C and it allows multiple values to be bound to a single key. The multitable shouldn’t re-implement the hashset and the vector , but instead should be layered on top of them. A single key’s collection of values should be stored in a C vector , and each key/ vector -of-values pair will be stored in a C hashset . The pair itself is a manually managed chunk of memory, the size being determined by the size of the key and the size of a vector . I’ve designed the multitable struct for you, but you’ll be implementing three functions to demonstrate your understanding of all the low-level C functions we’ve been studying. Here’s the reduced .h file outlining the signatures of those three functions. typedef int (*MultiTableHashFunction)(const void *keyAddr, int numBuckets); typedef int (*MultiTableCompareFunction)(const void *keyAddr1, const void *keyAddr2); typedef void (*MultiTableMapFunction)(void *keyAddr, void *valueAddr, void *auxData); typedef struct { hashset mappings; int keySize; int valueSize; } multitable; void MultiTableNew(multitable *mt, int keySizeInBytes, int valueSizeInBytes, int numBuckets, MultiTableHashFunction hash, MultiTableCompareFunction compare); void MultiTableEnter(multitable *mt, const void *keyAddr, const void *valueAddr); void MultiTableMap(multitable *mt, MultiTableMapFunction map, void *auxData); Some constraints and clarifications: You needn’t worry about alignment restrictions. The bytes making up a key must be laid out and replicated according to the diagram above. The bytes making up a value must be replicated as elements of the vector of values.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

19-Section-Handout - CS107 Spring 2007 Handout 19 Section...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online