Paste: simple binary trees in factor
Author: | slava |
Mode: | factor |
Date: | Thu, 13 Nov 2008 06:13:49 |
Plain Text |
USING: accessors kernel sequences math math.order ;
IN: stack-checker.recursive-state.tree
TUPLE: node value key hashcode left right ;
GENERIC: lookup ( key node -- value/f )
M: f lookup nip ;
: decide ( key node -- key node ? )
over hashcode over hashcode>> <= ; inline
M: node lookup
2dup key>> eq?
[ nip value>> ]
[ decide [ left>> ] [ right>> ] if lookup ] if ;
GENERIC: store ( value key node -- node' )
M: f store drop dup hashcode f f node boa ;
M: node store
clone decide
[ [ store ] change-left ]
[ [ store ] change-right ] if ;
New Annotation