diff options
Diffstat (limited to 'graphics/asymptote/base/map.asy')
-rw-r--r-- | graphics/asymptote/base/map.asy | 62 |
1 files changed, 29 insertions, 33 deletions
diff --git a/graphics/asymptote/base/map.asy b/graphics/asymptote/base/map.asy index 2b2277b956..06c61f7b4b 100644 --- a/graphics/asymptote/base/map.asy +++ b/graphics/asymptote/base/map.asy @@ -1,40 +1,36 @@ -// Create a struct <name> parameterized by types <key> and <value>, -// that maps keys to values, defaulting to the value in <default>. -void mapTemplate(string name, string key, string value, string default) -{ - type(key,"Key"); - type(value,"Value"); - eval("Value default="+default,true); +typedef import(Key, Value); - eval(" - struct keyValue { - Key key; - Value T; - void operator init(Key key) { - this.key=key; - } - void operator init(Key key, Value T) { - this.key=key; - this.T=T; - } +struct keyValue { + Key key; + Value value; + void operator init(Key key) { + this.key=key; } + void operator init(Key key, Value value) { + this.key=key; + this.value=value; + } +} - struct map { - keyValue[] M; - bool operator < (keyValue a, keyValue b) {return a.key < b.key;} +// Map keys to values, defaulting to the value default. - void add(Key key, Value T) { - keyValue m=keyValue(key,T); - M.insert(search(M,m,operator <)+1,m); - } - Value lookup(Key key) { - int i=search(M,keyValue(key),operator <); - if(i >= 0 && M[i].key == key) return M[i].T; - return default; - } +struct map { + keyValue[] M; + int Default; + + void operator init(Value Default) { + this.Default=Default; } -",true); - type("map",name); -} + bool operator < (keyValue a, keyValue b) {return a.key < b.key;} + void add(Key key, Value value) { + keyValue m=keyValue(key,value); + M.insert(search(M,m,operator <)+1,m); + } + Value lookup(Key key) { + int i=search(M,keyValue(key),operator <); + if(i >= 0 && M[i].key == key) return M[i].value; + return Default; + } +} |