class Geom2D::Utils::SortedLinkedList::Node
A node of the double linked list.
Attributes
next_node[RW]
The next node in the list. The last node points to the anchor node.
prev_node[RW]
The previous node in the list. The first node points to the anchor node.
value[RW]
The value of the node.
Public Class Methods
create_anchor()
click to toggle source
Creates a Node
object that can be used as the anchor of the doubly linked list.
# File lib/geom2d/utils/sorted_linked_list.rb, line 24 def self.create_anchor Node.new(AnchorValue).tap {|anchor| anchor.next_node = anchor.prev_node = anchor } end
new(value, prev_node = nil, next_node = nil)
click to toggle source
Creates a new Node
for the given value, with optional previous and next nodes to point to.
# File lib/geom2d/utils/sorted_linked_list.rb, line 38 def initialize(value, prev_node = nil, next_node = nil) @prev_node = prev_node @next_node = next_node @value = value end
Public Instance Methods
anchor?()
click to toggle source
Returns true
if this node is an anchor node, i.e. the start and end of this list.
# File lib/geom2d/utils/sorted_linked_list.rb, line 45 def anchor? @value == AnchorValue end
delete()
click to toggle source
Deletes this node from the linked list.
# File lib/geom2d/utils/sorted_linked_list.rb, line 59 def delete @prev_node.next_node = @next_node @next_node.prev_node = @prev_node @prev_node = @next_node = nil @value end
insert_before(node)
click to toggle source
Inserts this node before the given node.
# File lib/geom2d/utils/sorted_linked_list.rb, line 50 def insert_before(node) @prev_node = node.prev_node @next_node = node node.prev_node.next_node = self node.prev_node = self self end