pike.git / lib / modules / Array.pmod

version» Context lines:

pike.git/lib/modules/Array.pmod:675:   //! 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))    { -  mapping res = ([]); +  mapping(mixed:int) res = ([]);    if(mappingp(haystack)) -  haystack = values(haystack); -  foreach(haystack, mixed what) +  haystack = values([mapping]haystack); +  foreach((array)haystack, mixed what)    res[what]++;    return res;    }    return sizeof(filter(haystack, `==, needle));   }      //! Returns a random element from the @[in] array.   mixed random(array in) {    return in[predef::random(sizeof(in))];   }