pike.git / lib / modules / Array.pmod

version» Context lines:

pike.git/lib/modules/Array.pmod:19:   constant permute = __builtin.permute;   constant enumerate = predef::enumerate;      //! @[reduce()] sends the first two elements in @[arr] to @[fun],   //! then the result and the next element in @[arr] to @[fun] and   //! so on. Then it returns the result. The function will return   //! @[zero] if @[arr] is the empty array. If @[arr] has   //! only one element, that element will be returned.   //!   //! @seealso - //! @[Array.rreduce()] + //! @[rreduce()]   //!   mixed reduce(function fun, array arr, mixed|void zero)   {    if(sizeof(arr))    zero = arr[0];    for(int i=1; i<sizeof(arr); i++)    zero = ([function(mixed,mixed:mixed)]fun)(zero, arr[i]);    return zero;   }      //! @[rreduce()] sends the last two elements in @[arr] to @[fun],   //! then the third last element in @[arr] and the result to @[fun] and   //! so on. Then it returns the result. The function will return   //! @[zero] if @[arr] is the empty array. If @[arr] has   //! only one element, that element will be returned.   //!   //! @seealso - //! @[Array.reduce()] + //! @[reduce()]   //!   mixed rreduce(function fun, array arr, mixed|void zero)   {    if(sizeof(arr))    zero = arr[-1];    for(int i=sizeof(arr)-2; i>=0; --i)    zero = ([function(mixed,mixed:mixed)]fun)(arr[i], zero);    return zero;   }      //! @[shuffle()] gives back the same elements, but in random order.   //!   //! @seealso - //! @[Array.permute()] + //! @[permute()]   //!   array shuffle(array arr)   {    int i = sizeof(arr);       while(i) {    int j = random(i--);    if (j != i) {    mixed tmp = arr[i];    arr[i] = arr[j];
pike.git/lib/modules/Array.pmod:74:    }    return(arr);   }      //! @[search_array()] works like @[map()], only it returns the index   //! of the first call that returnes true instead.   //!   //! If no call returns true, -1 is returned.   //!   //! @seealso - //! @[Array.sum_arrays()], @[map()] + //! @[sum()], @[map()]   //!   int search_array(array arr, mixed fun, mixed ... args)   {    int e;       if(stringp(fun))    {    for(e=0;e<sizeof(arr);e++)    if(([function(mixed...:mixed)]([array(object)]arr)[e][fun])(@args))    return e;
pike.git/lib/modules/Array.pmod:591:   //! @item otherwise   //! arrayify(x) => ({ x })   //! @enddl   array arrayify(void|array|mixed x)   {    if(zero_type(x)) return ({});    if(arrayp(x)) return x;    return ({ x });   }    -  +    //! Sort with care of numerical sort for OID values:   //! "1.2.1" before "1.11.1"   int oid_sort_func(string a0,string b0)   {    string a2="",b2="";    int a1, b1;    sscanf(a0,"%d.%s",a1,a2);    sscanf(b0,"%d.%s",b1,b2);    if (a1>b1) return 1;    if (a1<b1) return 0;    if (a2==b2) return 0;    return oid_sort_func(a2,b2);   }