pike.git / lib / modules / ADT.pmod / Set.pike

version» Context lines:

pike.git/lib/modules/ADT.pmod/Set.pike:141:    foreach(indices(other), mixed item)    if (!contains(item))    return 0;       return 1;   }         //! True subset. A < B returns true if each item in A is also present   //! in B, and B contains at least one item not present in A. - int(0..1) `<(ADT.Set other) + protected int(0..1) `<(ADT.Set other)   {    if (sizeof(this) >= sizeof(other))    return 0;       return subset(other);   }         //! True superset. A > B returns true if each item in B is also present - //! in A, and A contains at least one item not present in B. - int(0..1) `>(ADT.Set other) + //! in A, and A contains at least one item not present in B.i + protected int(0..1) `>(ADT.Set other)   {    if (sizeof(this) <= sizeof(other))    return 0;       return superset(other);   }      //! Union. Returns a set containing all elements present in either   //! or both of the operand sets. - this_program `|(ADT.Set other) + protected this_program `|(ADT.Set other)   {    ADT.Set result = ADT.Set(this);       foreach(indices(other), mixed item)    result->add(item);       return result;   }    - mixed `+ = `|; // Addition on sets works the same as union on sets. + protected mixed `+ = `|; // Addition on sets works the same as union on sets.         //! Intersection. Returns a set containing those values that were   //! present in both the operand sets. - this_program `&(ADT.Set other) + protected this_program `&(ADT.Set other)   {    return filter(lambda (mixed x) { return other->contains(x);});   }         //! Difference. The expression 'A - B', where A and B are sets, returns   //! all elements in A that are not also present in B. - this_program `-(ADT.Set other) + protected this_program `-(ADT.Set other)   {    return filter(lambda (mixed x) { return !other->contains(x);});   }         //! Indexing a set with a value V gives 1 if V is a member of the   //! set, otherwise 0.   int(0..1) `[](mixed item)   {    return set[item];   }         //! Setting an index V to 0 removes V from the set. Setting it to   //! a non-0 value adds V as a member of the set. - int `[]=(mixed item, int value) + protected int `[]=(mixed item, int value)   {    if (value)    add(item);    else    remove(item);       return value;   }         ////////////////   /// SPECIALS ///   ////////////////      //! In analogy with multisets, indices() of an ADT.Set givess an array   //! containing all members of the set. - array(mixed) _indices() + protected array(mixed) _indices()   {    return indices(set);   }         //! In analogy with multisets, values() of an ADT.Set givess an array   //! indicating the number of occurrences in the set for each position   //! in the member array returned by indices(). (Most of the time, this   //! is probably rather useless for sets, since the result is an array   //! which just contain 1's, one for each member of the set. Still,   //! this function is provided for consistency. - array(mixed) _values() + protected array(mixed) _values()   {    return values(set);   }         //! An ADT.Set can be cast to an array or a multiset.   protected mixed cast(string to)   {    switch(to)    {
pike.git/lib/modules/ADT.pmod/Set.pike:254:    case "multiset":    return copy_value(set);       default:    return UNDEFINED;    }   }         //! Number of items in the set. - int _sizeof() + protected int _sizeof()   {    return sizeof(set);   }         //! Printable representation of the set. - string _sprintf(int t) { + protected string _sprintf(int t) {    return t=='O' && sprintf("%O%O", this_program, cast("array"));   }         //! Create an ADT.Set, optionally initialized from another ADT.Set or   //! a compatible type. If no initial data is given, the set will start   //! out empty. - void create(void|ADT.Set|array|multiset|mapping initial_data) + protected void create(void|ADT.Set|array|multiset|mapping initial_data)   {    reset();    if (arrayp(initial_data))    add(@initial_data);    else if (initial_data)    add(@indices(initial_data));   }