/usr/lib/falcon/struct/tree.fal is in libfalcon-engine1 0.9.6.9-git20120606-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | /*
FALCON - Generic modules
FILE: tree.fal
Generic structures: tree
-------------------------------------------------------------------
Author: Giancarlo Niccolai
Begin: Tue, 28 Sep 2010 15:30:16 +0200
-------------------------------------------------------------------
(C) Copyright 2010: the FALCON developers (see list in AUTHORS file)
See LICENSE file for licensing details.
*/
/*# Generic Node of a tree structure.
@optparam content Some generic payload for the tree structure.
*/
class Node( content )
content = content
parent = nil
next = nil
prev = nil
//# first child of the children of this node
firstChild = nil
//# last child of the children of this node
lastChild = nil
/*# Exchange this node with another one.
@pram node The new node.
*/
function change( node )
node.parent = self.parent
node.next = self.next
node.prev = self.prev
if self.next
self.next.prev = node
else
if self.parent: self.parent.lastChild = node
end
if self.prev
self.prev.next = node
else
if self.parent: self.parent.firstChild = node
end
end
/*# Inserts the parameter before this node
@pram node The node to be inserted.
*/
function insertBefore( node )
if self.prev
self.prev.next = node
else
// we're the last node of our parent.
if self.parent
self.parent.firstChild = node
end
end
node.prev = self.prev
node.next = self
node.parent = self.parent
self.prev = node
end
/*# Inserts the parameter after this node
@pram node The node to be inserted.
*/
function insertAfter( node )
if self.next
self.next.prev = node
else
// we're the first node of our parent.
if self.parent
self.parent.lastChild = node
end
end
node.next = self.next
node.prev = self
node.parent = self.parent
self.next = node
end
/*# Detach this node from the tree
@return The next node, if it exists.
*/
function remove()
if self.next == nil
if self.prev == nil
// we are the only child of our parent?
if self.parent != nil
self.parent.firstChild = nil
self.parent.lastChild = nil
end
else
self.prev.next = nil
if self.parent != nil
// however, without next we're the last child
self.parent.lastChild = self.prev
end
end
else
self.next.prev = self.prev
if self.prev == nil
// we are the FIRST child of our parent
if self.parent != nil
self.parent.firstChild = self.next
end
else
self.prev.next = self.next
end
end
return self.next
end
/*# Adds a child after the already present children.
@param The child to be added.
*/
function appendChild( child )
child.prev = self.lastChild
if self.lastChild
self.lastChild.next = child
else
self.firstChild = child
end
self.lastChild = child
child.parent = self
end
/*# Adds a child in front of the children
@param The child to be added.
*/
function prependChild( child )
child.next = self.firstChild
if self.firstChild
self.firstChild.prev = child
else
// this is the first child
self.lastChild = child
end
self.firstChild = child
child.parent = self
end
/*# Recursively traverse the node tree
@param f A callable that will be called with each node.
The @b f function is called frist on this node, and then
the traverse method of each children is called. This makes
the structure descend-first-then-call structure.
*/
function traverse( f )
f( self )
node = self.firstChild
while node != nil
node.traverse( f )
node = node.next
end
end
end
|