PageRenderTime 58ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/slow/ext_spl_datastructures/SplPriorityQueueClone.php

http://github.com/facebook/hiphop-php
PHP | 62 lines | 51 code | 11 blank | 0 comment | 0 complexity | 9c657f308241e8aa206832a7119d2966 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh
  2. function getQueueWithLittleData() {
  3. $q = new SplPriorityQueue();
  4. $q->insert('dux', 4);
  5. $q->insert('legati', 3);
  6. $q->insert('centurion', 2);
  7. $q->insert('munifex', 1);
  8. return $q;
  9. }
  10. function testExtractFlags() {
  11. $flags = varray[
  12. varray['SplPriorityQueue::EXTR_DATA', SplPriorityQueue::EXTR_DATA],
  13. varray['SplPriorityQueue::EXTR_PRIORITY', SplPriorityQueue::EXTR_PRIORITY],
  14. varray['SplPriorityQueue::EXTR_BOTH', SplPriorityQueue::EXTR_BOTH],
  15. ];
  16. $sources = varray[
  17. getQueueWithLittleData(),
  18. clone getQueueWithLittleData(),
  19. ];
  20. foreach ($sources as $queue) {
  21. foreach ($flags as $flagInfo) {
  22. list($name, $value) = $flagInfo;
  23. testExtractFlag($queue, $name, $value);
  24. }
  25. }
  26. }
  27. function testExtractFlag($q, $flagName, $flagValue) {
  28. $q->setExtractFlags($flagValue);
  29. echo "Get top with $flagName:\n";
  30. print_r($q->top());
  31. echo "\n";
  32. $q->rewind();
  33. $q->next();
  34. $q->valid();
  35. echo "Second in rank with $flagName:\n";
  36. print_r($q->current());
  37. echo "\n";
  38. echo "\n";
  39. }
  40. function testCloneGivesValidCopy() {
  41. $q = getQueueWithLittleData();
  42. $clonedQueue = clone $q;
  43. $clonedQueue->top();
  44. echo "Top rank (even after killing the top in a clone) is: ";
  45. echo $q->top() . "\n";
  46. }
  47. <<__EntryPoint>>
  48. function main_spl_priority_queue_clone() {
  49. testExtractFlags();
  50. testCloneGivesValidCopy();
  51. }