Thanks for your help. I wonder why there is no IRC for new comers .....
But, I wrote a piece of code (runnable :P) ,I just don't like it .
All those nested makers are necessary?
If someone can hint me on a better way to program in I will be happier.

And .. why Spider,init(C) in not written {Spider,init(C)} ? I'm missing the point.

Cheers
Paolino

functor
import
   OS
   Browser(browse:Browse) %Import Browse form Browser module
export new:Cluster splitter:Splitter
define
   D=Dictionary
   class Inspector meth get(A ?X) [EMAIL PROTECTED] end meth set(A X) A:=X end 
end
   class ClusterCell from Inspector
      attr
         father
         children id
         value
      meth isTop(C) [EMAIL PROTECTED] end
      meth top(R)
         if {self isTop($)} then R=self
         else
            {{self father($)} top(R)}
         end
      end
      meth addChild(C) {D.put @children {C id($)} C} end
      meth father(F) [EMAIL PROTECTED] end
      meth setFather(F) father:=F end
      meth prole(P) [EMAIL PROTECTED] end
      meth id(I) [EMAIL PROTECTED] end
      meth init(Value Father)
         value:=Value
         id:={NewName}
         children:={D.new}
         father:=Father
         if Father \= none then
            {Father addChild(self)}
         end
      end
      meth isLeaf(C) [EMAIL PROTECTED] end
   end
   proc {Cluster Values Father}
      Father ={New ClusterCell init(none none)}
      for V in Values do
         {New ClusterCell init(V Father) _}
      end
   end
   local Move={NewName} in % protected
      class Spider
         attr pos move:Move
         meth init(C)
            pos := C
         end
         meth !Move
            Sons=if [EMAIL PROTECTED] isLeaf($)} then nil else {D.items [EMAIL 
PROTECTED] prole($)}} end
            Father=if [EMAIL PROTECTED] isTop($)} then nil else [EMAIL 
PROTECTED] father($)}] end
            [EMAIL PROTECTED]|{Flatten [Father Sons]}
            Which={OS.rand} mod {Length Choices} + 1
         in
            pos := {Nth Choices Which}
         end
      end
   end

   % a procedure to split a dict randomly

   proc {Split From To}
      for Key#Value in  {D.entries From} do
         if {OS.rand} mod 2 == 0 then
            {D.remove From Key}
            To.Key := Value
         end
      end
      {Browse splitted}
   end

   class Splitter from Spider
      attr max
      meth init(C Max)
         max := Max
         Spider,init(C)
      end
      meth run
         {Browse @pos}
         local
            proc {Check}
               if {Length {D.keys [EMAIL PROTECTED] prole($)}}} > @max then
                  if [EMAIL PROTECTED] father($)} == none then
                     [EMAIL PROTECTED] setFather({New ClusterCell init(none 
none)})}
                     [EMAIL PROTECTED] father($)} addChild(@pos)}
                  end   
                  local Brother={New ClusterCell init(none [EMAIL PROTECTED] 
father($)})}
                  in [EMAIL PROTECTED] father($)} addChild(Brother)}
                     {Split [EMAIL PROTECTED] prole($)} {Brother prole($)}}
                  end
               end
               {self @move}
               {Check}
            end
         in
            {Check}
         end
      end
   end

end

                
___________________________________ Yahoo! Messenger: chiamate gratuite in tutto il mondo http://it.messenger.yahoo.com


_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to