I've been coding in php of late. So some thoughts on that...
Most languages have a few Data Structures (ds). Java has the excellent Collections framework which contains quite a few types of ds as shown in the figure
What I found in php was the array();
It can be used like...
$pasta = array('spaghetti', 'penne', 'macaroni');
In this case the array can be compared to a List or an Array.
You can also add an element to the end of an existing array with the array_push() function or remove an element from the end by using the array_pop() function.
Using the array_shift() and the array_unshift() function removing or adding elements to the beginning of the array can be done.
So now the array can work both as a Queue and a Stack.
Additionally it is possible to declare an array like..
$menu = array('breakfast' => 'bacon and eggs', 'lunch' => 'roast beef', 'dinner' => 'lasagna');
Here 'breakfast' is a key and 'bacon and eggs' is the value. Usually keys are numbers from 0 onwards. In effect our innocent array is now a Map as well.
All this is extremely great for learners. A few thoughts ..
1. The array exposes an API for all these ds'es. How can I enforce an array to act only as a Queue? Is the leakage of the abstraction too much.
2. How do they optimize? In Java I know the costs when I create a LinkedList or an ArrayList. Or use a TreeMap or HashMap. How is it done in php?
3. Also are there Sets in php where one object cannot be added twice. Maybe I am missing some ds library in php ;)
Thursday, June 29, 2006
Friday, June 23, 2006
Wednesday, June 21, 2006
Binary Search is broken
Courtesy Joshua Bloch (aka Java god) - Extra, Extra - Read All About It: Nearly All Binary Searches and Mergesorts are Broken
Can be filed for the next edition of Java Puzzlers.
Can be filed for the next edition of Java Puzzlers.
Tuesday, June 20, 2006
Get Functional
This article - Functional Programming for the rest of us - is like Argentina's performance against Serbia-Montenegro... beautiful.
Wednesday, June 07, 2006
Re: Have you ever felt this?
The "there's got to be more to life than this" deamon thread gets activated often. It's still at a way low priority level as compared to that dude but dunno for how long.
Saturday, June 03, 2006
Subscribe to:
Posts (Atom)