Changeset 2156

Show
Ignore:
Timestamp:
07/01/08 09:32:03 (3 months ago)
Author:
mspiegel
Message:

[Library] added toDotString() method in skip trees that will create a DOT formatted string for GraphViz? pretty graphics construction.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Library/incomplete/SkipTree.fsi

    r2140 r2156  
    2323    getter toString():String 
    2424 
     25    getter count():ZZ32 
     26 
    2527    opr |self| : ZZ32 
    26  
     28     
    2729    (** Takes a querykey as input and returns either a Just[\Value\] 
    2830      * object if the (key,value) pair lives in this map, or 
  • trunk/Library/incomplete/SkipTree.fss

    r2140 r2156  
    2525 
    2626    getter toString():String 
     27     
     28    getter toDotString(name:String):String 
     29     
     30    getter count():ZZ32 
    2731 
    2832    opr |self| : ZZ32 
     
    7074    getter toString():String = "(EMPTY)" 
    7175 
     76    getter toDotString(name:String):String = "digraph " || name || " {}" 
     77 
     78    getter count():ZZ32 = 0 
     79 
    7280    opr |self| : ZZ32 = 0 
    7381 
     
    9199    getter toString():String = root.toString() 
    92100 
     101    getter toDotString(name:String):String =  "digraph " || name  || (" {" //  
     102        "node [shape=record];" // "ordering=out;"  //  root.toDotString() ) || "}"  
     103 
     104    getter count():ZZ32 = root.count() 
     105 
    93106    opr |self| : ZZ32 = |root| 
    94  
     107     
    95108    find(querykey : Key) : Maybe[\Value\] = root.find(querykey) 
    96109 
     
    120133    getter toString() : String = keys "" values "" children " h" height 
    121134 
     135    getter toDotString() : String = do 
     136        name = keys[0] 
     137        s1 = "node" || name || " [label=\"" || childrenDotString() || "\"];"// 
     138        s2 = children.generate[\String\](StringReduction,fn (child) => typecase child of 
     139                Just[\Node[\Key,Value\]\] => child.get().toDotString() 
     140                else => "" end)  
     141        s3 = children.indexValuePairs().generate[\String\](StringReduction,  
     142            fn (i,child) => typecase child of 
     143                Just[\Node[\Key,Value\]\] => do 
     144                    childname = child.get().keys[0] 
     145                    "\"node" || name || "\":" || i || "-> \"node" || childname || "\";"//  
     146                end 
     147                else => "" end) 
     148        s1 s2 s3 
     149    end 
     150 
     151    getter childrenDotString() : String = do 
     152        s1 = keys.indexValuePairs().generate[\String\](StringReduction,  
     153            fn (i, key) => "<" || i  || "> " || key || " | ") 
     154        s1 || "<" || |keys| || "> h" || height 
     155    end 
     156     
     157    getter count() : ZZ32 = 1 + children.generate[\Number\](SumReduction,  
     158        fn (child) => typecase child of 
     159                Just[\Node[\Key,Value\]\] => child.get().count() 
     160                else => 0 end) 
     161 
    122162    opr |self| : ZZ32 = |keys| + children.generate[\Number\](SumReduction,  
    123163        fn (child) => typecase child of 
    124164                Just[\Node[\Key,Value\]\] => |child.get()| 
    125                 else => 0 end) 
    126      
     165                else => 0 end)     
    127166 
    128167    opr =(self, other:Node[\Key,Value\]): Boolean = 
  • trunk/Library/incomplete/SkipTreeTest.fss

    r2140 r2156  
    100100                elif NOT oldvalue.isEmpty() AND (|tree| =/= |newTree|) then 
    101101                    fail("Skip Tree has grown on attempt to insert an existing key!") 
    102                 end  
     102                end 
    103103                tree := newTree 
    104104            end 
     105            (* println tree.toDotString("WallE") *) 
     106            (* println (|tree| / tree.count()) *) 
    105107        end 
    106108    end