/[eiffelstudio]/FreeELKS/trunk/library/structures/cursor_tree/two_way_cursor_tree.e
ViewVC logotype

Contents of /FreeELKS/trunk/library/structures/cursor_tree/two_way_cursor_tree.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 91477 - (show annotations)
Sun Jan 14 09:47:13 2007 UTC (13 years ago) by ericb
File size: 3011 byte(s)
Synchronized with ISE 6.0.65740
1 indexing
2
3 description:
4 "Cursor trees implemented in two-way linked representation"
5 legal: "See notice at end of class."
6
7 status: "See notice at end of class."
8 names: two_way_cursor_tree, cursor_tree;
9 access: cursor, membership;
10 representation: recursive, linked;
11 contents: generic;
12 date: "$Date$"
13 revision: "$Revision$"
14
15 class TWO_WAY_CURSOR_TREE [G] inherit
16
17 RECURSIVE_CURSOR_TREE [G]
18 redefine
19 put_right, subtree,
20 active, cursor, is_leaf
21 end
22
23 create
24
25 make, make_root
26
27 feature -- Initialization
28
29 make is
30 -- Create an empty tree.
31 local
32 dummy: G
33 do
34 create above_node.make (dummy)
35 active := above_node
36 ensure
37 is_above: above
38 is_empty: is_empty
39 end
40
41 make_root (v: G) is
42 -- Create a tree with `v' as root.
43 do
44 make
45 put_root (v)
46 end
47
48 feature -- Status report
49
50 full: BOOLEAN is False
51 -- Is tree filled to capacity? (Answer: no.)
52
53 prunable: BOOLEAN is True
54
55 is_leaf: BOOLEAN is
56 do
57 if not off then
58 Result := not below and then active.arity = 0
59 end
60 end
61
62 feature -- Access
63
64 cursor: TWO_WAY_CURSOR_TREE_CURSOR [G] is
65 -- Current cursor position
66 do
67 create Result.make (active, active_parent, after, before, below)
68 end
69
70 feature -- Element change
71
72 put_right (v: G) is
73 -- Add `v' to the right of cursor position.
74 do
75 if below then
76 active.child_put_right (v)
77 active.child_forth
78 active_parent := active
79 active := active_parent.child
80 below := False
81 elseif before then
82 active_parent.child_put_left (v)
83 active_parent.child_back
84 active := active_parent.child
85 else
86 active_parent.child_put_right (v)
87 end
88 end
89
90 put_root (v: G) is
91 -- Put `v' as root of an empty tree.
92 require
93 is_empty: is_empty
94 do
95 above_node.child_put_right (v)
96 active_parent := above_node
97 active := active_parent.child
98 ensure
99 is_root: is_root
100 count = 1
101 end
102
103 put_child (v: G) is
104 -- Put `v' as child of a leaf.
105 require
106 is_leaf: is_leaf
107 do
108 down (0)
109 put_right (v)
110 end
111
112 feature -- Duplication
113
114 subtree: like Current is
115 -- Subtree rooted at current node.
116 do
117 create Result.make_root (item)
118 Result.fill_from_active (Current)
119 end
120
121 feature {LINKED_CURSOR_TREE} -- Implementation
122
123 new_tree: like Current is
124 -- A newly created instance of the same type.
125 -- This feature may be redefined in descendants so as to
126 -- produce an adequately allocated and initialized object.
127 do
128 create Result.make
129 end
130
131 feature {NONE} -- Implementation
132
133 active: TWO_WAY_TREE [G];
134 -- Current node
135
136 indexing
137 library: "EiffelBase: Library of reusable components for Eiffel."
138 copyright: "Copyright (c) 1984-2006, Eiffel Software and others"
139 license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
140 source: "[
141 Eiffel Software
142 356 Storke Road, Goleta, CA 93117 USA
143 Telephone 805-685-1006, Fax 805-685-6869
144 Website http://www.eiffel.com
145 Customer support http://support.eiffel.com
146 ]"
147
148
149
150
151
152
153
154 end -- class TWO_WAY_CURSOR_TREE
155
156
157

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23