<commit_before><?php

namespace Pinq;

DEFINE('IS_PHP_55', version_compare(PHP_VERSION, '5.5', '>='));

final class Utilities
{
    private function __construct() { }

    public static $Identical = [__CLASS__, 'Identical'];

    public static function Identical($One, $Two)
    {
        return $One === $Two;
    }

    public static $Comparison = [__CLASS__, 'Compare'];

    public static function Compare($One, $Two)
    {
        if($One === $Two || $One == $Two) {
            return 0;
        }
        
        return $One > $Two ? 1 : -1;
    }

    public static function IsTransitive(array $Array)
    {
        foreach($Array as $Value) {
            if(is_string($Value) || is_integer($Value)) {
                continue;
            }
            return false;
        }
        
        return true;
    }
    
    public static function GetTypeOrClass($Value)
    {
        return is_object($Value) ? get_class($Value) : gettype($Value);
    }
    
    public static function ToArray(\Traversable $Iterator)
    {
        if($Iterator instanceof \ArrayIterator || $Iterator instanceof \ArrayObject) {
            return $Iterator->getArrayCopy();
        }
        
        $Array = [];
        
        if(IS_PHP_55) {
            foreach($Iterator as $Key => $Value) {
                $Array[$Key] = $Value;
            }
        }
        else {
            //Does not support returning custom keys
            $Iterator->rewind();
            while ($Iterator->valid()) {
                $Array[$Iterator->key()] = $Iterator->current();
                $Iterator->next();
            }
        }
        
        return $Array;
    }
    
    /**
     * @return \Iterator
     */
    public static function ToIterator($TraversableOrArray)
    {
        if(!is_array($TraversableOrArray) && !($TraversableOrArray instanceof \Traversable)) {
            throw new PinqException(
                    'Invalid argument for %s: expecting array or \Traversable, %s given',
                    __METHOD__,
                    self::GetTypeOrClass($TraversableOrArray));
        }
        
        if($TraversableOrArray instanceof \Iterator) {
            return $TraversableOrArray;
        }
        else if($TraversableOrArray instanceof \IteratorAggregate) {
            return $TraversableOrArray->getIterator();
        }
        else if($TraversableOrArray instanceof \Traversable) {
            return new \IteratorIterator($TraversableOrArray);
        }
        else {
            return new \ArrayIterator($TraversableOrArray);
        }
    }
    
    public static function MultisortPreserveKeys(array $OrderArguments, array &$ArrayToSort)
    {
        $StringKeysArray = [];
        foreach ($ArrayToSort as $Key => $Value) {
            $StringKeysArray['a' . $Key] = $Value;
        }
        
        if(!defined('HHVM_VERSION')) {
            $OrderArguments[] =& $StringKeysArray;
            call_user_func_array('array_multisort', $OrderArguments);
        }
        else {
            //HHVM Compatibility: hhvm array_multisort wants all argument by ref?
            $ReferencedOrderArguments = [];
            foreach($OrderArguments as $Key => $OrderArgument) {
                $ReferencedOrderArguments[] =& $OrderArgument;
                unset($OrderArgument);
            }
            $ReferencedOrderArguments[] =& $StringKeysArray;
            
            call_user_func_array('array_multisort', $ReferencedOrderArguments);
        }
        
        $UnserializedKeyArray = [];
        foreach ($StringKeysArray as $Key => $Value) {
            $UnserializedKeyArray[substr($Key, 1)] = $Value;
        }
        
        $ArrayToSort = $UnserializedKeyArray;
    }
}<commit_msg>HHVM test<commit_after><?php

namespace Pinq;

DEFINE('IS_PHP_55', version_compare(PHP_VERSION, '5.5', '>='));

final class Utilities
{
    private function __construct() { }

    public static $Identical = [__CLASS__, 'Identical'];

    public static function Identical($One, $Two)
    {
        return $One === $Two;
    }

    public static $Comparison = [__CLASS__, 'Compare'];

    public static function Compare($One, $Two)
    {
        if($One === $Two || $One == $Two) {
            return 0;
        }
        
        return $One > $Two ? 1 : -1;
    }

    public static function IsTransitive(array $Array)
    {
        foreach($Array as $Value) {
            if(is_string($Value) || is_integer($Value)) {
                continue;
            }
            return false;
        }
        
        return true;
    }
    
    public static function GetTypeOrClass($Value)
    {
        return is_object($Value) ? get_class($Value) : gettype($Value);
    }
    
    public static function ToArray(\Traversable $Iterator)
    {
        if($Iterator instanceof \ArrayIterator || $Iterator instanceof \ArrayObject) {
            return $Iterator->getArrayCopy();
        }
        
        $Array = [];
        
        if(IS_PHP_55) {
            foreach($Iterator as $Key => $Value) {
                $Array[$Key] = $Value;
            }
        }
        else {
            //Does not support returning custom keys
            $Iterator->rewind();
            while ($Iterator->valid()) {
                $Array[$Iterator->key()] = $Iterator->current();
                $Iterator->next();
            }
        }
        
        return $Array;
    }
    
    /**
     * @return \Iterator
     */
    public static function ToIterator($TraversableOrArray)
    {
        if(!is_array($TraversableOrArray) && !($TraversableOrArray instanceof \Traversable)) {
            throw new PinqException(
                    'Invalid argument for %s: expecting array or \Traversable, %s given',
                    __METHOD__,
                    self::GetTypeOrClass($TraversableOrArray));
        }
        
        if($TraversableOrArray instanceof \Iterator) {
            return $TraversableOrArray;
        }
        else if($TraversableOrArray instanceof \IteratorAggregate) {
            return $TraversableOrArray->getIterator();
        }
        else if($TraversableOrArray instanceof \Traversable) {
            return new \IteratorIterator($TraversableOrArray);
        }
        else {
            return new \ArrayIterator($TraversableOrArray);
        }
    }
    
    public static function MultisortPreserveKeys(array $OrderArguments, array &$ArrayToSort)
    {
        $StringKeysArray = [];
        foreach ($ArrayToSort as $Key => $Value) {
            $StringKeysArray['a' . $Key] = $Value;
        }
        
        if(!defined('HHVM_VERSION')) {
            $OrderArguments[] =& $StringKeysArray;
            call_user_func_array('array_multisort', $OrderArguments);
        }
        else {
            //HHVM Compatibility: hhvm array_multisort wants all argument by ref?
            $ReferencedOrderArguments = [];
            foreach($OrderArguments as $Key => &$OrderArgument) {
                $ReferencedOrderArguments[$Key] =& $OrderArgument;
            }
            $ReferencedOrderArguments[] =& $StringKeysArray;
            
            call_user_func_array('array_multisort', $ReferencedOrderArguments);
        }
        
        $UnserializedKeyArray = [];
        foreach ($StringKeysArray as $Key => $Value) {
            $UnserializedKeyArray[substr($Key, 1)] = $Value;
        }
        
        $ArrayToSort = $UnserializedKeyArray;
    }
}
{'fraction_non_alphanumeric': 0.11596548004314995, 'fraction_numerical': 0.002696871628910464, 'mean_word_length': 1.8233726684430909, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3057313', 'n_tokens_mistral': 2044, 'n_tokens_neox': 1989, 'n_words': 412}