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

Language PHP Lines 59
MD5 Hash 5167eb74f81907055d67649e78904ac1 Estimated Cost $1,090 (why?)
Repository git://github.com/facebook/hiphop-php.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php

function getQueueWithLittleData() {
  $q = new SplPriorityQueue();
  $q->insert('dux', 4);
  $q->insert('legati', 3);
  $q->insert('centurion', 2);
  $q->insert('munifex', 1);
  return $q;
}

function testExtractFlags() {
  $flags = array(
    array('SplPriorityQueue::EXTR_DATA', SplPriorityQueue::EXTR_DATA),
    array('SplPriorityQueue::EXTR_PRIORITY', SplPriorityQueue::EXTR_PRIORITY),
    array('SplPriorityQueue::EXTR_BOTH', SplPriorityQueue::EXTR_BOTH),
  );
  $sources = array(
    getQueueWithLittleData(),
    clone getQueueWithLittleData(),
  );
  foreach ($sources as $queue) {
    foreach ($flags as $flagInfo) {
      list($name, $value) = $flagInfo;
      testExtractFlag($queue, $name, $value);
    }
  }
}

function testExtractFlag($q, $flagName, $flagValue) {
  $q->setExtractFlags($flagValue);
  echo "Get top with $flagName:\n";
  print_r($q->top());
  echo "\n";

  $q->rewind();
  $q->next();
  $q->valid();

  echo "Second in rank with $flagName:\n";
  print_r($q->current());
  echo "\n";

  echo "\n";
}
testExtractFlags();


function testCloneGivesValidCopy() {
  $q = getQueueWithLittleData();
  $clonedQueue = clone $q;

  $clonedQueue->top();

  echo "Top rank (even after killing the top in a clone) is: ";
  echo $q->top() . "\n";
}
testCloneGivesValidCopy();
Back to Top