// // set_union.pp // // The following propagation patterns allow for the use of Vertex_comma_lists // as sets in the set-theoretic sense. There are two variants of the // set_union function. // // set_union(Vertex* w) takes a vertex w and adds it to the list if it is not // already in the list. // // set_union(Vertex_comma_list *l) takes a list of vertices. Each vertex in // the list l is added to the list if it is not already in the list. This is // easier to implement in propagation patterns if the list of vertices to be // added is the object being traversed, however, this is not syntactically // consistent with the set_union above. To preserve readability in the rest // of the code and to ease implementation this is done with two operations. // One takes the syntax one would expect then swaps the lists and calls the // version that is easier to implement. // // Both functions assume that the list being added to is already a set. // // add Vertex* w to the Vertex_comma_list if it is not already in the list *operation* void set_union(Vertex* w) *traverse* *from* Vertex_comma_list *to* Vertex *carry* *inout* int in_list = (@ 0 @) *along* *from* Vertex_comma_list *to* Vertex *wrapper* Vertex_comma_list *suffix* (@ if (!in_list) { this->append(w); } @) *wrapper* Vertex *prefix* (@ if (g_equal(w)) { in_list = 1; } @) // add each Vertex in the Vertex_comma_list* l to the Vertex_comma_list if // it is not already in the list *operation* void set_union(Vertex_comma_list* l) *traverse* *from* Vertex_comma_list *to-stop* Vertex_comma_list *wrapper* Vertex_comma_list *prefix* (@ l->set_union_swap(this); @) *operation* void set_union_swap(Vertex_comma_list* final_list) *traverse* *from* Vertex_comma_list *to* Vertex *wrapper* Vertex *prefix* (@ final_list->set_union(this); @)