PHPackages                             chevere/data-structure - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. chevere/data-structure

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

chevere/data-structure
======================

Map and Vector data structures

1.1.1(1y ago)124.5k↑14.4%[1 issues](https://github.com/chevere/data-structure/issues)7Apache-2.0PHPPHP ^8.1CI passing

Since Nov 30Pushed 1y agoCompare

[ Source](https://github.com/chevere/data-structure)[ Packagist](https://packagist.org/packages/chevere/data-structure)[ Docs](https://chevere.org)[ RSS](/packages/chevere-data-structure/feed)WikiDiscussions 1.1 Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (6)Used By (7)

DataStructure
=============

[](#datastructure)

[![Chevere](chevere.svg)](chevere.svg)

[![Build](https://camo.githubusercontent.com/fe935cbfb607b60ed8117cf7ff0c6135bb1bca76d6fe5713b0f24388a53b3281/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636865766572652f646174612d7374727563747572652f746573742e796d6c3f6272616e63683d312e31267374796c653d666c61742d737175617265)](https://github.com/chevere/data-structure/actions)[![Code size](https://camo.githubusercontent.com/d2ef19a50404c86456ff002a536cbb6218470965d2d64b85ae7925b75ba72a6d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f636865766572652f646174612d7374727563747572653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/d2ef19a50404c86456ff002a536cbb6218470965d2d64b85ae7925b75ba72a6d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f636865766572652f646174612d7374727563747572653f7374796c653d666c61742d737175617265)[![Apache-2.0](https://camo.githubusercontent.com/665f6f2ca3b996471cd8713fe98078697c32724dd8e3647cbb58dc2c8000a3da/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636865766572652f646174612d7374727563747572653f7374796c653d666c61742d737175617265)](LICENSE)[![PHPStan](https://camo.githubusercontent.com/6016298b28550819030c76e9327f62501596a31fd76406695bae2f3d2a1f26a4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d626c756576696f6c65743f7374796c653d666c61742d737175617265)](https://phpstan.org/)[![Mutation testing badge](https://camo.githubusercontent.com/f627d2ef57b9d1edd13b9b1e98851548a884acd4bfb07a772c91b198bbf3cc3c/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742d7371756172652675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d25324663686576657265253246646174612d737472756374757265253246312e31)](https://dashboard.stryker-mutator.io/reports/github.com/chevere/data-structure/1.1)

[![Quality Gate Status](https://camo.githubusercontent.com/a8a18ebbe19f7a4b4f6f636bd0521ea274f2eeeb9a14c4f7a36ef8616ddf7de5/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f646174612d737472756374757265266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=chevere_data-structure)[![Maintainability Rating](https://camo.githubusercontent.com/378ffd61b1b51965809fc29f779ac2a365f94f21ef66671853bb6a0edc9624fc/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f646174612d737472756374757265266d65747269633d7371616c655f726174696e67)](https://sonarcloud.io/dashboard?id=chevere_data-structure)[![Reliability Rating](https://camo.githubusercontent.com/2146e8a089058e27f97507b1c89f8b8df84b240a488076e5433f91472dfb01fc/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f646174612d737472756374757265266d65747269633d72656c696162696c6974795f726174696e67)](https://sonarcloud.io/dashboard?id=chevere_data-structure)[![Security Rating](https://camo.githubusercontent.com/29ecd99d7b11828029596a14322772826d4fff86b72a169fe45ee696910015c8/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f646174612d737472756374757265266d65747269633d73656375726974795f726174696e67)](https://sonarcloud.io/dashboard?id=chevere_data-structure)[![Coverage](https://camo.githubusercontent.com/b18aed3364b946be192056b841880df50f4995f63b5a31162d265230f53248f0/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f646174612d737472756374757265266d65747269633d636f766572616765)](https://sonarcloud.io/dashboard?id=chevere_data-structure)[![Technical Debt](https://camo.githubusercontent.com/78edd12e86c9a78c0a4518c9d78c584c9ac339969b58f695531fb16ffbc0fad6/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f646174612d737472756374757265266d65747269633d7371616c655f696e646578)](https://sonarcloud.io/dashboard?id=chevere_data-structure)[![CodeFactor](https://camo.githubusercontent.com/dafc461c017b8c319f09d071b0809da4d757abf93c25a705aee6c2d9d36f8e32/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f636865766572652f646174612d7374727563747572652f6261646765)](https://www.codefactor.io/repository/github/chevere/data-structure)

Summary
-------

[](#summary)

DataStructure provides Map and Vector data structures.

Installing
----------

[](#installing)

DataStructure is available through [Packagist](https://packagist.org/packages/chevere/data-structure) and the repository source is at [chevere/data-structure](https://github.com/chevere/data-structure).

```
composer require chevere/data-structure
```

Map
---

[](#map)

A Map is a sequential collection of key-value pairs. Keys can be of type `integer` and `string`.

Create a Map by passing named arguments of any type.

```
use Chevere\DataStructure\Map;

$map = new Map(foo: $foo, bar: $bar);
```

### Put Map values

[](#put-map-values)

The `withPut` method is used to put value(s) to the Map.

```
$map = $map
    ->withPut(
        foo: $foo,
        bar: $bar
    );
```

### Counting Map keys

[](#counting-map-keys)

The `count` method returns the number of keys mapped.

```
$map->count();
// 2
```

### Map keys

[](#map-keys)

The `keys` method is used to retrieve the map keys as an array.

```
$map->keys();
// ['foo', 'bar']
```

### Has Map keys

[](#has-map-keys)

The `has` method is used to check if the Map contains the given key(s).

```
$map->has('foo'); // true
$map->has('notFound'); // false
```

### Assert has Map keys

[](#assert-has-map-keys)

The `assertHas` method is used to assert if the Map contains the given key(s). It throws an exception when failing to assert.

```
$map->assertHas('foo');
$map->assertHas('notFound');
```

### Get Map value

[](#get-map-value)

The `get` method is used to retrieve the Map value for the given key.

```
$foo = $map->get('foo');
```

### Get Map value or default

[](#get-map-value-or-default)

The `getOrDefault` method is used to retrieve the Map value for the given key or a default value if not found.

```
$foo = $map->getOrDefault('foo', null);
// Return null if not found
```

Vector
------

[](#vector)

A Vector is a sequence of values of any type. Keys are of type integer.

Create a Vector by passing values.

```
use Chevere\DataStructure\Vector;

$vector = new Vector($value1, $value2,);
```

### Counting Vector keys

[](#counting-vector-keys)

The `count` method returns the number of keys in the vector.

```
$vector->count();
// 2
```

### Vector keys

[](#vector-keys)

The `keys` method is used to retrieve the map keys as an array.

```
$map->keys();
// [0, 1]
```

### Push Vector values

[](#push-vector-values)

The `withPush` method is used to add one or more elements to the end of the sequence.

```
$with = $vector->withPush($value,);
```

### Set Vector values

[](#set-vector-values)

The `withSet` method is used to set the value at the given position.

```
$with = $vector->withSet(0, $value);
```

### Unshift Vector values

[](#unshift-vector-values)

The `withUnshift` method is used to prepend one or more elements at the beginning of the sequence.

```
$with = $vector->withUnshift($value,);
```

### Insert Vector values

[](#insert-vector-values)

The `withInsert` method is used to insert values at a given position.

```
$with = $vector->withInsert($pos, ...$values);
```

### Remove Vector values

[](#remove-vector-values)

The `withRemove` method is used to remove one or more values at a given position.

```
$with = $vector->withRemove($pos,);
```

### Has Vector values

[](#has-vector-values)

The `has` method is used to check if the Vector contains the given value(s).

```
$vector->has($value); // true
$vector->has($notFound); // false
```

### Assert Vector has values

[](#assert-vector-has-values)

The `assertHas` method is used to assert if the Vector contains the given value(s). It throws an exception when failing to assert.

```
$vector->assertHas($value);
```

### Get Vector value

[](#get-vector-value)

The `get` method is used to retrieve the Vector value at the given position.

```
$value = $vector->get($pos);
```

Find values
-----------

[](#find-values)

The `find` method is used to find the position for the given value.

```
$pos = $vector->find($value);
```

Contains values
---------------

[](#contains-values)

The `contains` method is used to check if the Vector contains the given value(s).

```
$vector->contains($value); // bool
```

Documentation
-------------

[](#documentation)

Documentation is available at [chevere.org](https://chevere.org/packages/data-structure).

License
-------

[](#license)

Copyright [Rodolfo Berrios A.](https://rodolfoberrios.com/)

Chevere is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full license text.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~102 days

Recently: every ~118 days

Total

6

Last Release

387d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a87fbbcb1518fe64878bc53dedd9f61b81243cbb21b73c26f5e299d501375984?d=identicon)[rodolfo](/maintainers/rodolfo)

---

Top Contributors

[![rodber](https://avatars.githubusercontent.com/u/20590102?v=4)](https://github.com/rodber "rodber (18 commits)")

---

Tags

cheverephpphp-library

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/chevere-data-structure/health.svg)

```
[![Health](https://phpackages.com/badges/chevere-data-structure/health.svg)](https://phpackages.com/packages/chevere-data-structure)
```

###  Alternatives

[chevere/throwable-handler

Throwable handler for multiple contexts

1131.9k9](/packages/chevere-throwable-handler)[chevere/parameter

Dynamic parameter-argument validation for PHP with rich type constraints, attributes, and schema introspection.

1023.7k20](/packages/chevere-parameter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
