wxxiong6/php-ext-arraylist

Repository files navigation

Build Status

ArrayList是一个使用C实现类似于Java ArrayList的高性能扩展。 适用于构建超大数组,比原生数组创建数组使用时间更快,内存占用量更少。

php7.0 +

phpize
./configure --enable-arraylist
make
make install

下载源码自行编译

ArrayList implements ArrayAccess, Countable {
    /* 方法 */
    public __construct ([ int $size = 0 ] )
    public count ( void ) : int
    public getSize ( void ) : int
    public get ( int $index ) : mixed
    public add (mixed $newval ) : void
    public toArray ( void ) : array
}
$ret = new ArrayList();
$ret[] = 1; // 也可以使用 $ret->add(1); 
$ret[0];    // 也可以使用 $ret->get(0);
$ret->count();
$ret->getSize();
$ret->toArray();
const SIZE = 20;
$ret2 = new ArrayList();
$ret3 = new ArrayList();
for ($i = 0; $i < SIZE; $i++)
{
    $ret2->add((string)$i);
    $ret3->add((string)(SIZE-$i));
}
$ret = new Arraylist();
$ret->add($ret2);
$ret->add($ret3);
for ($i = 0; $i < $ret->count(); $i++) {
    for($j = 0; $j < $ret->get($i)->count(); $j++) {
        var_dump($ret->get($i)->get($j));
    }
    echo "\n";
}
$ret = new ArrayList();
$ret->add([1, 3, 4, 5, 6,]);
$ret->add([8, 9, 10]);
for ($i = 0; $i< $ret->count(); $i++) {
    foreach($ret->get($i) as $v){
        var_dump($v);
    }
}
Testing sizeArrayListArray
1,0000.00059604644775391
16.1875
0.00033903121948242
19.9375
2,0000.00047087669372559
32.1875
0.00060915946960449
35.9375
4,0000.00081586837768555
64.1875
0.00076293945312500
67.9375
8,0000.00094485282897949
128.1875
0.00123691558837890
131.9375
2,048,0000.19431805610657
32000.28125
0.32430100440979
33539.9375
4,096,0000.44307684898376
64000.28125
0.67080807685852
67075.9375

About

ArrayList是一个使用C实现类似于Java ArrayList的高性能扩展。 适用于构建超大数组,比原生数组创建数组使用时间更快,内存占用量更少。

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published