src/bin/pg_dump/pg_dump.c
static int
findSecLabels(Archive *fout, Oid classoid, Oid objoid, SecLabelItem **items)
{
	SecLabelItem *middle = NULL;
	SecLabelItem *low;
	SecLabelItem *high;
	int			nmatch;

	if (nseclabels <= 0)		/* no labels, so no match is possible */
	{
		*items = NULL;
		return 0;
	}

	/*
	 * Do binary search to find some item matching the object.
	 */
	low = &seclabels[0];
	high = &seclabels[nseclabels - 1];
	while (low <= high)
	{
		middle = low + (high - low) / 2;

		if (classoid < middle->classoid)
			high = middle - 1;
		else if (classoid > middle->classoid)
			low = middle + 1;
		else if (objoid < middle->objoid)
			high = middle - 1;
		else if (objoid > middle->objoid)
			low = middle + 1;
		else
			break;				/* found a match */
	}

	if (low > high)				/* no matches */
	{
		*items = NULL;
		return 0;
	}

	/*
	 * Now determine how many items match the object.  The search loop
	 * invariant still holds: only items between low and high inclusive could
	 * match.
	 */
	nmatch = 1;
	while (middle > low)
	{
		if (classoid != middle[-1].classoid ||
			objoid != middle[-1].objoid)
			break;
		middle--;
		nmatch++;
	}

	*items = middle;

	middle += nmatch;
	while (middle <= high)
	{
		if (classoid != middle->classoid ||
			objoid != middle->objoid)
			break;
		middle++;
		nmatch++;
	}

	return nmatch;
}
/*
 * findSecLabels
 *
 * Find the security label(s), if any, associated with the given object.
 * All the objsubid values associated with the given classoid/objoid are
 * found with one search.
 */
findSecLabels
Find the security label(s), if any, associated with the given object.
All the objsubid values associated with the given classoid/objoid are
found with one search.
findSecLabels Find the security label ( s ) if any associated with the given object . All the objsubid values associated with the given classoid / objoid are found with one search .
static int
findSecLabels(Archive *fout, Oid classoid, Oid objoid, SecLabelItem **items)
{
	SecLabelItem *middle = NULL;
	SecLabelItem *low;
	SecLabelItem *high;
	int			nmatch;
	if (nseclabels <= 0)		
	{
		*items = NULL;
		return 0;
	}
	low = &seclabels[0];
	high = &seclabels[nseclabels - 1];
	while (low <= high)
	{
		middle = low + (high - low) / 2;
		if (classoid < middle->classoid)
			high = middle - 1;
		else if (classoid > middle->classoid)
			low = middle + 1;
		else if (objoid < middle->objoid)
			high = middle - 1;
		else if (objoid > middle->objoid)
			low = middle + 1;
		else
			break;				
	}
	if (low > high)				
	{
		*items = NULL;
		return 0;
	}
	nmatch = 1;
	while (middle > low)
	{
		if (classoid != middle[-1].classoid ||
			objoid != middle[-1].objoid)
			break;
		middle--;
		nmatch++;
	}
	*items = middle;
	middle += nmatch;
	while (middle <= high)
	{
		if (classoid != middle->classoid ||
			objoid != middle->objoid)
			break;
		middle++;
		nmatch++;
	}
	return nmatch;
}
static int findSecLabels ( Archive * fout , Oid classoid , Oid objoid , SecLabelItem * * items ) { SecLabelItem * middle = NULL ; SecLabelItem * low ; SecLabelItem * high ; int nmatch ; if ( nseclabels <= 0 ) { * items = NULL ; return 0 ; } low = & seclabels [ 0 ] ; high = & seclabels [ nseclabels - 1 ] ; while ( low <= high ) { middle = low + ( high - low ) / 2 ; if ( classoid < middle -> classoid ) high = middle - 1 ; else if ( classoid > middle -> classoid ) low = middle + 1 ; else if ( objoid < middle -> objoid ) high = middle - 1 ; else if ( objoid > middle -> objoid ) low = middle + 1 ; else break ; } if ( low > high ) { * items = NULL ; return 0 ; } nmatch = 1 ; while ( middle > low ) { if ( classoid != middle [ -1 ] . classoid || objoid != middle [ -1 ] . objoid ) break ; middle -- ; nmatch ++ ; } * items = middle ; middle += nmatch ; while ( middle <= high ) { if ( classoid != middle -> classoid || objoid != middle -> objoid ) break ; middle ++ ; nmatch ++ ; } return nmatch ; }
findSecLabels
 Find the security label(s), if any, associated with the given object.
findSecLabels Find the security label ( s ) if any associated with the given object .
/* no labels, so no match is possible */ /*
	 * Do binary search to find some item matching the object.
	 */ /* found a match */ /* no matches */ /*
	 * Now determine how many items match the object.  The search loop
	 * invariant still holds: only items between low and high inclusive could
	 * match.
	 */