forked from facebook/hhvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Now that Sets retain insertion order it would be handy if Sets could be sorted using PHP's sort builtin functions. This diff leverages to shared implementation between Map and Set to enable sorting for Sets. Reviewed By: ptc, eletuchy Differential Revision: D1435214
- Loading branch information
1 parent
ea92f3b
commit 89ec52e
Showing
3 changed files
with
157 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?hh | ||
function main() { | ||
for ($i = 0; $i < 8; ++$i) { | ||
if ($i < 4) { | ||
$s = Set {3, 4, 1, 2}; | ||
} else { | ||
$s = Set {'b', 'a', 'd', 'c'}; | ||
} | ||
var_dump($s); | ||
switch ($i % 4) { | ||
case 0: asort($s); break; | ||
case 1: ksort($s); break; | ||
case 2: | ||
uasort($s, | ||
function ($l, $r) { return $l < $r ? -1 : ($l === $r ? 0 : 1); }); | ||
break; | ||
case 3: | ||
uksort($s, | ||
function ($l, $r) { return $l < $r ? -1 : ($l === $r ? 0 : 1); }); | ||
break; | ||
} | ||
var_dump($s); | ||
unset($s); | ||
echo "----\n"; | ||
} | ||
} | ||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
object(HH\Set)#1 (4) { | ||
int(3) | ||
int(4) | ||
int(1) | ||
int(2) | ||
} | ||
object(HH\Set)#1 (4) { | ||
int(1) | ||
int(2) | ||
int(3) | ||
int(4) | ||
} | ||
---- | ||
object(HH\Set)#1 (4) { | ||
int(3) | ||
int(4) | ||
int(1) | ||
int(2) | ||
} | ||
object(HH\Set)#1 (4) { | ||
int(1) | ||
int(2) | ||
int(3) | ||
int(4) | ||
} | ||
---- | ||
object(HH\Set)#1 (4) { | ||
int(3) | ||
int(4) | ||
int(1) | ||
int(2) | ||
} | ||
object(HH\Set)#1 (4) { | ||
int(1) | ||
int(2) | ||
int(3) | ||
int(4) | ||
} | ||
---- | ||
object(HH\Set)#1 (4) { | ||
int(3) | ||
int(4) | ||
int(1) | ||
int(2) | ||
} | ||
object(HH\Set)#1 (4) { | ||
int(1) | ||
int(2) | ||
int(3) | ||
int(4) | ||
} | ||
---- | ||
object(HH\Set)#1 (4) { | ||
string(1) "b" | ||
string(1) "a" | ||
string(1) "d" | ||
string(1) "c" | ||
} | ||
object(HH\Set)#1 (4) { | ||
string(1) "a" | ||
string(1) "b" | ||
string(1) "c" | ||
string(1) "d" | ||
} | ||
---- | ||
object(HH\Set)#1 (4) { | ||
string(1) "b" | ||
string(1) "a" | ||
string(1) "d" | ||
string(1) "c" | ||
} | ||
object(HH\Set)#1 (4) { | ||
string(1) "a" | ||
string(1) "b" | ||
string(1) "c" | ||
string(1) "d" | ||
} | ||
---- | ||
object(HH\Set)#1 (4) { | ||
string(1) "b" | ||
string(1) "a" | ||
string(1) "d" | ||
string(1) "c" | ||
} | ||
object(HH\Set)#1 (4) { | ||
string(1) "a" | ||
string(1) "b" | ||
string(1) "c" | ||
string(1) "d" | ||
} | ||
---- | ||
object(HH\Set)#1 (4) { | ||
string(1) "b" | ||
string(1) "a" | ||
string(1) "d" | ||
string(1) "c" | ||
} | ||
object(HH\Set)#1 (4) { | ||
string(1) "a" | ||
string(1) "b" | ||
string(1) "c" | ||
string(1) "d" | ||
} | ||
---- |