4

After googling for a bit it seems there's no documentation on the complexity of each of the SPL functions. Has anyone came across with some of information on this aspect?

Mihai Stancu
  • 14,701
  • 2
  • 30
  • 49
manei_cc
  • 175
  • 2
  • 10

1 Answers1

1

PHP Architect has a book called Mastering the SPL LIbrary The section on data structures has a table with the code complexity for all data structures for the following operations:

  • Insert elements at the beginning I
  • Insert elements at the end
  • Insert elements in the middle
  • Delete elements from the beginning
  • Delete elements from the end
  • Delete elements from the middle
  • Sequential read
  • Random reads

You will be surprised how many of these operations are O(1), yet the actual speed can be different because some data structures make better use of memory.

I definitely suggest getting the book as it has some helpful information.

Onema
  • 6,423
  • 11
  • 61
  • 97
  • 1
    I'm halfway the mentioned book and I've got to say it's pretty interesting so far. Found exactly what I was looking for, a nice table with the comparison of the different data structures [table](http://bit.ly/1AyZMSB). It seems PHP Array is by default a solid choice, as long as no collisions are produced, which probability is quite low according to this [thread](http://stackoverflow.com/questions/14210298/probability-of-collision-crc32#answer-14210379) and the documentation in the book. The book is a very nice and in depth study of the SPL Library. – manei_cc Jul 30 '14 at 16:28
  • A good book indeed. Other data structures can be used when the data-sets are large enough that memory or sorting become a problem. Personally the linked list is currently one of my favorite SPL data structures and I'm starting to use in different use cases. The ability to go back and forward is nice, plus it can act as a queue or a stack! – Onema Jul 30 '14 at 18:02