File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,10 @@ method clear() {
104104 @ ! nodes = ();
105105}
106106
107+ method clone {
108+ nextwith (: type($ . type . clone ), : nodes(@ . nodes . clone ))
109+ }
110+
107111method ! bubble-up ($ index ) {
108112 if (self ! is-minlevel($ index )) {
109113 if (self ! has-parent($ index ) and (@ ! nodes [$ index ] minmaxheap-cmp @ ! nodes [self ! find-parent($ index )] == Order ::More)) {
Original file line number Diff line number Diff line change 1+ use v6 ;
2+ use Test ;
3+ use Algorithm::MinMaxHeap;
4+
5+ {
6+ my $ heap = Algorithm::MinMaxHeap. new ();
7+ $ heap . insert(0 );
8+ $ heap . insert(1 );
9+ $ heap . insert(2 );
10+ $ heap . insert(3 );
11+ $ heap . insert(4 );
12+ $ heap . insert(5 );
13+ $ heap . insert(6 );
14+ $ heap . insert(7 );
15+ $ heap . insert(8 );
16+
17+ is $ heap . nodes. elems , 9 ;
18+
19+ my $ clone-heap = $ heap . clone ;
20+ is $ clone-heap . nodes, $ heap . nodes;
21+ $ heap . clear();
22+ is $ clone-heap . nodes. elems , 9 ;
23+ is $ clone-heap . type === Int , True ;
24+ }
25+
26+ done-testing ;
You can’t perform that action at this time.
0 commit comments