/[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 91424 - (show annotations)
Tue Oct 26 18:39:32 2004 UTC (15 years, 2 months ago) by manus_eiffel
File size: 3425 byte(s)
Initial revision

1 indexing
2
3 description:
4 "Cursor trees implemented in two-way linked representation"
5
6 status: "See notice at end of class"
7 names: two_way_cursor_tree, cursor_tree;
8 access: cursor, membership;
9 representation: recursive, linked;
10 contents: generic;
11 date: "$Date$"
12 revision: "$Revision$"
13
14 class TWO_WAY_CURSOR_TREE [G] inherit
15
16 RECURSIVE_CURSOR_TREE [G]
17 redefine
18 put_right, subtree,
19 active, cursor, is_leaf
20 end
21
22 create
23
24 make, make_root
25
26 feature -- Initialization
27
28 make is
29 -- Create an empty tree.
30 local
31 dummy: G
32 do
33 create above_node.make (dummy)
34 active := above_node
35 ensure
36 is_above: above
37 is_empty: is_empty
38 end
39
40 make_root (v: G) is
41 -- Create a tree with `v' as root.
42 do
43 make
44 put_root (v)
45 end
46
47 feature -- Status report
48
49 full: BOOLEAN is False
50 -- Is tree filled to capacity? (Answer: no.)
51
52 prunable: BOOLEAN is True
53
54 is_leaf: BOOLEAN is
55 do
56 if not off then
57 Result := not below and then active.arity = 0
58 end
59 end
60
61 feature -- Access
62
63 cursor: TWO_WAY_CURSOR_TREE_CURSOR [G] is
64 -- Current cursor position
65 do
66 create Result.make (active, active_parent, after, before, below)
67 end
68
69 feature -- Element change
70
71 put_right (v: G) is
72 -- Add `v' to the right of cursor position.
73 do
74 if below then
75 active.child_put_right (v)
76 active.child_forth
77 active_parent := active
78 active := active_parent.child
79 below := False
80 elseif before then
81 active_parent.child_put_left (v)
82 active_parent.child_back
83 active := active_parent.child
84 else
85 active_parent.child_put_right (v)
86 end
87 end
88
89 put_root (v: G) is
90 -- Put `v' as root of an empty tree.
91 require
92 is_empty: is_empty
93 do
94 above_node.child_put_right (v)
95 active_parent := above_node
96 active := active_parent.child
97 ensure
98 is_root: is_root
99 count = 1
100 end
101
102 put_child (v: G) is
103 -- Put `v' as child of a leaf.
104 require
105 is_leaf: is_leaf
106 do
107 down (0)
108 put_right (v)
109 end
110
111 feature -- Duplication
112
113 subtree: like Current is
114 -- Subtree rooted at current node.
115 do
116 create Result.make_root (item)
117 Result.fill_from_active (Current)
118 end
119
120 feature {LINKED_CURSOR_TREE} -- Implementation
121
122 new_tree: like Current is
123 -- A newly created instance of the same type.
124 -- This feature may be redefined in descendants so as to
125 -- produce an adequately allocated and initialized object.
126 do
127 create Result.make
128 end
129
130 feature {NONE} -- Implementation
131
132 active: TWO_WAY_TREE [G];
133 -- Current node
134
135 indexing
136
137 library: "[
138 EiffelBase: Library of reusable components for Eiffel.
139 ]"
140
141 status: "[
142 Copyright 1986-2001 Interactive Software Engineering (ISE).
143 For ISE customers the original versions are an ISE product
144 covered by the ISE Eiffel license and support agreements.
145 ]"
146
147 license: "[
148 EiffelBase may now be used by anyone as FREE SOFTWARE to
149 develop any product, public-domain or commercial, without
150 payment to ISE, under the terms of the ISE Free Eiffel Library
151 License (IFELL) at http://eiffel.com/products/base/license.html.
152 ]"
153
154 source: "[
155 Interactive Software Engineering Inc.
156 ISE Building
157 360 Storke Road, Goleta, CA 93117 USA
158 Telephone 805-685-1006, Fax 805-685-6869
159 Electronic mail <info@eiffel.com>
160 Customer support http://support.eiffel.com
161 ]"
162
163 info: "[
164 For latest info see award-winning pages: http://eiffel.com
165 ]"
166
167 end -- class TWO_WAY_CURSOR_TREE
168
169
170

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23