[Gd-chatter] r10886 - trunk/libraries/koala/sources/koala

hannes at gwydiondylan.org hannes at gwydiondylan.org
Mon Sep 4 02:04:57 CEST 2006


Author: hannes
Date: Mon Sep  4 02:04:55 2006
New Revision: 10886

Modified:
   trunk/libraries/koala/sources/koala/server.dylan
   trunk/libraries/koala/sources/koala/utils.dylan
Log:
Job: koala
* fix directory responders:
  *insert is interested in direct matches in the string-trie
    -> so call itself recursively until path is a list of zero size
     -> then try to add its object as string-trie object
    => don't depend on find-object, which looks for the longest-match
  *find is interested in longest match
    -> leave untouched

Modified: trunk/libraries/koala/sources/koala/server.dylan
==============================================================================
--- trunk/libraries/koala/sources/koala/server.dylan	(original)
+++ trunk/libraries/koala/sources/koala/server.dylan	Mon Sep  4 02:04:55 2006
@@ -836,7 +836,7 @@
 end method register-url;
 
 define method register-url-now
-    (url :: <string>, target :: <function>, #key replace?, prefix?)
+    (url :: <string>, target :: <function>, #key replace?, prefix? = #())
   let server :: <server> = *server*;
   let (bpos, epos) = trim-whitespace(url, 0, size(url));
   if (bpos = epos)
@@ -844,15 +844,9 @@
                format-string: "You cannot register an empty URL: %=",
                format-arguments: list(substring(url, bpos, epos))));
   else
+    //format(*standard-output*, "Trying to register url %s now\n", url);
     let path = split(url, separator: "/");
-    let old-target = find-object(server.url-map, path);
-    if (replace? | ~old-target)
-      add-object(server.url-map, path, pair(target, prefix?));
-    else
-      error(make(<koala-api-error>,
-                 format-string: "There is already a target registered for URL %=",
-                 format-arguments: list(url)));
-    end;
+    add-object(server.url-map, path, pair(target, prefix?), replace?: replace?);
   end;
   log-info("URL %s registered", url);
 end method register-url-now;

Modified: trunk/libraries/koala/sources/koala/utils.dylan
==============================================================================
--- trunk/libraries/koala/sources/koala/utils.dylan	(original)
+++ trunk/libraries/koala/sources/koala/utils.dylan	Mon Sep  4 02:04:55 2006
@@ -205,27 +205,27 @@
 define method add-object
     (trie :: <string-trie>, path :: <sequence>, object :: <object>,
      #key replace?)
-  let old = ~replace? & find-object(trie, path);
-  if (old)
-    signal(make(<trie-error>,
-                format-string: "Trie already contains an object (%=) for the "
-                               "given path.",
-                format-arguments: list(old)));
-  end;
-  let current-node :: <string-trie> = trie;
-  let path-size = path.size;
-  for (name in path,
-       index from 1)
-    let child-node = element(trie-children(current-node), name, default: #f);
-    if (child-node)
-      current-node := child-node;
+  //format(*standard-output*, "trying to register %d %=\n", path.size, path);
+  if (path.size = 0)
+    if (trie.trie-object = #f | replace?)
+      //format(*standard-output*, "Successfully added\n");
+      trie.trie-object := object;
     else
-      let obj = (index == path-size) & object;
-      let node = make(<string-trie>, object: obj);
-      trie-children(current-node)[name] := node;
-      current-node := node;
-    end if;
-  end for;
+      signal(make(<trie-error>,
+                  format-string: "Trie already contains an object for the given path."))
+    end;
+  else
+    let first-path = path[0];
+    let rest-path = copy-sequence(path, start: 1);
+    let children = trie-children(trie);
+    let child = element(children, first-path, default: #f);
+    unless (child)
+      let node = make(<string-trie>, object: #f);
+      children[first-path] := node;
+      child := node;
+    end;
+    add-object(child, rest-path, object, replace?: replace?)
+  end;
 end method add-object;
 
 // Find the object with the longest path, if any.  2nd return value is
@@ -250,6 +250,9 @@
             end
           end
         end method fob;
-  fob(trie, as(<list>, path), #f, #f)
+  //let (res1, res2) = fob(trie, as(<list>, path), trie.trie-object, #f);
+  //format(*standard-output*, "res1 %= res2 %=\n", res1, res2);
+  //values(res1, res2);
+  fob(trie, as(<list>, path), trie.trie-object, #f);
 end method find-object;
 



More information about the chatter mailing list