Changeset - 225612581f1b
[Not reviewed]
0 1 0
Christopher Esterhuyse - 5 years ago 2020-04-29 13:31:56
christopher.esterhuyse@gmail.com
whoops
git push
1 file changed with 6 insertions and 9 deletions:
0 comments (0 inline, 0 general)
examples/6_constraint_solve/main.c
Show inline comments
 
@@ -11,26 +11,23 @@ typedef struct PeerInfo {
 
	int id;
 
	bool puts; // true iff the channel to this peer is INCOMING.
 
} PeerInfo;
 

	
 
// return the index of (i,j) in the lexicographic ordering of set {(i,j) : i<j, j<N}
 
// for convenience, swaps (i,j) if i>j 
 
int combination_index(int i, int j) {
 
int combination_index(unsigned int i, unsigned int j) {
 
	if (i > j) {
 
		// swap!
 
		i ^= j;
 
		j ^= i;
 
		i ^= j;
 
	}
 
	assert(0 <= i);
 
	assert(i < j);
 
	assert(j < N);
 
		
 
	int idx_in_square = i*N + j;
 
	int skipped = ((i+1) * (i+2)) / 2;
 
	return idx_in_square - skipped;
 
	assert(i<j && j<N);
 
	unsigned int index_in_square = i*N + j;
 
	unsigned int skipped_indexes = ((i+1) * (i+2)) / 2;
 
	return index_in_square - skipped_indexes;
 
}
 

	
 
// initializes the given 3-element array,
 
// breaking symmetry with put-get direction.
 
void init_peer_infos(PeerInfo * peer_infos, int my_id) {
 
	int i;
 
@@ -85,13 +82,13 @@ int main(int arg_c, char * argv[]) {
 
	}
 
	printf("connecting...\n");
 
	check("connect", connector_connect(c, 5000));
 
	
 
	// for every native port, create a singleton batch
 
	for (i = 0; i < 3; i++) {
 
		if (i > 0) check("next ", connector_next_batch(c));
 
		if (i > 0) assert(connector_next_batch(c) >= 0);
 
		PeerInfo * pi = &peer_infos[i];
 
		check("op ", pi->puts?
 
			connector_get(c, i):
 
			connector_put(c, i, NULL, 0));
 
	}
 
	// solve!
0 comments (0 inline, 0 general)