Class: Doku::DancingLinks::LinkMatrix::Node

Inherits:
Object
  • Object
show all
Includes:
HorizontalLinks, VerticalLinks
Defined in:
lib/doku/dancing_links.rb

Overview

This class represents a normal node in Knuth’s Doku::DancingLinks::LinkMatrix. Every node belongs to a column and a row, and it represents the fact that the row (i.e. set) “covers” the column.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HorizontalLinks

included, #insert_left, #reinsert_horizontal, #remove_horizontal

Methods included from Uninspectable

#inspect

Methods included from VerticalLinks

included, #insert_above, #reinsert_vertical, #remove_vertical

Instance Attribute Details

#columnObject

The Column object that this node belongs to.



226
227
228
# File 'lib/doku/dancing_links.rb', line 226

def column
  @column
end

#row_idObject

The user-assigned ID of the row this node belongs to.



229
230
231
# File 'lib/doku/dancing_links.rb', line 229

def row_id
  @row_id
end

Instance Method Details

#chooseObject

Removes a row from the Doku::DancingLinks::LinkMatrix by covering every column that it touches. This represents (tentatively) choosing the node’s row to be in our exact cover. When that choice is proven to not work, this action can be efficiently undone with #unchoose.



257
258
259
260
261
# File 'lib/doku/dancing_links.rb', line 257

def choose
  nodes_except_self_rightward.each do |node|
    node.column.cover
  end
end

#nodes_except_self_leftwardObject

All nodes in the same row, starting with self and going to the left, but not including self.



244
245
246
# File 'lib/doku/dancing_links.rb', line 244

def nodes_except_self_leftward
  LinkEnumerator.new :left, self
end

#nodes_except_self_rightwardObject Also known as: nodes_except_self

All nodes in the same row, starting with self and going to the right, but not including self.



238
239
240
# File 'lib/doku/dancing_links.rb', line 238

def nodes_except_self_rightward
  LinkEnumerator.new :right, self
end

#nodes_rightwardObject Also known as: nodes

All nodes in the same row, starting with self and going to the right.



232
233
234
# File 'lib/doku/dancing_links.rb', line 232

def nodes_rightward
  LinkEnumerator.new :right, self, true
end

#unchooseObject

Undoes the effect of #choose, putting the nodes of the row back into the Doku::DancingLinks::LinkMatrix.



265
266
267
268
269
# File 'lib/doku/dancing_links.rb', line 265

def unchoose
  nodes_except_self_leftward.each do |node|
    node.column.uncover
  end
end