(@ #define MAX_DIST 1000 @) // return the distance between the physical nodes node1 and node2 on the ring. // return also the corresponding virtual nodes vnode1 and vnode2. *operation* int distance(Node* node1, Node* node2, VNode*& vnode1, VNode*& vnode2) *wrapper* Ring (@ return_val = node1->distance_to(node2, this, vnode1, vnode2); @) // return the distance to physical node 'node', and also compute the corresponding // pair of virtual nodes *operation* int distance_to(Node* node, Ring* ring, VNode*& vnode1, VNode*& vnode2) *init* (@ MAX_DIST @) *traverse* *from* Node *through* -> *, vnodes, * *to-stop* VNode *wrapper* VNode (@ VNode* temp_vnode2; int dist = node->distance_from(this, ring, temp_vnode2); if (dist < return_val) { return_val = dist; vnode1 = this; vnode2 = temp_vnode2; } @) // return the distance from virtual node vnode, and also compute the corresponding // pair of virtual nodes. *operation* int distance_from(VNode* vnode, Ring* ring, VNode*& vnode2) *init* (@ MAX_DIST @) *traverse* *from* Node *through* -> *, vnodes, * *to-stop* VNode *wrapper* VNode (@ int dist = ring->distance(vnode, this); if (dist < return_val) { return_val = dist; vnode2 = this; } @) // find the distance between two virtual nodes on the ring. The // order of the arguments is important. *operation* int distance(VNode* vnode1, VNode* vnode2) *wrapper* Ring (@ int count = *(this->get_vnode_count()); return_val = (*(vnode2->get_vid()) - *(vnode1->get_vid()) + count) % count; @) *operation* VNode* furthest_possible_source(VNode* dest_vnode) *wrapper* Ring (@ VirtualAdjacency* dest_adj = this->find(dest_vnode); VirtualAdjacency* next_adj; Node* dest_node = dest_vnode->get_phys_node(); VNode* next_vnode; Node* next_phys_node; next_adj = this->get_nextdefault(dest_adj); VNode *vnode1, *vnode2; do { next_vnode = next_adj->get_source(); next_phys_node = next_vnode->get_phys_node(); this->distance(next_phys_node, dest_node, vnode1, vnode2); next_adj = this->get_nextdefault(next_adj); }while (vnode1 != next_vnode || vnode2 != dest_vnode); return_val = next_vnode; @) *operation* int before(VNode* vnode1, VNode* vnode2) *wrapper* Ring (@ return_val = (*(vnode1->get_vid()) <= *(vnode2->get_vid())); @) // return 1 if virtual nodes a, b and c ar in order on the ring, 0 // otherwise. *operation* int in_ring_order(VNode* a, VNode* b, VNode* c) *wrapper* Ring (@ int count = *(this->get_vnode_count()); return_val = (distance(a, b) + distance(b, c) <= count); @)