<commit_before>USING: assocs hashtables help.markup help.syntax kernel
quotations sequences vectors ;
IN: sets

ARTICLE: "sets" "Sets"
"A set is an unordered list of elements. Words for working with sets are in the " { $vocab-link "sets" } " vocabulary." $nl
"All sets are instances of a mixin class:"
{ $subsections
    set
    set?
}
{ $subsections "set-operations" "set-implementations" } ;

ABOUT: "sets"

ARTICLE: "set-operations" "Operations on sets"
"To test if an object is a member of a set:"
{ $subsection member? }
"All sets can be represented as a sequence, without duplicates, of their members:"
{ $subsection members }
"Sets can have members added or removed destructively:"
{ $subsections
    adjoin
    delete
}
"Basic mathematical operations, which any type of set may override for efficiency:"
{ $subsections
    diff
    intersect
    union
}
"Mathematical predicates on sets, which may be overridden for efficiency:"
{ $subsections
    intersects?
    subset?
    set=
}
"An optional generic word for creating sets of the same class as a given set:"
{ $subsection set-like }
"An optional generic word for creating a set with a fast lookup operation, if the set itself has a slow lookup operation:"
{ $subsection fast-set }
"For set types that allow duplicates, like sequence sets, some additional words test for duplication:"
{ $subsections
    all-unique?
    duplicates
}
"Utilities for sets and sequences:"
{ $subsections
     within
     without
} ;

ARTICLE: "set-implementations" "Set implementations"
"There are several implementations of sets in the Factor library. More can be added if they implement the words of the set protocol, the basic set operations."
{ $subsections
    "sequence-sets"
    "hash-sets"
    "bit-sets"
} ;

ARTICLE: "sequence-sets" "Sequences as sets"
"Any sequence can be used as a set. The members of this set are the elements of the sequence. Calling the word " { $link members } " on a sequence returns a copy of the sequence with only one listing of each member. Destructive operations " { $link adjoin } " and " { $link delete } " only work properly on growable sequences like " { $link vector } "s."
$nl
"Care must be taken in writing efficient code using sequence sets. Testing for membership with " { $link in? } ", as well as the destructive set operations, take time proportional to the size of the sequence. Another representation, like " { $link "hash-sets" } ", would take constant time for membership tests. But binary operations like " { $link union } "are asymptotically optimal, taking time proportional to the sum of the size of the inputs."
$nl
"As one particlar example, " { $link POSTPONE: f } " is a representation of the empty set, as it represents the empty sequence." ;<commit_msg>Fixing spacing in the sets docs<commit_after>USING: assocs hashtables help.markup help.syntax kernel
quotations sequences vectors ;
IN: sets

ARTICLE: "sets" "Sets"
"A set is an unordered list of elements. Words for working with sets are in the " { $vocab-link "sets" } " vocabulary." $nl
"All sets are instances of a mixin class:"
{ $subsections
    set
    set?
}
{ $subsections "set-operations" "set-implementations" } ;

ABOUT: "sets"

ARTICLE: "set-operations" "Operations on sets"
"To test if an object is a member of a set:"
{ $subsections member? }
"All sets can be represented as a sequence, without duplicates, of their members:"
{ $subsections members }
"Sets can have members added or removed destructively:"
{ $subsections
    adjoin
    delete
}
"Basic mathematical operations, which any type of set may override for efficiency:"
{ $subsections
    diff
    intersect
    union
}
"Mathematical predicates on sets, which may be overridden for efficiency:"
{ $subsections
    intersects?
    subset?
    set=
}
"An optional generic word for creating sets of the same class as a given set:"
{ $subsections set-like }
"An optional generic word for creating a set with a fast lookup operation, if the set itself has a slow lookup operation:"
{ $subsections fast-set }
"For set types that allow duplicates, like sequence sets, some additional words test for duplication:"
{ $subsections
    all-unique?
    duplicates
}
"Utilities for sets and sequences:"
{ $subsections
     within
     without
} ;

ARTICLE: "set-implementations" "Set implementations"
"There are several implementations of sets in the Factor library. More can be added if they implement the words of the set protocol, the basic set operations."
{ $subsections
    "sequence-sets"
    "hash-sets"
    "bit-sets"
} ;

ARTICLE: "sequence-sets" "Sequences as sets"
"Any sequence can be used as a set. The members of this set are the elements of the sequence. Calling the word " { $link members } " on a sequence returns a copy of the sequence with only one listing of each member. Destructive operations " { $link adjoin } " and " { $link delete } " only work properly on growable sequences like " { $link vector } "s."
$nl
"Care must be taken in writing efficient code using sequence sets. Testing for membership with " { $link in? } ", as well as the destructive set operations, take time proportional to the size of the sequence. Another representation, like " { $link "hash-sets" } ", would take constant time for membership tests. But binary operations like " { $link union } "are asymptotically optimal, taking time proportional to the sum of the size of the inputs."
$nl
"As one particlar example, " { $link POSTPONE: f } " is a representation of the empty set, as it represents the empty sequence." ;
{'fraction_non_alphanumeric': 0.08014440433212996, 'fraction_numerical': 0.0, 'mean_word_length': 4.092830882352941, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2197090', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1484, 'n_words': 757}