11.07.2014 Views

Flute acoustics: measurement, modelling and design - School of ...

Flute acoustics: measurement, modelling and design - School of ...

Flute acoustics: measurement, modelling and design - School of ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

248 APPENDIX B. PROGRAM LISTINGS<br />

/*<br />

Map.c<br />

By Paul Dickens, 2005<br />

Listing B.12: Map.c<br />

Map.c is a Linked List implementation <strong>of</strong> a Map (associative array).<br />

Refer to Map.h for interface details.<br />

*/<br />

#include <br />

#include "Map.h"<br />

Map createMap(void) {<br />

return createVector();<br />

}<br />

void put(Map m, double key, void* value) {<br />

int i;<br />

Pair cur;<br />

Pair newPair;<br />

/* search for key */<br />

for(i = 0; i < sizeMap(m); i++) {<br />

cur = (Pair) elementAt(m, i);<br />

if((cur->key) == key) {<br />

cur->value = value;<br />

return;<br />

}<br />

}<br />

/* if key not found, make new entry */<br />

newPair = malloc(size<strong>of</strong>(*newPair));<br />

newPair->key = key;<br />

newPair->value = value;<br />

addElement(m, newPair);<br />

}<br />

void* get(Map m, double key) {<br />

int i;<br />

Pair cur;<br />

/* search for key */<br />

for(i = 0; i < sizeMap(m); i++) {<br />

cur = (Pair) elementAt(m, i);<br />

if((cur->key) == key)<br />

return cur->value;<br />

}<br />

/* if key not found, return NULL */<br />

return NULL;<br />

}<br />

int containsKey(Map m, double key) {<br />

int i;<br />

Pair cur;<br />

/* search for key */<br />

for(i = 0; i < sizeMap(m); i++) {<br />

cur = (Pair) elementAt(m, i);<br />

if((cur->key) == key)<br />

return 1;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!