Fix clone + add tests

This commit is contained in:
Etienne Kneuss 2008-08-03 19:07:22 +00:00
parent ac1204b7eb
commit 1c23174d9d
3 changed files with 40 additions and 0 deletions

View File

@ -397,7 +397,13 @@ static zend_object_value spl_heap_object_new_ex(zend_class_entry *class_type, sp
intern->ce_get_iterator = other->ce_get_iterator;
if (clone_orig) {
int i;
intern->heap = spl_ptr_heap_clone(other->heap TSRMLS_CC);
for (i = 0; i < intern->heap->count; ++i) {
if (intern->heap->elements[i]) {
Z_ADDREF_P((zval *)intern->heap->elements[i]);
}
}
} else {
intern->heap = other->heap;
}

View File

@ -32,7 +32,9 @@ $b = 4;
$h->insert($b);
$b = 5;
$h2 = clone $h;
echo $h->extract()."\n";
echo $h2->extract()."\n";
?>
===DONE===
<?php exit(0); ?>
@ -47,4 +49,5 @@ Exception: Can't extract from an empty heap
0
--
4
4
===DONE===

View File

@ -0,0 +1,31 @@
--TEST--
SPL: SplHeap with overriden compare()
--FILE--
<?php
class SplMinHeap2 extends SplMinHeap {
public function compare($a, $b) {
return -parent::compare($a,$b);
}
}
$h = new SplMinHeap2();
$h->insert(1);
$h->insert(6);
$h->insert(5);
$h->insert(2);
var_dump($h->top());
class SplMaxHeap2 extends SplMaxHeap {
public function compare($a, $b) {
return -parent::compare($a,$b);
}
}
$h = new SplMaxHeap2();
$h->insert(1);
$h->insert(6);
$h->insert(5);
$h->insert(2);
var_dump($h->top());
?>
--EXPECT--
int(6)
int(1)