Archive - May 13, 2007

Date

Sacrifice a slight amount of memory for the amazing speed

My last statement on array_shift about there is no point of using array_shift bring some controversy. Jeff Standen pointed out that queue and stack can be done by array_shift() and array_pop() with a reasonable speed.
After some testing, I agrees that array_pop() is reasonable, and it's the most fit way to implement a stack because the popping action runs in O(1) time. Although I still have to disagree with using array_shift() for queue.

To support what I said before, I created a queue system that uses slightly more memory but much faster than the array_shift() implementation.
The queue class I fixed up in a few minute

class queue{
	var $q;
	var $p=0;
 
	function enqueue($stuff=null){
		$this->q[]=$stuff;
	}
	function dequeue(){
		$a = $this->q[$this->p];
		unset($this->q[$this->p++]);
		return $a;
	}
}
$queue = new queue;
//add things to queue 
$queue->enqueue('stuff');
//take things out
$queue->dequeue();

The usual native array queue:

$queue = array();
//add something in the queue
$queue[] = 'stuff';
//take something out
array_shift($queue);

The queue class I fixed is slightly slower in the enqueue process, but each dequeuing is running in O(1) time, while the native way running in O(n) time.

Time to say my most famous line in past month1
I can't think of any time that you need to use array_shift().

  1. 1. "I live in Long Island state" comes 2nd.

Vogoo PHP LIB

Vogoo logo
When ever there is a lot of content spreading around, the content filtering is a pain for anyone. Vogoo PHP LIB successfully implements the slope one rating based collaborative filtering algorithm. With the help of more than one person, it's much easier to recommend content to specific person.
Websites might want to use this library when it offers loads of resources on multi-aspects(is there any?).

Notes for May 13

in

I tried my best to avoid go to NYC because i want to use the computer at home.
The struggle...
Me: No, I'm not going
Mum: Go, go there so I can take photos.
Me: I hate photos.
Mum: How about go for me?
Me: (damn I hate when she uses this to make me feel guilty.. think think...ahhh!!) I have AP bio test tomorrow so I have to study.
Mum: seems like you can't go then... then go next week.
Me: (ZOMG I'm dying here..)

Ghetto Asians...
"Yo, what's up brother"
"nothing, man, just synthesizing proteins from artificial amino acids"
"word!"

Honey Pot that kill bots