Skip to content

Commit 2403f0a

Browse files
committed
Explicit cmp function
1 parent a2346a8 commit 2403f0a

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

lib/RangeDB.php

+8-17
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ function save(string $file) {
6666
// });
6767
// }
6868

69-
function sort($mode = "Start") {
70-
usort($this->ranges, ["Range", "cmp$mode"]);
69+
function sort(string $cmpFunction) {
70+
usort($this->ranges, ["Range", $cmpFunction]);
7171
}
7272

73-
function equals($compact = true) {
73+
function equals() {
7474
$deleted = 0;
7575
$i = $this->recCount;
7676

77-
$this->sort("Start");
77+
$this->sort("cmpStart");
7878
for($r = 0; $r < $i - 1; $r++) {
7979
if(!isset($this->ranges[$r]))
8080
continue;
@@ -110,18 +110,15 @@ function equals($compact = true) {
110110
}
111111
}
112112

113-
// if($compact)
114-
// $this->compact();
115-
116113
return $deleted;
117114
}
118115

119116
# TODO: remove?
120-
function overlapopen($compact = true) {
117+
function overlapopen() {
121118
$deleted = 0;
122119
$i = $this->recCount;
123120

124-
$this->sort("Start");
121+
$this->sort("cmpStart");
125122
for($r = 0; $r < $i - 1; $r++) {
126123
if(!isset($this->ranges[$r]))
127124
continue;
@@ -144,18 +141,15 @@ function overlapopen($compact = true) {
144141
}
145142
}
146143

147-
// if($compact)
148-
// $this->compact();
149-
150144
return $deleted;
151145
}
152146

153-
function overlap($compact = true) {
147+
function overlap() {
154148
$deleted = 0;
155149

156150
$i = $this->recCount;
157151

158-
$this->sort("Start");
152+
$this->sort("cmpStart");
159153
for($r = 0; $r < $i - 1; $r++) {
160154
if(!isset($this->ranges[$r]))
161155
continue;
@@ -176,9 +170,6 @@ function overlap($compact = true) {
176170
}
177171
}
178172

179-
// if($compact)
180-
// $this->compact();
181-
182173
return $deleted;
183174
}
184175
}

step3-combine-all.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function usage(){
5959
print "DONE\n";
6060

6161
print "Sorting...";
62-
$db->sort();
62+
$db->sort("cmpStart");
6363
print "DONE\n";
6464

6565
print "Saving $COMBINED...";

tests/tree1.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $db->addRecord(new CountryRange('LV', 5,6));
2424
$db->addRecord(new CountryRange('LV', 6,6));
2525
$db->addRecord(new CountryRange('LV', 7,8));
2626

27-
$db->sort();
27+
$db->sort("cmpStart");
2828
$data = $db->getRanges();
2929

3030
$root = build_tree($data, 0, count($data) - 1);

0 commit comments

Comments
 (0)