21 using namespace basis;
27 struct internal_link {
29 internal_link(node *destination =
NULL_POINTER) : _connection(destination) {}
33 class node_link_amorph :
public amorph<internal_link>
36 node_link_amorph(
int num) :
amorph<internal_link>(
num) {}
41 node::node(
int number_of_links)
42 : _links(new node_link_amorph(number_of_links))
43 {
for (
int i = 0; i < number_of_links; i++) set_empty(i); }
54 void node::set_empty(
int link_num)
56 internal_link *blank_frank =
new internal_link(
NULL_POINTER);
57 _links->put(link_num, blank_frank);
60 #define test_arg(link_num) bounds_return(link_num, 0, _links->elements()-1, );
65 (*_links)[link_number]->_connection = new_link;
71 _links->zap(link_number, link_number);
80 _links->insert(where, 1);
88 return (*_links)[link_number]->_connection;
93 int to_return = common::NOT_FOUND;
94 for (
int i = 0; i <=
links() - 1; i++)
An object representing the interstitial cell in most linked data structures.
void zap_link(int link_number)
the specified link is removed from the node.
void set_link(int link_number, node *new_link)
Connects the node "new_link" to this node.
int links() const
Returns the number of links the node currently holds.
void insert_link(int where, node *to_add=NULL_POINTER)
adds a new link prior to the position specified in "where".
virtual ~node()
the destructor simply invalidates the node.
int which(node *to_find) const
locates the index where "to_find" lives in our list of links.
node * get_link(int link_number) const
Returns the node that is connected to the specified "link_number".
#define NULL_POINTER
The value representing a pointer to nothing.
#define bounds_return(value, low, high, to_return)
Verifies that "value" is between "low" and "high", inclusive.
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
A dynamic container class that holds any kind of object via pointers.
#define test_arg(link_num)