Page 1 of 1

My CSV class

Posted: Fri May 05, 2006 3:56 pm
by alex.barylski
Uses a multi-dimensional array...yippy :P

However it also includes read/write which is really the only thing that makes it CSV...otherwise it's just a hash array container and IMHO belongs in a library of code like STL or PHP's SPL or whatever it's called...

I have already written a Tree container class, as I needed one a while back when working on a DOM implementation

So I have two container classes done already...the tree class was pretty simple, but makes dealing with hierarchial data easier and possibly more efficient than implementing the tree as a linear array using parent/child relation ID's...

I now want to complete the library by writting a few others:
- Stack
- Deque
- Queue
- Vector
- etc...

PHP's native array functions however make a stack or vector somewhat pointless as they can be easily be emulated using native array_* functions...

And some containers don't make sense at all, such as linked lists...

The hash array/array is most useful as it takes care of alot of details, sorting, etc...

But I can't justify writting an array container class, but here is a list of possibilities:
1) Friendlier interface IMHO although unessecary for the most part
2) Automatic index re-calculation
3) More efficient memory handling avoiding use of unset()

I languages like C++ an array class is a life saver, as it takes care of memory allocation, etc for you, but PHP kinda does that for you...so I need more reasons than mentioned above...

So I ask, can anyone think of *good* reasons why an array container should be written outside of what I mentioned above???

psuedo-interface:

Code: Select all

//
// Implements a single dimensional array
class CxArray{
  function getCount();
  function isEmpty();
  function removeAll();

  function freeUnused(); // Remove all elements set as FALSE

  function fromArray(); // Merge another array with this array

  function addElement();
  function appendElement();

  function removeElement(); // Sets element as FALSE
  function insertElement();
}
Rough draft I just sorta copied from MFC, so it's not complete, as I am trying to figure out how to reuse this class as a composite in my multi-dimensional array as well...

Are there any caveats of PHP arrays, like re-calculating indicies, which as container class could handle or take care of, therefore making it worth while in implementing???

Cheers :)