Exemplo n.º 1
0
/* Return the rank of the given site in the given site list.
 */
int nl_index(struct node_list *nl, char *node){
	/* Sort the list if not yet sorted.
	 */
	if (nl->unsorted) {
		nl_sort(nl);
	}

	/* Binary search.
	 */
	int lb = 0, ub = nl->nnodes;
	while (lb < ub) {
		int i = (lb + ub) / 2;
		int cmp = strcmp(node, nl->nodes[i]);
		if (cmp < 0) {
			ub = i;
		}
		else if (cmp > 0) {
			lb = i + 1;
		}
		else {
			return i;
		}
	}
	return -1;
}
Exemplo n.º 2
0
static void print_nids(NIDList nidlist, int lookup, int enumerate, int indent)
{
	char *s, *sep = "\n", *pfx = "";

	if (lookup)
		nl_lookup_ip(nidlist);
	nl_sort(nidlist);
	nl_uniq(nidlist);
	if (nl_count(nidlist) > 0) {
		if (indent) {
			sep = "\n    ";
			pfx = "    ";
		}
		if (enumerate)
			s = nl_string(nidlist, sep);
		else
			s = nl_xstring(nidlist, sep);
		printf("%s%s\n", pfx, s);
		free(s);
	}
}