Live data from Hacker News

PHP 7's new hashtable implementation

nikic.github.io

11–20 of 137 posts

Re: PHP 7's new hashtable implementation

#11
post #8
post #7

This is great news. PHP doesn't have many structured data types, so arrays (aka maps) are basically used for everything. Any improvement to them will impact the entire application. It would be nice to have separate types for arrays and maps though. I don't understand why they were combined to begin with. Simplicity? Seems like there are more edge cases and gotchas the way things are now.

> It would be nice to have separate types for arrays and hash tables though. I don't understand why they were combined to begin with. Simplicity? Seems like there are more edge cases and gotchas the way things are now. There is no "hash table" type in PHP user land.

[deleted]

Re: PHP 7's new hashtable implementation

#12
This is neat. Looking through it, looks like it makes regular numeric arrays faster as well via the flags.

I wonder if the ->pDataPtr vs ->pData confusion has been resolved.

I'm probably a few years behind, but a lot of my confusion working with hashes has been that pair of void* pointers.

Re: PHP 7's new hashtable implementation

#13
post #8

Earlier quoted context omitted.

> It would be nice to have separate types for arrays and hash tables though. I don't understand why they were combined to begin with. Simplicity? Seems like there are more edge cases and gotchas the way things are now. There is no "hash table" type in PHP user land.

There are no arrays in PHP. There are only hash tables that are called "array" for simplicity.

You made my day, guys, please don't stop :)

Re: PHP 7's new hashtable implementation

#14
post #7

This is great news. PHP doesn't have many structured data types, so arrays (aka maps) are basically used for everything. Any improvement to them will impact the entire application. It would be nice to have separate types for arrays and maps though. I don't understand why they were combined to begin with. Simplicity? Seems like there are more edge cases and gotchas the way things are now.

PHP has a standard library with plenty of collections: http://php.net/manual/en/book.spl.php

Stack - http://php.net/manual/en/book.spl.php Queue - http://php.net/manual/en/class.splqueue.php PriorityQueue - http://php.net/manual/en/class.splpriorityqueue.php Real Maps - http://php.net/manual/en/class.splobjectstorage.php

It's a shame some people are not aware of these.

Re: PHP 7's new hashtable implementation

#16
post #8

Earlier quoted context omitted.

> It would be nice to have separate types for arrays and hash tables though. I don't understand why they were combined to begin with. Simplicity? Seems like there are more edge cases and gotchas the way things are now. There is no "hash table" type in PHP user land.

There are no arrays in PHP. There are only hash tables that are called "array" for simplicity.

How do they maintain their order?

Re: PHP 7's new hashtable implementation

#17

Earlier quoted context omitted.

There are no arrays in PHP. There are only hash tables that are called "array" for simplicity.

How do they maintain their order?

You put things in order by memory address and they stay in order when you access them. An array is just a special case of a hash map -- one with a trivial hash function.

That's why the lend themselves to the same syntax so well.

Re: PHP 7's new hashtable implementation

#18
post #14
post #7

This is great news. PHP doesn't have many structured data types, so arrays (aka maps) are basically used for everything. Any improvement to them will impact the entire application. It would be nice to have separate types for arrays and maps though. I don't understand why they were combined to begin with. Simplicity? Seems like there are more edge cases and gotchas the way things are now.

PHP has a standard library with plenty of collections: http://php.net/manual/en/book.spl.php Stack - http://php.net/manual/en/book.spl.php Queue - http://php.net/manual/en/class.splqueue.php PriorityQueue - http://php.net/manual/en/class.splpriorityqueue.php Real Maps - http://php.net/manual/en/class.splobjectstorage.php It's a shame some people are not aware of these.

No primitive types: tuples, lists, sets. Having only arrays to work with and being weak typed results in a lot of headache.

Re: PHP 7's new hashtable implementation

#20

Earlier quoted context omitted.

There are no arrays in PHP. There are only hash tables that are called "array" for simplicity.

How do they maintain their order?

By using a doubly linked list, where the first element in the "bucket", contains the next pointer to the next element in the hash table. Read zend_hash.h & zend_hash.c It is fairly complicated and explaining it in depth is beyond the scope of this comment.

This "bucket" also handles the collisions by using separate chaining. There is actually two "next" pointers, one for the chains, and one for the next element in order of insertion. Very confusing and requires reading through the code and playing with it.

Post reply on HN