src/libs/elektra/keyset.c
/**
 * Compare the name of two keys.
 *
 * @return a number less than, equal to or greater than zero if
 *    k1 is found, respectively, to be less than, to match, or
 *    be greater than k2.
 *
 * The comparison is based on a strcmp of the keynames, and iff
 * they match a strcmp of the owner will be used to distuingish.
 * If even this matches the keys are found to be exactly the
 * same and 0 is returned. These two keys can't be used in the same
 * KeySet.
 *
 * keyCmp() defines the sorting order for a KeySet.
 *
 * The following 3 points are the rules for null values:
 *
 * - A null pointer will be found to be smaller than every other
 * key. If both are null pointers, 0 is returned.
 *
 * - A null name will be found to be smaller than every other
 * name. If both are null names, 0 is returned.
 *
 * If the name is equal then:
 *
 * - No owner will be found to be smaller then every other owner.
 * If both don't have a owner, 0 is returned.
 *
 * @note the owner will only be used if the names are equal.
 *
 * Often is enough to know if the other key is
 * less then or greater then the other one.
 * But Sometimes you need more precise information,
 * see keyRel().
 *
 * Given any Keys k1 and k2 constructed with keyNew(), following
 * equation hold true:
 *
 * @snippet testabi_rel.c cmp null
 *
 * Here are some more examples:
 * @code
Key *k1 = keyNew("user/a", KEY_END);
Key *k2 = keyNew("user/b", KEY_END);

// keyCmp(k1,k2) < 0
// keyCmp(k2,k1) > 0
 * @endcode
 *
 * And even more:
 * @code
Key *k1 = keyNew("user/a", KEY_OWNER, "markus", KEY_END);
Key *k2 = keyNew("user/a", KEY_OWNER, "max", KEY_END);

// keyCmp(k1,k2) < 0
// keyCmp(k2,k1) > 0
 * @endcode
 *
 * Do not strcmp the keyName() yourself because
 * the result differs from simple ascii comparison.
 *
 * @param k1 the first key object to compare with
 * @param k2 the second key object to compare with
 *
 * @see ksAppendKey(), ksAppend() will compare keys when appending
 * @see ksLookup() will compare keys during searching
 * @ingroup keytest
 */
Compare the name of two keys.
@return a number less than, equal to or greater than zero if
k1 is found, respectively, to be less than, to match, or
be greater than k2.

The comparison is based on a strcmp of the keynames, and iff
they match a strcmp of the owner will be used to distuingish.
If even this matches the keys are found to be exactly the
same and 0 is returned. These two keys can't be used in the same
KeySet.

keyCmp() defines the sorting order for a KeySet.

The following 3 points are the rules for null values.

- A null pointer will be found to be smaller than every other
key. If both are null pointers, 0 is returned.

- A null name will be found to be smaller than every other
name. If both are null names, 0 is returned.

If the name is equal then.

- No owner will be found to be smaller then every other owner.
If both don't have a owner, 0 is returned.

@note the owner will only be used if the names are equal.

Often is enough to know if the other key is
less then or greater then the other one.
But Sometimes you need more precise information,
see keyRel().

Given any Keys k1 and k2 constructed with keyNew(), following
equation hold true.



Here are some more examples:
@code
Key *k1 = keyNew("user/a", KEY_END);
Key *k2 = keyNew("user/b", KEY_END).







Do not strcmp the keyName() yourself because
the result differs from simple ascii comparison.

@param k1 the first key object to compare with
@param k2 the second key object to compare with

@see ksAppendKey(), ksAppend() will compare keys when appending
@see ksLookup() will compare keys during searching
@ingroup keytest
Compare the name of two keys . @return a number less than equal to or greater than zero if k1 is found respectively to be less than to match or be greater than k2 . The comparison is based on a strcmp of the keynames and iff they match a strcmp of the owner will be used to distuingish . If even this matches the keys are found to be exactly the same and 0 is returned . These two keys can ' t be used in the same KeySet . keyCmp () defines the sorting order for a KeySet . The following 3 points are the rules for null values . - A null pointer will be found to be smaller than every other key . If both are null pointers 0 is returned . - A null name will be found to be smaller than every other name . If both are null names 0 is returned . If the name is equal then . - No owner will be found to be smaller then every other owner . If both don ' t have a owner 0 is returned . @note the owner will only be used if the names are equal . Often is enough to know if the other key is less then or greater then the other one . But Sometimes you need more precise information see keyRel () . Given any Keys k1 and k2 constructed with keyNew () following equation hold true . Here are some more examples : @code Key * k1 = keyNew ( " user / a " KEY_END ) ; Key * k2 = keyNew ( " user / b " KEY_END ) . Do not strcmp the keyName () yourself because the result differs from simple ascii comparison . @param k1 the first key object to compare with @param k2 the second key object to compare with @see ksAppendKey () ksAppend () will compare keys when appending @see ksLookup () will compare keys during searching @ingroup keytest
int keyCmp (const Key * k1, const Key * k2)
{
	if (!k1 && !k2) return 0;
	if (!k1) return -1;
	if (!k2) return 1;
	if (!k1->key && !k2->key) return 0;
	if (!k1->key) return -1;
	if (!k2->key) return 1;
	return keyCompareByNameOwner (&k1, &k2);
}
int keyCmp ( const Key * k1 , const Key * k2 ) { if ( ! k1 && ! k2 ) return 0 ; if ( ! k1 ) return -1 ; if ( ! k2 ) return 1 ; if ( ! k1 -> key && ! k2 -> key ) return 0 ; if ( ! k1 -> key ) return -1 ; if ( ! k2 -> key ) return 1 ; return keyCompareByNameOwner ( & k1 , & k2 ) ; }
Compare the name of two keys.
Compare the name of two keys .