Bug #14920 Updated: Internal pointer stack for arrays, to solve pointer problems
| From: | paule at cs dot tamu dot edu | Date: | Mon, 07 Jan 2002 22:16:50 +0000 |
| Subject: | Bug #14920 Updated: Internal pointer stack for arrays, to solve pointer problems | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-76220@lists.php.net to get a copy of this message | ||
ID: 14920
User updated by: paule@cs.tamu.edu
Reported By: paule@cs.tamu.edu
Status: Open
Bug Type: Feature/Change Request
Operating System: All
PHP Version: 4.1.1
New Comment:
whoops, sorry about the double message there....
Previous Comments:
------------------------------------------------------------------------
[2002-01-07 17:15:01] paule@cs.tamu.edu
There are many occasions where an array's internal pointer gets modifed
by a function that requires a traversal for one reason or another (e.g.,
foreach, array_walk, etc.). This often messes with the continuity and
readability of the code. For example, some sort of a workaround is
required if one wants to nest a foreach statement within another
operating on the same array. Often these workarounds involve various
traversals and can cause serious performance issues with larger array.
A simple solution for this is to provide for an internal pointer stack.
I propose two functions:
void pos_push(array array);
mixed pos_pop(array array);
The function pos_push merely pushes the internal pointer position onto
the pointer stack. The complementary function pos_pop pops the internal
pointer off of the stack and returns the resulting current value of the
new position in the array.
This is easy to efficiently implement through a linked list stack
specific to each array. The memory usage is minimal, and overhead is
slight. The stack could store the actual position pointers. Of course,
that means care would have to be taken if an element that was stored on
the stack was deleted.
------------------------------------------------------------------------
[2002-01-07 17:13:16] paule@cs.tamu.edu
There are many occasions where an array's internal pointer gets modifed
by a function that requires a traversal for one reason or another (e.g.,
foreach, array_walk, etc.). This often messes with the continuity and
readability of the code. For example, some sort of a workaround is
required if one wants to nest a foreach statement within another
operating on the same array. Often these workarounds involve various
traversals or copy operations and can cause serious performance issues
with larger array.
A simple solution for this is to provide for an internal pointer stack.
I propose two functions:
void pos_push(array array);
mixed pos_pop(array array);
The function pos_push merely pushes the internal pointer position onto
the pointer stack. The complementary function pos_pop pops the internal
pointer off of the stack and returns the resulting current value of the
new position in the array.
This is easy to efficiently implement through a linked list stack
specific to each array. The memory usage is minimal, and overhead is
slight. The stack could store the actual position pointers. Of course,
that means care would have to be taken if an element that was been
stored on the stack was deleted.
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=14920&edit=1