pike.git / lib / modules / Array.pmod

version» Context lines:

pike.git/lib/modules/Array.pmod:571:   {    array res;    mixed last;    if (!sizeof(a)) return ({});    res=({last=a[0]});    foreach (a,mixed v)    if (v!=last) last=v,res+=({v});    return res;   }    - //! Make an array of the argument, if it isn't already. A zero_type + //! Make an array of the argument, if it isn't already. An undefined   //! argument gives the empty array. This is useful when something is   //! either an array or a basic datatype, for instance in headers from   //! the MIME module or Protocols.HTTP.Server.   //! @param x   //! Result depends of the argument type:   //! @dl   //! @item arrayp(x)   //! arrayify(x) => x - //! @item zero_type(x) + //! @item undefinedp(x)   //! arrayify(x) => ({})   //! @item otherwise   //! arrayify(x) => ({ x })   //! @enddl   array arrayify(void|array|mixed x)   { -  if(zero_type(x)) return ({}); +  if(undefinedp(x)) return ({});    if(arrayp(x)) return [array]x;    return ({ x });   }      //! Sort with care of numerical sort for OID values, e.g.   //! "1.2.1" before "1.11.1".   //! @returns   //! @int   //! @value -1   //! @expr{a<b@}
pike.git/lib/modules/Array.pmod:690:   //! If the optional @[needle] argument is omitted, @[count] instead   //! works similar to the unix command @tt{sort|uniq -c@}, returning   //! a mapping with the number of occurrences of each element in   //! @[haystack]. For array or mapping @[haystack]s, it's the values   //! that are counted, for multisets the indices, as you'd expect.   //! @seealso   //! @[String.count], @[search], @[has_value]   int|mapping(mixed:int) count(array|mapping|multiset haystack,    mixed|void needle)   { -  if(zero_type(needle)) +  if(undefinedp(needle))    {    mapping(mixed:int) res = ([]);    if(mappingp(haystack))    haystack = values([mapping]haystack);    foreach((array)haystack, mixed what)    res[what]++;    return res;    }    return sizeof(filter(haystack, `==, needle));   }