Skip to content

Best Practices

Doğan Can Uçar edited this page Sep 11, 2018 · 3 revisions

Comparing objects within the library's classes

Sorting and searching consists a lot of comparing. Implement doganoo\PHPAlgorithms\Common\Interfaces\IComparable if you want PHPAlgorithms to work best when comparing your own classes\objects. The implementation is based on PHP's strcmp() method. The method returns an integer with the following meaning:

  • 0: object1 equals object2
  • -1: object1 less than object2
  • 1: object1 greater than object2

JSON serializing

I try to make every data structure class of the library JSON serializable. To serialize each object within a data structure, make sure that you also implement the JsonSerializable interface.

Clone this wiki locally