Tentative Extra Data Structures for php

Overview

Teds

Introduction

Build Status Build Status (Windows)

Teds is a another collection of data structures. (Tentative Extra Data Structures)

Installation

This extension requires php 8.0 or newer.

phpize
./configure
make install

On Windows, see https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2 instead

Functionality

Teds\ImmutableKeyValueSequence

Teds\ImmutableKeyValueSequence API

Currently, PHP does not provide a built-in way to store the state of an arbitrary iterable for reuse later (when the iterable has arbitrary keys, or when keys might be repeated). It would be useful to do so for many use cases, such as:

  1. Creating a rewindable copy of a non-rewindable Traversable (e.g. a Generator) before passing that copy to a function that consumes an iterable/Traversable. (new ImmutableKeyValueSequence(my_generator()))
  2. Generating an IteratorAggregate from a class still implementing Iterator (e.g. SplObjectStorage) so that code can independently iterate over the key-value sequences. (e.g. foreach ($immutableKeyValueSequence as $k1 => $v1) { foreach ($immutableKeyValueSequence as $k2 => $v2) { /* process pairs */ } })
  3. Providing helpers such as iterable_flip(iterable $iterable), iterable_take(iterable $iterable, int $limit), iterable_chunk(iterable $iterable, int $chunk_size) that act on iterables with arbitrary key/value sequences and have return values including iterables with arbitrary key/value sequences
  4. Providing constant time access to both keys and values of arbitrary key-value sequences at any offset (for binary searching on keys and/or values, etc.)

Having this implemented as a native class would also allow it to be much more efficient than a userland solution (in terms of time to create, time to iterate over the result, and total memory usage).

Objects within this data structure or references in arrays in this data structure can still be mutated.

Teds\ImmutableSequence

Teds\ImmutableKeyValueSequence API

Similar to SplFixedArray or Ds\Sequence, but immutable. This stores a sequence of values with the keys 0, 1, 2....

Teds\Vector

Teds\Vector API

Similar to SplFixedArray or Ds\Vector. This stores a mutable sequence of values with the keys 0, 1, 2... It can be appended to with push(), and elements can be removed from the end with pop()

This is implemented based on SplFixedArray/ImmutableSequence. There are plans to add more methods.

Teds\KeyValueVector

Teds\KeyValueVector API

Similar to Teds\Vector and Teds\ImmutableKeyValueSequence. This stores a mutable vector of keys and values with the keys 0, 1, 2... It can be resized with setSize().

Teds\Deque

Teds\Deque API

Similar to SplDoublyLinkedList but backed by an array instead of a linked list. Much more efficient in memory usage and random access than SplDoublyLinkedList.

(Also similar to Ds\Deque)

iterable functions

This PECL contains a library of native implementations of various functions acting on iterables. See teds.stub.php for function signatures.

The behavior is equivalent to the following polyfill (similarly to array_filter, the native implementation is likely faster than the polyfill with no callback, and slower with a callback)

namespace Teds;

/**
 * Determines whether any element of the iterable satisfies the predicate.
 *
 * If the value returned by the callback is truthy
 * (e.g. true, non-zero number, non-empty array, truthy object, etc.),
 * this is treated as satisfying the predicate.
 *
 * @param iterable $iterable
 * @param null|callable(mixed):mixed $callback
 */
function any(iterable $iterable, ?callable $callback = null): bool {
    foreach ($iterable as $v) {
        if ($callback !== null ? $callback($v) : $v) {
            return true;
        }
    }
    return false;
}
/**
 * Determines whether all elements of the iterable satisfy the predicate.
 *
 * If the value returned by the callback is truthy
 * (e.g. true, non-zero number, non-empty array, truthy object, etc.),
 * this is treated as satisfying the predicate.
 *
 * @param iterable $iterable
 * @param null|callable(mixed):mixed $callback
 */
function all(iterable $iterable, ?callable $callback = null): bool {
    foreach ($iterable as $v) {
        if (!($callback !== null ? $callback($v) : $v)) {
            return false;
        }
    }
    return true;
}

/**
 * Determines whether no element of the iterable satisfies the predicate.
 *
 * If the value returned by the callback is truthy
 * (e.g. true, non-zero number, non-empty array, truthy object, etc.),
 * this is treated as satisfying the predicate.
 *
 * @param iterable $iterable
 * @param null|callable(mixed):mixed $callback
 */
function none(iterable $iterable, ?callable $callback = null): bool {
	return !any($iterable, $callback);
}

// Analogous to array_reduce but with mandatory default
function fold(iterable $iterable, callable $callback, mixed $default): bool {
	foreach ($iterable as $value) {
		$default = $callback($default, $value);
	}
	return $default;
}

/**
 * Returns the first value for which $callback($value) is truthy.
 */
function find(iterable $iterable, callable $callback, mixed $default = null): bool {
	foreach ($iterable as $value) {
		if ($callback($value)) {
			return $value;
		}
	}
	return $default;
}

/**
 * Similar to in_array($value, $array, true) but also works on Traversables.
 */
function includes_value(iterable $iterable, mixed $value): bool {
	foreach ($iterable as $other) {
		if ($other === $value) {
			return true;
		}
	}
	return false;
}

Motivation

This contains functionality and data structures that may be proposed for inclusion into PHP itself (under a different namespace) at a future date, reimplemented using SPL's source code as a starting point.

Providing this as a PECL first would make this functionality easier to validate for correctness, and make it more practical to change APIs before proposing including them in PHP if needed.

License

See COPYING

Related Projects

Comments
  • Change strict_hash implementation to handle array cyclic reference edge case

    Change strict_hash implementation to handle array cyclic reference edge case

    If the top level value is an array, and the array contains reference cycles at any nesting depth, then give up on the current hash computation and only hash the parts of the top level that aren't arrays (keys, values)

    This still meets the condition that if X === Y, then strict_hash(X) === strict_hash(Y) - collisions are already inevitable due to the https://en.wikipedia.org/wiki/Pigeonhole_principle

    e.g. for

    $x = [];
    $x[1] = &$x;
    $y = [1 => $x];
    
    var_dump($x === $y); // true, so we expect the strict_hash to be the same. Only hash the key 1 but don't hash the top level array
    
    // Expected: same hashes are computed
    // Observed: Different hashes in Teds 1.2.6
    var_dump(Teds\strict_hash($x), Teds\strict_hash($y));
    int(-2238224086993845681)
    int(8691057668021067674)
    
    
    
    opened by TysonAndre 1
  • Map/Set interface, like Java

    Map/Set interface, like Java

    • This represents a collection with unique keys (through hashing, sorting, etc.)
    • This allows changing/passing in representation where useful to do so (collision resistance, getting sorted results, etc)
    • This allows userland implementations of Set/Map with additional constraints (e.g. enforcing key type)
    opened by TysonAndre 1
  • Idea: SortedIntMap/SortedStringMap/SortedMap

    Idea: SortedIntMap/SortedStringMap/SortedMap

    (e.g. with a skip list, splay tree, or red black tree, etc)

    Use integers and strings as keys

    Possibly invalidate iterators or throw if a node is removed during iteration (if invalidating, keep removed nodes in an associated buffer if they have active iterators?)

    opened by TysonAndre 1
  • Regenerate arginfo. Add Teds\strict_equals()

    Regenerate arginfo. Add Teds\strict_equals()

    Regenerate arginfo with php 8.3-dev's build/gen_stubs.php

    • Adding the @generate-legacy-arginfo 80000 for minimum php 8.0 version compatibility turned out to be unnecessary.

    Add Teds\strict_equals as used by hash sets/maps and unique_values

    opened by TysonAndre 0
  • tests/misc/strict_hash_array_recursion_32bit.phpt fails on 32bits

    tests/misc/strict_hash_array_recursion_32bit.phpt fails on 32bits

    Attempted too upgrade for Alpinelinux I got failed test on 32-bit arches (x86,armv7,armhf)

    SKIP Test strict_hash() function on recursive arrays [tests/misc/strict_hash_array_recursion.phpt] reason: 64-bit only
    TEST 253/261 [tests/misc/strict_hash_array_recursion_32bit.phpt]
    ========DIFF========
         array(1) {
           [0]=>
           *RECURSION*
    005+ int(-665309858)
         int(1357152471)
    006+ int(-351226279)
    005- int(1357152471)
    006- int(944359473)
         array(1) {
           [0]=>
           *RECURSION*
    011+ int(-665309858)
         int(1357152471)
    012+ int(-351226279)
    011- int(1357152471)
    012- int(944359473)
         Recursive arrays hashed in a predictable way
         array(2) {
           [0]=>
    --
             [1]=>
             int(123)
           }
    030+ int(-1313776964)
         int(-2005905482)
    031+ int(-1313776964)
    030- int(-2005905482)
    031- int(-2005905482)
         Test deeper recursion level
    033+ int(-1313776964)
    033- int(-2086164413)
    ========DONE========
    FAIL Test strict_hash() function on recursive arrays [tests/misc/strict_hash_array_recursion_32bit.phpt] 
    
    opened by andypost 0
  • Start running 32-bit tests on linux in CI

    Start running 32-bit tests on linux in CI

    And fix a harmless warning about copying uninitialized temporary variable by adding a macro to set a zval to a new reference counted zend_array pointer

    opened by TysonAndre 0
  • 1.2.5: Fix and optimize get_properties/get_properties_for handlers

    1.2.5: Fix and optimize get_properties/get_properties_for handlers

    Don't keep around properties table longer than they need to be kept in php 8.3+. Fix crash with array_walk(), reset(), and end() - Don't return null in get_properties. Switch to get_properties_for.

    Combine some redundant functionality

    opened by TysonAndre 0
  • Release 1.2.3 - change pop(), fix reference handling

    Release 1.2.3 - change pop(), fix reference handling

    Make pop() affect iterators like offsetUnset

    Iterators pointing to the element/entry removed with pop() will be moved backwards, consistently.

    Convert references to non-references when constructing/unserializing from arrays/traversables in a few Collections that missed that step

    opened by TysonAndre 0
  • Add popFront/pushFront as preferred/alternate method names instead of shift/unshift

    Add popFront/pushFront as preferred/alternate method names instead of shift/unshift

    For Deque, no elements are being shifted in the underlying collection, unlike array_shift/array_unshift, which take linear time instead of constant time to shift elements in arrays.

    See https://externals.io/message/116100#116214

    opened by TysonAndre 0
  • Idea: `final class Teds\ComparableObject {public readonly $key: mixed; public $value; }`

    Idea: `final class Teds\ComparableObject {public readonly $key: mixed; public $value; }`

    • This could throw for keys that don't have a stable comparison order, e.g. most objects
    • stable_compare could check for instances of this class
    • This could be used in StableMinHeap, stable sorts, etc.
    • This class would override the regular object comparison handler to compare $key if the instances were the same to be usable in <=>, <, sort, etc.
    opened by TysonAndre 0
  • Handle references in keys of StrictHashSet/StrictHashMap

    Handle references in keys of StrictHashSet/StrictHashMap

    • If arrays contain references, then use copies of the arrays that don't contain references, instead (and use copies for parents of those arrays, as well). If there are multiple occurrences of the original array then use the same copy every time.
    • Alternately, throw a RuntimeException (e.g. for reference cycles)
    $x = new Teds\StrictHashSet();
    $v = 1;
    $a = [&$v];
    $x->add($a); // should add a copy of the array without references, instead
    
    opened by TysonAndre 0
  • Benchmark hybrid approach in Teds\unique_values, use if practical

    Benchmark hybrid approach in Teds\unique_values, use if practical

    I've seen a hybrid approach in other implementations of methods to deduplicate values, since a hash table and sorting do worse than nested for loops in practice at very small sizes

    • For small n=count($input), use a regular foreach over buckets in the zend_array to be returned and call zend_is_identical one by one
    • For large n, use a hash table similar to the previous comment
    opened by TysonAndre 0
  • Add ImmutableSortedStringConstantMap

    Add ImmutableSortedStringConstantMap

    Map from strings to constants, where constants are serialized array/float/int/string/bool/null constants without references/reference cycles

    Similar to ImmutableSortedStringSet, back this with the serialized string representation

    opened by TysonAndre 0
Releases(1.3.0)
  • 1.3.0(Nov 10, 2022)

    • Optimize Teds\Deque insert() and offsetUnset() calls with offsets when they're closer to the front of the deque than the end of the Deque.
    • Add Teds\strict_equals($v1, $v2): bool with stricter NAN handling than ===.
    • Regenerate function arginfo with namespaced C symbols from stub.php files.
    Source code(tar.gz)
    Source code(zip)
  • 1.2.8(Oct 27, 2022)

    • Same as 1.2.7 other than the version and tests folder.
    • Update expected test output of the unit test tests/misc/strict_hash_array_recursion_32bit.phpt
    Source code(tar.gz)
    Source code(zip)
  • 1.2.7(Oct 22, 2022)

    • Fix an edge case in Teds\strict_hash for different arrays with reference cycles where php's strict equality operator would return true: '==='. (and for Teds\unique_values, Teds\StrictHashSet, and Teds\StrictHashMap) '$x === $y' should now always imply that 'Teds\strict_hash($x) === Teds\strict_hash($y)'
    Source code(tar.gz)
    Source code(zip)
  • 1.2.6(Oct 11, 2022)

    • Fix a build warning in clang for placeholders indicating that a data structure was constructed/unserialized.
    • Fix a build warning after change to expected return type of count_elements object handler implementation.
    Source code(tar.gz)
    Source code(zip)
  • 1.2.5(Oct 10, 2022)

    • Reduce memory usage by refactoring the way properties/fields of data structures are returned, for var_export/var_dump/debug_zval_dump/array type casts/serialize. In php 8.3+, this should reduce the impact of calling var_export/var_dump/debug_zval_dump on memory usage, and avoid the side effect of keeping around references to fields after those calls.. In all php versions, consistently return temporary arrays for remaining data structures in serialize() and array type casts that will be freed after being used.
    Source code(tar.gz)
    Source code(zip)
  • 1.2.4(Aug 14, 2022)

  • 1.2.3(Mar 6, 2022)

    • Make pop() on Sequences affect iterators the same way that $o->offsetUnset(count($o) - 1) would. (Move iterators pointing to the removed entry backwards by 1)
    • Make pop() on MutableIterable move iterators pointing to that entry backwards.
    • Properly convert references to non-references in some Collection constructors/unserializers and Teds\unique_values()
    Source code(tar.gz)
    Source code(zip)
  • 1.2.2(Mar 6, 2022)

    • Fix bugs in Teds\StrictHashSet/Teds\StrictHashMap iteration behavior.
    • Fix bug constructing balanced tree in Teds\StrictTreeSet/Teds\StrictTreeMap from array/unserializing, where certain sizes resulted in trees not maintaining the balancing invariant.
    • Fix bug when constructing Teds\IntVector from array when promoting type but not keeping reserved capacity.
    • Fix bugs in Teds\StrictSortedVectorSet::__construct
    Source code(tar.gz)
    Source code(zip)
  • 1.2.1(Mar 5, 2022)

    • Update documentation
    • Make iteration of Teds\StrictSortedVectorSet and Teds\StrictSortedVectorMap account for removals and additions.
    • Make removal in Teds\StrictTreeSet and Teds\StrictTreeMap move iterators to the previous node if the iterator pointed to the removed node. Add a state for iterators being prior to the start of the tree. Use the state of being before the first value of the tree when calling InternalIterator::rewind on an empty tree or removing an iterator pointing to the first value in a tree.
    • Make repacking/removals in Teds\StrictHashSet and Teds\StrictHashMap move InternalIterator positions.
    • Change iteration behavior of Teds\Deque to be like Vector, make shift/pop behave the same way as offsetUnset with respect to iteration. (If the iterator is moved to be before the start of the deque, calling next will move it to the front, and other changes to the Deque will have no effect)
    Source code(tar.gz)
    Source code(zip)
  • 1.2.0(Mar 4, 2022)

    • Add Teds\SortedIntVectorSet - a Set implementation represented in a way similar to an Teds\IntVector with unique sorted integers. (This may be useful for reducing memory usage and speeding up unserialization, when unserializing large Sets of integers which change infrequently. See benchmarks/benchmark_vector_unserialize.php)
    • Add Teds\ImmutableSortedStringSet - an immutable Set implementation containing a list of unique strings sorted with strcmp. (This may be useful for reducing memory usage and speeding up unserialization, when unserializing large Sets of strings which change infrequently to check values for membership in a Set. See benchmarks/benchmark_string_set.php)
    • Add Teds\ImmutableSortedIntSet - an immutable Set implementation containing a list of unique integers sorted by increasing value. (This may be useful for reducing memory usage and speeding up unserialization, when unserializing large Sets of integers which change infrequently to check values for membership in a Set.)
    • Rename Teds\BitSet to Teds\BitVector and add an alias
    • Add Teds\Sequence::insert(int $offset, mixed ...$values) to the Sequence interfaces and implementations
    • Add first/last to the Teds\Sequence interface.
    • Fix edge cases with var_export/var_dump/debug_zval_dump and cyclic data structures in debug builds and php 8.2.0-dev.
    • Make iteration account for offsetUnset/insert/shift/unshift in Sequences.
    Source code(tar.gz)
    Source code(zip)
  • 1.1.2(Feb 20, 2022)

  • 1.1.1(Feb 19, 2022)

  • 1.1.0(Feb 19, 2022)

    • Fix ImmutableSequence throwing for ArrayAccess shorthand read syntax.
    • Add CachedIterable as an alternative to ImmutableIterable that lazily evaluates Traversable objects passed into the constructor. (e.g. only runs Generators up to the most recently requested offset)
    • Change exception type to Teds\UnsupportedOperationException in a few places.
    • Add Teds\is_same_array_handle(array $array1, array $array2): bool for infinite recursion detection when processing arrays.
    • Fix memory leak when initializing Teds\StrictMinHeap/Teds\StrictMaxHeap from Traversables.
    • Fix memory leak when constructing collections from Traversable where rewind throws
    • Use first/last as method names for getting the first and last method names. Keep bottom/top as aliases to be deprecated later.
    • Add first/last helper methods to more collection types
    • Optimize implementations of $map[$x] array access shorthand in Teds\Map implementations.
    • Throw for $map[] = $value instead of setting the key for null in Teds\Map implementations.
    • Fix Teds\IntVector and Teds\LowMemoryVector shift implementation for integers
    • Add more methods to Teds\BitSet to read/write bytes/integers, convert to/from strings.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Feb 17, 2022)

  • 1.0.0(Feb 17, 2022)

    • BREAKING CHANGES: Fix incorrect serialization/unserialization result of LowMemoryVector for boolean/null. Incompatible with older releases.
    • BUGFIX: Fix converting LowMemoryVector of floats to an array (they were unintentionally converted to integers).
    • BREAKING CHANGES: Rename datastructures and interfaces for consistency. Change definitions of interfaces/remove interfaces. Rename Teds\ImmutableKeyValueSequence to Teds\ImmutableIterable and add an alias for the old name. Aliases will be removed in a future release. Rename Teds\KeyValueSequence to Teds\MutableIterable and add an alias. Rename Teds\SortedStrictMap to Teds\StrictTreeMap and add an alias. Rename Teds\StrictMap to Teds\StrictHashMap and add an alias. Rename Teds\SortedStrictSet to Teds\StrictTreeSet and add an alias. Rename Teds\StrictSet to Teds\StrictHashSet and add an alias. Rename Teds\StableMinHeap to Teds\StrictMinHeap and add an alias. Rename Teds\StableMaxHeap to Teds\StrictMaxHeap and add an alias. Change the definition of Teds\Collection to be just a Collection of values. Make Teds\Values an alias of Teds\Collection. Add the interfaces Teds\Sequence, Teds\Map, Teds\Set.
    Source code(tar.gz)
    Source code(zip)
  • 0.14.0(Feb 13, 2022)

    • Make strict_hash deterministic for NAN
    • Make strict_hash return the same value for signed positive and negative zero. (In php, 0.0 === -0.0, though var_export/print/var_dump output differ.)
    • Fix StrictMap/StrictSet handling of NAN. Make StrictMap/StrictSet treat positive and negative zero floats as the same key, like SortedStrictSet/stable_compare.
    • Add bitset source files to package.xml
    Source code(tar.gz)
    Source code(zip)
  • 0.13.0(Feb 13, 2022)

    • Add Teds\BitSet providing similar functionality to a Vector of booleans, using a single bit per boolean.
    • Fix stub documentation and qualify \Iterator for StableMinHeap/StableMaxHeap in documentation.
    Source code(tar.gz)
    Source code(zip)
  • 0.12.0(Feb 10, 2022)

    • Breaking changes.
    • Fix serialization/unserialization in StableMinHeap/StableMaxHeap.
    • Add interfaces for Teds\Values (e.g. Heap/Set), Teds\Collection(e.g. StrictMap, StableSortedMap), ListInterface(Vector, Deque, etc.) (the keyword list is reserved)
    • Implement ->values() in classes implementing Teds\Values.
    • Make offsetExists consistently return false when the value of the given key is null across all data structures.
    • Add Teds\Collection->containsKey to return true if a key exists without coercing types, and returning true regardless of whether the corresponding key is null.
    • Change signature of IntVector::set() and ::push() to match ListInterface
    • Add Collection::toArray() (behaves like iterator_to_array).
    • Check for exceeding 64-bit capacity limits in more collections to avoid hitting gc size limits and to avoid unpredictable behavior (e.g. it'd be surprising to have this throw/fatal error only if var_export/var_dump/json_encode was called and PHP's array size limits(2147483648 elements, or at least 32GB) were hit).
    Source code(tar.gz)
    Source code(zip)
  • 0.11.0(Feb 9, 2022)

    • Breaking change: Make StableMinHeap/StableMaxHeap stop inheriting from SplHeap to be more memory efficient.
    • Properly sort in StableSortedListSet::__construct and __set_state
    • Deduplicate code.
    • Reduce size/capacity limits to the same limits as array for Deque.
    • Add ImmutableSequence::map(), filter()
    • Fix bug in Deque::contains(), Deque::indexOf()
    Source code(tar.gz)
    Source code(zip)
  • 0.10.0(Feb 7, 2022)

    • Speed up unserializing SortedStrictSet/SortedStrictMap when the input data is already sorted. (If the data is not sorted, then build the binary tree the slow but correct way)
    • Add a LowMemoryVector type and IntVector type, supporting reduced memory usage.
    • Deduplicate code.
    • Fix garbage collection in some classes.
    Source code(tar.gz)
    Source code(zip)
  • 0.9.2(Jan 30, 2022)

    • Make SortedStrictSet/SortedStrictMap use a red-black tree that is rebalanced on insertions and removals, guaranteeing worst-case logarithmic time for insertions/removals/lookups.
    Source code(tar.gz)
    Source code(zip)
  • 0.9.1(Jan 29, 2022)

    • Make SortedStrictSet/SortedStrictMap use a binary search tree (not yet a balanced tree).
    • Associate iterators on SortedStrictSet/SortedStrictMap with nodes of the tree. Invalidate iterators pointing to a node when that node of the set/map is removed.
    • Fix sorting order when instantiating StableSortedListSet/SortedStrictSet/SortedStrictMap from unsorted arrays.
    Source code(tar.gz)
    Source code(zip)
  • 0.9.0(Jan 27, 2022)

    • Migrate Teds\StrictSet, Teds\StrictMap, and Teds\unique_values implementation to use an actual hash table instead of a list of unique values.
    Source code(tar.gz)
    Source code(zip)
  • 0.8.0(Jan 23, 2022)

    • Add StableSortedListSet and StableSortedListMap as memory-efficient alternatives to SortedStrictSet/SortedStrictMap.
    • Speed up SortedStrictSet::__unserialize and SortedStrictMap::__unserialize when data is already sorted.
    • Fix crash in StrictSet and SortedStrictSet during cyclic garbage collection.
    Source code(tar.gz)
    Source code(zip)
  • 0.7.0(Jan 23, 2022)

    • Make Teds\strict_hash ignore recursion caused by unrelated functions (e.g. var_dump calling __debugInfo calling strict_hash)
    • Add Teds\binary_search(array $values, mixed $target, callable $comparer = null, bool $useKey=false)
    • Change parent class of Teds\StableMaxHeap and Teds\StableMinHeap to SplHeap.
    • Fix deduplication when constructing StrictSet from iterable, StrictMap from Traversable.
    • Add Teds\unique_values(iterable): array using strict_hash to check for duplicates.
    Source code(tar.gz)
    Source code(zip)
  • 0.6.0(Jan 18, 2022)

    • Make Teds\stable_compare sort objects by class name with strcmp before sorting by spl_object_id.
    • Add a hash map StrictMap using Teds\stable_hash as a hash algorithm. Keys are returned in order of insertion.
    • Add a hash set StrictSet using Teds\stable_hash as a hash algorithm.
    • Add a sorted map SortedStrictMap using Teds\stable_compare as a comparison function. Keys are returned ordered by Teds\stable_compare and no two keys have stable_compare return 0 (i.e. no two keys are equivalent).
    • Add a sorted set SortedStrictSet using Teds\stable_compare as a comparison function.
    • Add StableMinHeap/StableMaxHeap extending SplMinHeap/SplMaxHeap, using Teds\stable_compare as a comparison function.
    Source code(tar.gz)
    Source code(zip)
  • 0.5.1(Jan 15, 2022)

  • 0.5.0(Jan 15, 2022)

    • Add Teds\array_value_first(), Teds\array_value_last()
    • Add Teds\stable_compare($v1, $v2): int for a stable comparison function of arbitrary values. (see tests/misc/stable_compare.phpt). Like strcmp, this returns a negative value for less than, and positive for greater than, and 0 for equality. Note that php's < operator is not stable. '10' < '0a' < '1b' < '9' < '10'. stable_compare fixes that by strictly ordering: null < false < true < int,float < string < array < object < resource. (objects and resources are compared by id, and arrays are compared recursively. Numbers are compared numerically. If an int is equal to a float, then the int is first) (strings use strcmp)
    • Make Deque iteration account for calls to shift/unshift tracking the position of the front of the Deque. Calls to shift/unshift will do the following:
      • Increase/Decrease the value returned by the iterator's key() by the number of elements added/removed to/from the front of the Deque. ($deque[$iteratorKey] === $iteratorValue at the time the key and value are returned).
      • Repeated calls to shift will cause valid() to return false if the iterator's position ends up before the start of the Deque at the time iteration resumes.
      • They will not cause the remaining values to be iterated over more than once or skipped.
    Source code(tar.gz)
    Source code(zip)
  • 0.4.1(Sep 27, 2021)

  • 0.4.0(Sep 26, 2021)

    • Backwards incompatible change: Change Deque APIs to be consistent with SplDoublyLinkedList and array_push: change pushBack/popBack/pushFront/popFront to push/pop/unshift/shift
    • Backwards incompatible change: Remove $preserve_keys flag from Vector::__construct (Always reindex keys in order of iteration instead).
    • Add isEmpty() method to datastructures
    • Make exceeding the capacity limit for a vector a fatal error.
    • Make Deque::push() and unshift() variadic.
    Source code(tar.gz)
    Source code(zip)
Owner
Tyson Andre
Tyson Andre
A collection of type-safe functional data structures

lamphpda A collection of type-safe functional data structures Aim The aim of this library is to provide a collection of functional data structures in

Marco Perone 99 Nov 11, 2022
A Magento implementation for validating JSON Structures against a given Schema

Zepgram JsonSchema A Magento implementation for validating JSON Structures against a given Schema with support for Schemas of Draft-3 or Draft-4. Base

Benjamin Calef 1 Nov 5, 2021
laminas-xml2json provides functionality for converting XML structures to JSON

laminas-xml2json This package is considered feature-complete, and is now in security-only maintenance mode, following a decision by the Technical Stee

Laminas Project 13 Dec 28, 2022
Melek Berita Backend is a service for crawling data from various websites and processing the data to be used for news data needs.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Chacha Nurholis 2 Oct 9, 2022
Data visualization for NASA's DSNNow public data

DSN Monitor Data visualization for NASA's DSNNow public data. A live version of the project can be accessed at http://dsnmonitor.ddns.net. Description

Vinz 2 Sep 18, 2022
Import data from and export data to a range of different file formats and media

Ddeboer Data Import library This library has been renamed to PortPHP and will be deprecated. Please use PortPHP instead. Introduction This PHP library

David de Boer 570 Dec 27, 2022
📦 "PHP type names" contains the list of constants for the available PHP data types.

PHP type names PHP type names ?? Description Simple library containing the list of constants for the available PHP data types. Use those constant type

♚ PH⑦ de Soria™♛ 4 Dec 15, 2022
The VarExporter component allows exporting any serializable PHP data structure to plain PHP code.

The VarExporter component allows exporting any serializable PHP data structure to plain PHP code. While doing so, it preserves all the semantics associated with the serialization mechanism of PHP (__wakeup, __sleep, Serializable).

Symfony 1.8k Jan 1, 2023
PHP with PDO (PHP Data Objects) Quickstart

PHP with PDO (PHP Data Objects) Quickstart This repository contains a simple web application that demonstrates how to quickly connect to and communica

Developer Code Central 3 Oct 20, 2022
YL MVC Structure (PHP MVC) is a pattern made in PHP used to implement user interfaces, data, and controlling logic.

YL MVC Structure (PHP MVC) is a pattern made in PHP used to implement user interfaces, data, and controlling logic. It is built based on the combination of ideas from the Yii framework and Laravel framework (yl).

Tan Nguyen 3 Jan 3, 2023
Creating data transfer objects with the power of php objects. No php attributes, no reflection api, and no other under the hook work.

Super Simple DTO Creating data transfer objects with the power of php objects. No php attributes, no reflection api, and no other under the hook work.

Mohammed Manssour 8 Jun 8, 2023
Samsui is a factory library for building PHP objects useful for setting up test data in your applications.

#Samsui Samsui is a factory library for building PHP objects useful for setting up test data in your applications. It is mainly inspired by Rosie for

Sam Yong 31 Nov 11, 2020
JsonQ is a simple, elegant PHP package to Query over any type of JSON Data

php-jsonq JsonQ is a simple, elegant PHP package to Query over any type of JSON Data. It'll make your life easier by giving the flavour of an ORM-like

Nahid Bin Azhar 834 Dec 25, 2022
A PHP library providing ISO 3166-1 data

league/iso3166 A PHP library providing ISO 3166-1 data. What is ISO 3166-1 ISO 3166-1 is part of the ISO 3166 standard published by the International

The League of Extraordinary Packages 555 Dec 21, 2022
PHP package that provides functions for calculating mathematical statistics of numeric data

Statistics PHP package PHP package that provides functions for calculating mathematical statistics of numeric data. In this package I'm collecting som

Hi Folks! 289 Dec 27, 2022
PHP package that provides functions for calculating mathematical statistics of numeric data.

Statistics PHP package PHP package that provides functions for calculating mathematical statistics of numeric data. In this package I'm collecting som

Hi Folks! 290 Dec 29, 2022
A PHP spreadsheet reader (Excel XLS and XLSX, OpenOffice ODS, and variously separated text files) with a singular goal of getting the data out, efficiently

spreadsheet-reader is a PHP spreadsheet reader that differs from others in that the main goal for it was efficient data extraction that could handle l

Nuovo 666 Dec 24, 2022
First Data driver for the Omnipay PHP payment processing library

Omnipay: First Data First Data driver for the Omnipay PHP payment processing library Omnipay is a framework agnostic, multi-gateway payment processing

The League of Extraordinary Packages 20 Oct 23, 2022
PHP scraper to get data from Google Play

nelexa/google-play-scraper PHP library to scrape application data from the Google Play store. Checking the exists of the app on Google Play. Retrievin

Pisarev Alexey 57 Dec 20, 2022