pike.git / lib / modules / Array.pmod

version» Context lines:

pike.git/lib/modules/Array.pmod:542:   //! Flatten a multi-dimensional array to a one-dimensional array.   //! @note   //! Prior to Pike 7.5.7 it was not safe to call this function   //! with cyclic data-structures. The method always terminates   //! now, but cyclic input might not yield a useful result.   array flatten(array a, mapping|void state)   {    if (state && state[a]) return state[a];    if (!state) state = ([a:({})]);    else state[a] = ({}); -  foreach(a, mixed b) state[a]+=arrayp(b)?flatten([array]b, state):({b}); -  return state[a]; +  array res = allocate(sizeof(a)); +  foreach(a; int i; mixed b) { +  res[i] = arrayp(b)?flatten([array]b, state):({b});    } -  +  return state[a] = (res*({})); + }      //! Sum the elements of an array using `+   mixed sum(array a)   {    if(a==({})) return 0;    // 1000 is a safe stack limit    if (sizeof(a)<1000)    return `+(@a);    else    {