2017 © Pedro Peláez
 

library typed-array

Linna Typed Array

image

linna/typed-array

Linna Typed Array

  • Sunday, June 17, 2018
  • by s3b4stian
  • Repository
  • 1 Watchers
  • 1 Stars
  • 856 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 8 % Grown

The README.md

Linna Logo

br/, (*1)

Linna dotenv Logo

br/, (*2)

[![Tests](https://github.com/linna/typed-array/actions/workflows/tests.yml/badge.svg)](https://github.com/linna/typed-array/actions/workflows/tests.yml) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=linna_typed-array&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=linna_typed-array) [![PDS Skeleton](https://img.shields.io/badge/pds-skeleton-blue.svg?style=flat)](https://github.com/php-pds/skeleton) [![PHP 8.1](https://img.shields.io/badge/PHP-8.1-8892BF.svg)](http://php.net)

About

This package provide typed arrays for php as extension of native ArrayObject., (*3)

Requirements

This package require php 8.1, (*4)

Installation

With composer:, (*5)

composer require linna/typed-array

Classes

Name Native Type Handled Description
ArrayOfArrays array
ArrayOfBooleans bool
ArrayOfCallable callable
ArrayOfClasses any existing class passed as first argument in constructor as ::class
ArrayOfFloats float
ArrayOfIntegers int
ArrayOfObjects object
ArrayOfStrings string

Usage

use Linna\TypedArrayObject\ArrayOfIntegers;
use Linna\TypedArrayObject\ArrayOfClasses;

//correct, only int passed to constructor.
$intArray = new ArrayOfIntegers([1, 2, 3, 4]);

//correct, int assigned
$intArray[] = 5;
//throw InvalidArgumentException, string assigned, int expected.
$intArray[] = 'a';

//correct, int used
$intArray->append(5);
//throw InvalidArgumentException, string used, int expected.
$intArray->append('a');

//throw InvalidArgumentException, mixed array passed to constructor.
$otherIntArray = new ArrayOfIntegers([1, 'a', 3, 4]);

//correct, only Foo class instances passed to constructor.
$fooArray = new ArrayOfClasses(Foo::class, [
    new Foo(),
    new Foo()
]);

//correct, Foo() instance assigned.
$fooArray[] = new Foo();
//throw InvalidArgumentException, Bar() instance assigned.
$fooArray[] = new Bar();

//correct, Foo() instance used.
$fooArray->append(new Foo());
//throw InvalidArgumentException, Bar() instance used, Foo() instance expected.
$fooArray->append(new Bar());

//throw InvalidArgumentException, mixed array of instances passed to constructor.
$otherFooArray = new ArrayOfClasses(Foo::class, [
    new Foo(),
    new Bar()
]);

Note: Allowed types are: array, bool, callable, float, int, object, string and all existing classes., (*6)

Performance consideration for v3.0

Compared to previous versions of the library, this version is a bit faster because every types has it own class. Do milliseconds really matters?, (*7)

Array Speed Test, (*8)

Performance consideration for v2.0

Compared to first version of the library, this version is a bit slower because after merging TypedObjectArray with TypedArray, there are more code that be executed when new instance is created and on assign operations., (*9)

Array Speed Test, (*10)

Performance consideration for v1.0

Compared to the parent class ArrayObject typed arrays are slower on writing approximately from 6x to 8x. The slowness is due to not native __construct() and not native offsetSet().
Other operations do not have a speed difference with the native ArrayObject., (*11)

use Linna\TypedArray;

//slower from 6x to 8x.
$array = new TypedArray('int', [1, 2, 3, 4]);
$array[] = 5;

//other operations, fast as native.
//for example:
$arrayElement = $array[0];
$elements = $array->count();

Array Speed Test View the speed test script on gist., (*12)

The Versions

17/06 2018

dev-master

9999999-dev https://github.com/linna/typed-array

Linna Typed Array

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php array typed array

26/10 2017

v1.0.4

1.0.4.0 https://github.com/linna/typed-array

Linna Typed Array

  Sources   Download

MIT

The Requires

  • php ^7.0.0

 

The Development Requires

php array typed array

24/08 2017

v1.0.3

1.0.3.0 https://github.com/linna/typed-array

Linna Typed Array

  Sources   Download

MIT

The Requires

  • php ^7.0.0

 

php array typed array

24/06 2017

v1.0.2

1.0.2.0

Linna Typed Array

  Sources   Download

MIT

The Requires

  • php ^7.0.0

 

php array typed array

11/06 2017

v1.0.1

1.0.1.0

Linna Array

  Sources   Download

MIT

The Requires

  • php ^7.0.0

 

php array typed array

07/06 2017

v1.0.0

1.0.0.0

Linna Array

  Sources   Download

MIT

The Requires

  • php ^7.0.0

 

php array typed array