PageRenderTime 50ms CodeModel.GetById 47ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/wrappers/glib/examples/tree_example.e

http://github.com/tybor/Liberty
Specman e | 68 lines | 56 code | 9 blank | 3 comment | 2 complexity | 0c21d7f9fc3d9e16cb0e00c9078b8f50 MD5 | raw file
 1indexing
 2	
 3	copyright: "(C) 2007 Paolo Redaelli "
 4	license: "LGPL v2 or later"
 5	date: "$Date:$"
 6	revision: "$REvision:$"
 7
 8class TREE_EXAMPLE
 9
10creation make
11
12feature
13	tree: G_TREE[G_DATE, G_STRING]
14	first: G_STRING
15feature
16	make is
17		do
18			setup
19			test
20		end
21
22	setup is
23		do
24			create tree.make(agent compare)
25
26			tree.insert_value (create {G_DATE}.make_dmy(1,1,1970),
27									 create {G_STRING}.from_string("Epoch"))
28			tree.insert_value (create {G_DATE}.make_dmy(10,3,1984),
29									 create {G_STRING}.from_string("Gnu birthday"))
30			tree.insert_value (create {G_DATE}.make_dmy(17,9,1991),
31									 create {G_STRING}.from_string("Linux birthday"))
32		end
33
34	test is
35		local
36			a_date: G_DATE;
37			test_dates: FAST_ARRAY[TUPLE[INTEGER_8,INTEGER_8,INTEGER_16]]; i: INTEGER
38			event: G_STRING
39		do
40			test_dates:={FAST_ARRAY[TUPLE[INTEGER_8,INTEGER_8,INTEGER_16]]
41			<< [17,9,1991],
42				[10,7,1976],
43				[10,3,1984] >> }
44			from i:=test_dates.lower
45			until i>test_dates.upper
46			loop
47				create a_date.from_tuple(test_dates.item(i))
48				event:=tree.lookup(a_date)
49				if event/=Void
50				 then print (a_date.to_string+": "+event.to_string+"%N")
51				else print ("No known events on "+a_date.to_string+"%N")
52				end
53				i:=i+1
54			end
55			-- from i:=list.get_new_iterator; i.start until i.is_off loop
56			-- print (i.item.to_string) print (", ") i.next end print
57			-- ("%N")
58		end
59					 
60	compare(a_date,another_date: COMPARABLE_C_STRUCT): INTEGER is
61		require 
62			date_not_void: a_date/=Void
63			another_not_void: another_date/=Void
64		do
65			Result:=a_date.compare(another_date)
66		end
67end
68