summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/asymptote/map.asy
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2021-02-24 18:33:44 +0000
committerKarl Berry <karl@freefriends.org>2021-02-24 18:33:44 +0000
commitdbd941ed19b558edd09219a372b2b0832957b283 (patch)
tree9c6af6f3924d8b1fff6638e510a907306342fa7d /Master/texmf-dist/asymptote/map.asy
parenta360890a6c2a4befab6b48084d0731ad09c46631 (diff)
asymptote 2.69 support files
git-svn-id: svn://tug.org/texlive/trunk@57876 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/asymptote/map.asy')
-rw-r--r--Master/texmf-dist/asymptote/map.asy40
1 files changed, 40 insertions, 0 deletions
diff --git a/Master/texmf-dist/asymptote/map.asy b/Master/texmf-dist/asymptote/map.asy
new file mode 100644
index 00000000000..2b2277b9568
--- /dev/null
+++ b/Master/texmf-dist/asymptote/map.asy
@@ -0,0 +1,40 @@
+// 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);
+
+ 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 map {
+ keyValue[] M;
+ bool operator < (keyValue a, keyValue b) {return a.key < b.key;}
+
+ 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;
+ }
+ }
+",true);
+
+ type("map",name);
+}
+