---
name: "af_sets"
section: "3"
platform: "linux"
package: "atfs-dev"
version: "1.4pl6-15+b1"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/af_sets"
---

# af\_sets(3)

AtFS operations on key sets

## NAME

af\_initset, af\_nrofkeys, af\_setgkey, af\_setaddkey, af\_setrmkey, af\_setposrmkey, af\_sortset, af\_subset, af\_copyset, af\_intersect, af\_union, af\_diff - AtFS operations on key sets

## SYNOPSIS

\#include \<atfs.h\>

int af\_initset (Af\_set \*set)

int af\_nrofkeys (Af\_set \*set)

int af\_setgkey (Af\_set \*set, int position, Af\_key \*key)

int af\_setaddkey (Af\_set \*set, int position, Af\_key \*key)

int af\_setrmkey (Af\_set \*set, Af\_key \*key)

int af\_setposrmkey (Af\_set \*set, int position)

int af\_sortset (Af\_set \*set, char \*attrname)

int af\_subset (Af\_set \*set, Af\_attrs \*attrbuf, Af\_set \*subset)

int af\_copyset (Af\_set \*source, Af\_set \*destination)

int af\_intersect (Af\_set \*set1, Af\_set \*set2, Af\_set \*newset)

int af\_union (Af\_set \*set1, Af\_set \*set2, Af\_set \*newset)

int af\_diff (Af\_set \*set1, Af\_set \*set2, \*Af\_set newset)

## DESCRIPTION

Sets in AtFS are ordered collections of keys. The structure of sets is the following

```
typedef struct {
	int	af_nkeys;
	int	af_setlen;
	Af_key	*af_klist;
} Af_set;
```

The list of keys in a set is a linear list, residing in allocated memory. The list has no holes, so that positions *0* through *af\_nkeys-1* are occupied with valid keys. Set functions returning a set require a pointer to an empty set structure as argument.

*af\_initset* initializes a set.

*af\_nrofkeys* returns the number of valid keys in the given *set*.

*af\_setgkey* delivers the filekey, stored at position *position* in the identified set. The result is passed in the buffer *key*. Typically you use af\_setgkey to run through a set and perform a special action on each key. The following code sequence does this job:

```
	Af_key key;
	Af_set set;
	af_initset (&set);
	...
	for (i = 0; i < af_nrofkeys (&set); i++) {
		af_setgkey (&set, i, &key);
		/* process key */
		...
	}
```

*af\_setaddkey* introduces a new filekey to an existing set at the given position. All following keys are moved back by one position. The constant AF\_LASTPOS given as *position* argument leads to adding the new filekey at the end of the set.

*af\_setrmkey (af\_setposrmkey)* removes the given filekey (the filekey at position *position*) from the specified set. Holes generated by deleting single keys from a set are eliminated by condensing the set. All following keys are moved one position forth in the set.

*af\_sortset* sorts a given set of object keys by the values of the named attribute. The set is sorted in increasing order. Increasing order means, that the lowest value occurs first in the set. Af\_user structures are compared by username first and by userdomain, if the names are equal (user host will not be taken into account). Version numbers are ordered in natural order, busy versions first.

In *atfs.h* you can find a list of attribute names naming the standard attributes. All other attribute names are presumed to be user defined attributes. While sorting by the values of an user defined attribute, all ASOs that do not have the named attribute are added at the end of the resulting (sorted) set. Sorting of user defined attributes with multiple values bases on simple text comparison with the order of the values taken as it is. The length of the given attribute name is limited. This limit is defined by the constant AF\_UDANAMLEN in atfs.h.

*af\_subset* does a retrieve operation (similar to af\_find - manual page [af\_retrieve(3)](/af_retrieve/3.md)) on a given set of object keys. Af\_subset takes an attribute buffer (*attrbuf*) with all desired attributes set to an appropriate value as argument. The attribute buffer should be initialized by *af\_initattrs* (manual page [af\_retrieve(3)](/af_retrieve/3.md)) beforehand. af\_subset returns it's result in a new set, the original set remains unchanged.

*af\_copyset* for copying sets (really! =:-).

*af\_intersect*, *af\_union* and *af\_diff* build intersections, unions, and differences between two sets. The result is a new set, where all keys taken from the first argument set (*set1*) occur first, and the keys from the second argument set (*set2*) afterwards. You may gibe one of set1 or set2 as *resultset*. In that case, the original set get lost and is dropped implicitely.

Sets generated by af\_copyset, af\_subset, af\_intersect, af\_union, or af\_diff should be released by *af\_dropset* as soon as they are not used any longer.

## SEE ALSO

[af\_retrieve(3)](/af_retrieve/3.md)

## DIAGNOSTICS

Upon error, -1 or a nil pointer (depending on the return type) is returned and *af\_errno* is set to the corresponding error number.
