john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

ternary search trie INCOMPLETE

class Node( object ):
  """ char + ptr if part of a path, value if an endpoint """
  def __init__( self , char ):
    self.char = char
    self.value = None
    self.left = None
    self.middle = None
    self.right=None

class TST( object ):
  def __init__(self):
    self.root = None

  def put( self, string ):
    self.putr( self.root, string, 0 )

  def putr( self, node, key, depth):
    c = key[ depth ]
    if not node:
      node = Node( c )
    if len( key ) == depth + 1:
      node.value = key
      return
    else:
      next = depth+ 1
      if key[next] < c:
        self.putr( node.left, key, next)
      elif key[next] == c:
        self.putr( node.middle, key, next)
      else:
        self.putr( node.right, key, next)


if __name__=='__main__':
  n = Node( 's' )
  print n.char
  t = TST()
  t.put( 'a' )

  • « binary search tree
  • Make build compile from source uninstall »

Published

Jul 21, 2013

Category

python

~100 words

Tags

  • incomplete 22
  • python 180
  • search 8
  • ternary 2
  • trie 1