Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2892022
PhutilSortVector.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
1 KB
Referenced Files
None
Subscribers
None
PhutilSortVector.php
View Options
<?php
final
class
PhutilSortVector
extends
Phobject
{
private
$parts
=
array
(
)
;
public
function
addInt
(
$value
)
{
// We need to produce strings for each integer which sort naturally. This
// requires some careful manipulation.
if
(
$value
===
~
PHP_INT_MAX
)
{
// For the minimum integer value (usually -9223372036854775808 on 64
// bit systems) we just give it a special "A" prefix to make sure it
// sorts first.
$prefix
=
'A'
;
}
else
if
(
$value
<
0
)
{
// For all other negative values, we give them a "B" prefix, then
// subtract the value from the maximum integer. This sorts values
// in ascending order when printed.
$prefix
=
'B'
;
$value
=
PHP_INT_MAX
+
$value
;
}
else
{
// For zero and positive values, we give them a "C" prefix.
$prefix
=
'C'
;
}
$this
->
parts
[
]
=
sprintf
(
'%s%020u'
,
$prefix
,
$value
)
;
return
$this
;
}
public
function
addString
(
$value
)
{
if
(
strlen
(
$value
)
&&
(
strpos
(
$value
,
"\0"
)
!==
false
)
)
{
throw
new
Exception
(
pht
(
'String components of a sort vector must not contain NULL bytes.'
)
)
;
}
$this
->
parts
[
]
=
$value
;
return
$this
;
}
public
function
__toString
(
)
{
return
implode
(
"\0"
,
$this
->
parts
)
;
}
/**
* This allows you to sort a list of sort vectors using @{function:msortv}.
*/
public
function
getSelf
(
)
{
return
$this
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Jan 19, 16:05 (2 w, 6 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1115562
Default Alt Text
PhutilSortVector.php (1 KB)
Attached To
Mode
rARC Arcanist
Attached
Detach File
Event Timeline
Log In to Comment