예제 #1
0
def main():
  if (len(sys.argv)>1):
    filename = sys.argv[1]
  else:
    filename = "test_data.txt"

  infile = open(filename,'r')

  for line in infile:
    (name,start,end) = line.strip().split(' ')
    print "%s, %s, %s" % (name,start,end)

  i = IntervalTree()

# 1,3,4,5,6,8,10
# use a mix of insert and load
# to test the total functionality
  """
           5
        3     8
      1  4   6  10
  """
  i.insert(6)
  i.insert(3)
  i.insert(3)
  i.insert(4)
  i.load(1)
  i.load(5)
  i.load(8)
  i.load(10)

  i.unload()
  print ""

  i.inorder( debug2 )

  # time to test insertions
  i.add(3,8,"yohann")
  print ""
  i.inorder( debug2 )
  i.inorder( debug3 )
예제 #2
0
def main():
  """
  Function for testing interval tree
  """
  # default filename
  if (len(sys.argv)>1):
    filename = sys.argv[1]
  else:
    filename = "composers.txt"

  # open our input text file
  infile = open(filename,'r')
  data = []

  # process the file
  for line in infile:
    (name,start,end) = line.strip().split(' ')
    print "%s, %s, %s" % (name,start,end)
    data.append((int(start),int(end),name))
  print ""

  # define interval-tree instance
  i = IntervalTree()

  """
  # special insert
  i.insert(1874)

  i.insert(1779)
  i.insert(1951)

  i.insert(1672)
  i.insert(1828)
  i.insert(1907)
  i.insert(1971)

  i.insert(1585)
  i.insert(1756)
  i.insert(1791)
  i.insert(1843)
  i.insert(1888)
  ################
  """

  # load pts
  for tup in data:
    i.load(tup[0])
    i.load(tup[1])
  # don't forget to "unload"
  i.unload()

  # insert objects into interval-tree
  for tup in data:
    #s = StringWrapper(tup[2])
    #i.add(tup[0],tup[1],s)
    i.add(tup[0],tup[1],tup[2])

  # dump tree contents
  i.inorder( debug2 )
  print ""
  i.inorder( debug3 )
  print ""

  #while True:
    #ep = int(raw_input())
    #print "date: %d" % ep, ["%s" % obj for obj in i.query_endpoint( ep )]


  # test endpoint
  for ep in [1400,1828,1830,1907,1908,1780,1888,1887,1757]:
    #print "date: %d" % ep, ["%s" % obj for obj.name in i.query_endpoint( ep )]
    print "date: %d" % ep, ["%s" % obj for obj in i.query_endpoint( ep )]