1implement Objstore; 2include "sys.m"; 3 sys: Sys; 4include "draw.m"; 5include "sets.m"; 6 None: import Sets; 7include "../spree.m"; 8 spree: Spree; 9 Object, Clique: import spree; 10include "objstore.m"; 11 12clique: ref Clique; 13archiveobjs: array of list of (string, ref Object); 14 15init(mod: Spree, g: ref Clique) 16{ 17 sys = load Sys Sys->PATH; 18 spree = mod; 19 clique = g; 20} 21 22unarchive() 23{ 24 archiveobjs = array[27] of list of (string, ref Object); 25 for (i := 0; i < len clique.objects; i++) { 26 obj := clique.objects[i]; 27 if (obj != nil && (nm := obj.getattr("§")) != nil) { 28 (n, toks) := sys->tokenize(nm, " "); 29 for (; toks != nil; toks = tl toks) { 30 x := strhash(hd toks, len archiveobjs); 31 archiveobjs[x] = (hd toks, obj) :: archiveobjs[x]; 32 } 33 obj.setattr("§", nil, None); 34 } 35 } 36} 37 38setname(obj: ref Object, name: string) 39{ 40 nm := obj.getattr("§"); 41 if (nm != nil) 42 nm += " " + name; 43 else 44 nm = name; 45 obj.setattr("§", nm, None); 46} 47 48get(name: string): ref Object 49{ 50 for (al := archiveobjs[strhash(name, len archiveobjs)]; al != nil; al = tl al) 51 if ((hd al).t0 == name) 52 return (hd al).t1; 53 return nil; 54} 55 56# from Aho Hopcroft Ullman 57strhash(s: string, n: int): int 58{ 59 h := 0; 60 m := len s; 61 for(i := 0; i<m; i++){ 62 h = 65599 * h + s[i]; 63 } 64 return (h & 16r7fffffff) % n; 65} 66