Skip to content

Commit 94c3ff7

Browse files
committed
Restructure core data structure architecture with modular enhancements
**Detailed Description:** 1. **Refactored Architecture:** - Removed outdated classes (`firehub.Linear.php`, `firehub.Sequence.php`, etc.) in favor of a modular and extensible structure. - Introduced a new hierarchy for Data Structures: - `Capability`: Introduced concepts like `StreamingAccess`, `SequentialAccess`, and `Countable` behavior for precise feature modularization. - `Abstraction`: Added higher-level abstractions like `Collection`, `Stream`, and `Enumerable` for defining standardized structural behavior. - `Type`: Implemented the `Linear` interface to define sequentially organized data. 2. **Addition of Core Components:** - Created `DS` as the new entry point for managing FireHub's data structure constructs: - Integrated `SequenceBuilder` for flexible and efficient sequence creation. - Provided factory APIs for improved abstraction and usability. - Added new `Sequence` implementation under `Collection\Linear`: - Designed for ordered collections supporting sequential iteration and manipulation. - Uses redesigned storage mechanisms for enhanced compatibility and performance. 3. **Enhanced Storage Layer:** - Updated `Storage`: - Added `count()` method as part of `Countable` contract. - Dropped redundant methods like `keys()` and `values()`. - Enhanced compatibility with new `GeneratorStorage` and `ArrStorage` as backends: - Both storages now implement `SequentialAccess` or `StreamingAccess` capabilities based on their traits. - Refactored `GeneratorStorage` for lazy evaluation with reduced memory overhead. 4. **Revised Testing Suite:** - Replaced legacy tests (`SequenceTest.php`, `StorageTest.php`) with dedicated unit tests: - Verified integration with modular capabilities via separate tests for storage options. - Ensured alignment of domain logic and expected behaviors for each abstraction. 5. **Autoload Updates:** - Updated classmap with new abstractions (`Abstraction`, `Capability`, `Collection`, etc.) to ensure continuous and efficient module discovery in enterprise environments. **Key Benefits:** - Introduces a modular and standardized approach to FireHub data structures, improving scalability and maintainability. - Enhances memory efficiency and flexibility of data operations via improved storage integration. - Simplifies developer experience with extensible and reusable abstractions.
1 parent c352f46 commit 94c3ff7

23 files changed

Lines changed: 488 additions & 290 deletions

dist/core.min.phar

5.19 KB
Binary file not shown.

dist/core.phar

11.4 KB
Binary file not shown.

src/support/autoload/classmap.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,20 @@
7878
\FireHub\Core\Support\Bootstrap\Bootloader\RegisterHelpers::class => __DIR__.'/../../support/bootstrap/bootloader/firehub.RegisterHelpers.php',
7979
\FireHub\Core\Support\Bootstrap\FireHubConfigurator::class => __DIR__.'/../../support/bootstrap/firehub.FireHubConfigurator.php',
8080
\FireHub\Core\Support\Contracts\DataStructure::class => __DIR__.'/../../support/contracts/firehub.DataStructure.php',
81-
\FireHub\Core\Support\DataStructure\Behavior\Countable::class => __DIR__.'/../../support/datastructure/behavior/firehub.Countable.php',
82-
\FireHub\Core\Support\DataStructure\Behavior\Enumerable::class => __DIR__.'/../../support/datastructure/behavior/firehub.Enumerable.php',
83-
\FireHub\Core\Support\DataStructure\Linear::class => __DIR__.'/../../support/datastructure/firehub.Linear.php',
84-
\FireHub\Core\Support\DataStructure\Linear\Sequence::class => __DIR__.'/../../support/datastructure/linear/firehub.Sequence.php',
81+
\FireHub\Core\Support\DataStructure\Abstraction\Collection::class => __DIR__.'/../../support/datastructure/abstraction/firehub.Collection.php',
82+
\FireHub\Core\Support\DataStructure\Abstraction\Enumerable::class => __DIR__.'/../../support/datastructure/abstraction/firehub.Enumerable.php',
83+
\FireHub\Core\Support\DataStructure\Abstraction\Stream::class => __DIR__.'/../../support/datastructure/abstraction/firehub.Stream.php',
84+
\FireHub\Core\Support\DataStructure\Builder\SequenceBuilder::class => __DIR__.'/../../support/datastructure/builder/firehub.SequenceBuilder.php',
85+
\FireHub\Core\Support\DataStructure\Capability\Access\RandomAccess::class => __DIR__.'/../../support/datastructure/capability/access/firehub.RandomAccess.php',
86+
\FireHub\Core\Support\DataStructure\Capability\Access\SequentialAccess::class => __DIR__.'/../../support/datastructure/capability/access/firehub.SequentialAccess.php',
87+
\FireHub\Core\Support\DataStructure\Capability\Access\StreamingAccess::class => __DIR__.'/../../support/datastructure/capability/access/firehub.StreamingAccess.php',
88+
\FireHub\Core\Support\DataStructure\Capability\Behavior\Countable::class => __DIR__.'/../../support/datastructure/capability/behavior/firehub.Countable.php',
89+
\FireHub\Core\Support\DataStructure\Collection\Linear\Sequence::class => __DIR__.'/../../support/datastructure/collection/linear/firehub.Sequence.php',
90+
\FireHub\Core\Support\DataStructure\DS::class => __DIR__.'/../../support/datastructure/firehub.DS.php',
8591
\FireHub\Core\Support\DataStructure\Storage::class => __DIR__.'/../../support/datastructure/firehub.Storage.php',
8692
\FireHub\Core\Support\DataStructure\Storage\ArrStorage::class => __DIR__.'/../../support/datastructure/storage/firehub.ArrStorage.php',
8793
\FireHub\Core\Support\DataStructure\Storage\GeneratorStorage::class => __DIR__.'/../../support/datastructure/storage/firehub.GeneratorStorage.php',
94+
\FireHub\Core\Support\DataStructure\Type\Linear::class => __DIR__.'/../../support/datastructure/type/firehub.Linear.php',
8895
\FireHub\Core\Support\LowLevel::class => __DIR__.'/../../support/firehub.LowLevel.php',
8996
\FireHub\Core\Support\LowLevel\Arr::class => __DIR__.'/../../support/lowlevel/firehub.Arr.php',
9097
\FireHub\Core\Support\LowLevel\CharMB::class => __DIR__.'/../../support/lowlevel/firehub.CharMB.php',

src/support/autoload/loader/firehub.CompiledClassmap.php

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,20 +244,44 @@ public function __invoke (string $class):void {
244244
require __DIR__.'/../../../support/contracts/firehub.DataStructure.php';
245245
return;
246246

247-
case \FireHub\Core\Support\DataStructure\Behavior\Countable::class:
248-
require __DIR__.'/../../../support/datastructure/behavior/firehub.Countable.php';
247+
case \FireHub\Core\Support\DataStructure\Abstraction\Collection::class:
248+
require __DIR__.'/../../../support/datastructure/abstraction/firehub.Collection.php';
249249
return;
250250

251-
case \FireHub\Core\Support\DataStructure\Behavior\Enumerable::class:
252-
require __DIR__.'/../../../support/datastructure/behavior/firehub.Enumerable.php';
251+
case \FireHub\Core\Support\DataStructure\Abstraction\Enumerable::class:
252+
require __DIR__.'/../../../support/datastructure/abstraction/firehub.Enumerable.php';
253253
return;
254254

255-
case \FireHub\Core\Support\DataStructure\Linear::class:
256-
require __DIR__.'/../../../support/datastructure/firehub.Linear.php';
255+
case \FireHub\Core\Support\DataStructure\Abstraction\Stream::class:
256+
require __DIR__.'/../../../support/datastructure/abstraction/firehub.Stream.php';
257257
return;
258258

259-
case \FireHub\Core\Support\DataStructure\Linear\Sequence::class:
260-
require __DIR__.'/../../../support/datastructure/linear/firehub.Sequence.php';
259+
case \FireHub\Core\Support\DataStructure\Builder\SequenceBuilder::class:
260+
require __DIR__.'/../../../support/datastructure/builder/firehub.SequenceBuilder.php';
261+
return;
262+
263+
case \FireHub\Core\Support\DataStructure\Capability\Access\RandomAccess::class:
264+
require __DIR__.'/../../../support/datastructure/capability/access/firehub.RandomAccess.php';
265+
return;
266+
267+
case \FireHub\Core\Support\DataStructure\Capability\Access\SequentialAccess::class:
268+
require __DIR__.'/../../../support/datastructure/capability/access/firehub.SequentialAccess.php';
269+
return;
270+
271+
case \FireHub\Core\Support\DataStructure\Capability\Access\StreamingAccess::class:
272+
require __DIR__.'/../../../support/datastructure/capability/access/firehub.StreamingAccess.php';
273+
return;
274+
275+
case \FireHub\Core\Support\DataStructure\Capability\Behavior\Countable::class:
276+
require __DIR__.'/../../../support/datastructure/capability/behavior/firehub.Countable.php';
277+
return;
278+
279+
case \FireHub\Core\Support\DataStructure\Collection\Linear\Sequence::class:
280+
require __DIR__.'/../../../support/datastructure/collection/linear/firehub.Sequence.php';
281+
return;
282+
283+
case \FireHub\Core\Support\DataStructure\DS::class:
284+
require __DIR__.'/../../../support/datastructure/firehub.DS.php';
261285
return;
262286

263287
case \FireHub\Core\Support\DataStructure\Storage::class:
@@ -272,6 +296,10 @@ public function __invoke (string $class):void {
272296
require __DIR__.'/../../../support/datastructure/storage/firehub.GeneratorStorage.php';
273297
return;
274298

299+
case \FireHub\Core\Support\DataStructure\Type\Linear::class:
300+
require __DIR__.'/../../../support/datastructure/type/firehub.Linear.php';
301+
return;
302+
275303
case \FireHub\Core\Support\LowLevel::class:
276304
require __DIR__.'/../../../support/firehub.LowLevel.php';
277305
return;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types = 1);
2+
3+
/**
4+
* This file is part of the FireHub Project ecosystem
5+
*
6+
* @author Danijel Galić <danijel.galic@outlook.com>
7+
* @copyright 2026 The FireHub Project - All rights reserved
8+
* @license https://opensource.org/license/Apache-2-0 Apache License, Version 2.0
9+
*
10+
* @php-version 7.0
11+
* @package Core\Support
12+
*/
13+
14+
namespace FireHub\Core\Support\DataStructure\Abstraction;
15+
16+
/**
17+
* ### Collection Contract
18+
*
19+
* A Collection is a structured, stateful data container that stores and manages a finite set of elements. It
20+
* provides consistent, repeatable iteration and supports common data operations such as adding, removing,
21+
* and transforming items while preserving internal state and order guarantees depending on its specific type
22+
* (e.g., linear, associative, or set-based).
23+
* @since 1.0.0
24+
*
25+
* @template TKey
26+
* @template TValue
27+
*
28+
* @extends \FireHub\Core\Support\DataStructure\Abstraction\Enumerable<TKey, TValue>
29+
*/
30+
interface Collection extends Enumerable {
31+
32+
}

src/support/datastructure/behavior/firehub.Enumerable.php renamed to src/support/datastructure/abstraction/firehub.Enumerable.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
* @package Core\Support
1212
*/
1313

14-
namespace FireHub\Core\Support\DataStructure\Behavior;
14+
namespace FireHub\Core\Support\DataStructure\Abstraction;
1515

16+
use FireHub\Core\Support\Contracts\DataStructure;
1617
use FireHub\Core\Shared\Contracts\IteratorAggregate;
1718

1819
/**
19-
* ### Enumerable Behavior Contract
20+
* ### Enumerable Contract
2021
*
2122
* Defines the ability to iterate over all elements in a structure. Provides higher-level traversal operations such
2223
* as mapping, filtering, and transformation, typically built on top of a traversal mechanism.
@@ -25,6 +26,9 @@
2526
* @template TKey
2627
* @template TValue
2728
*
29+
* @extends \FireHub\Core\Support\Contracts\DataStructure<TKey, TValue>
2830
* @extends \FireHub\Core\Shared\Contracts\IteratorAggregate<TKey, TValue>
2931
*/
30-
interface Enumerable extends IteratorAggregate {}
32+
interface Enumerable extends DataStructure, IteratorAggregate {
33+
34+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types = 1);
2+
3+
/**
4+
* This file is part of the FireHub Project ecosystem
5+
*
6+
* @author Danijel Galić <danijel.galic@outlook.com>
7+
* @copyright 2026 The FireHub Project - All rights reserved
8+
* @license https://opensource.org/license/Apache-2-0 Apache License, Version 2.0
9+
*
10+
* @php-version 7.0
11+
* @package Core\Support
12+
*/
13+
14+
namespace FireHub\Core\Support\DataStructure\Abstraction;
15+
16+
/**
17+
* ### Stream Contract
18+
*
19+
* A Stream is a lazy, single-pass data structure that produces elements on demand during iteration. It does not
20+
* store data in memory as a collection but instead computes or retrieves each element as it is traversed.
21+
* Streams are ideal for processing large or infinite datasets, enabling transformations and operations like mapping
22+
* and filtering without materializing the entire dataset.
23+
* @since 1.0.0
24+
*
25+
* @template TKey
26+
* @template TValue
27+
*
28+
* @extends \FireHub\Core\Support\DataStructure\Abstraction\Enumerable<TKey, TValue>
29+
*/
30+
interface Stream extends Enumerable {
31+
32+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php declare(strict_types = 1);
2+
3+
/**
4+
* This file is part of the FireHub Project ecosystem
5+
*
6+
* @author Danijel Galić <danijel.galic@outlook.com>
7+
* @copyright 2026 The FireHub Project - All rights reserved
8+
* @license https://opensource.org/license/Apache-2-0 Apache License, Version 2.0
9+
*
10+
* @php-version 7.0
11+
* @package Core\Support
12+
*/
13+
14+
namespace FireHub\Core\Support\DataStructure\Builder;
15+
16+
use FireHub\Core\Support\DataStructure\Collection\Linear\Sequence;
17+
use FireHub\Core\Support\DataStructure\Capability\Access\SequentialAccess;
18+
use FireHub\Core\Support\DataStructure\ {
19+
Storage, Storage\ArrStorage
20+
};
21+
use FireHub\Core\Support\LowLevel\Arr;
22+
23+
/**
24+
* ### Sequence Builder
25+
*
26+
* Provides a scoped construction API for creating Sequence data structures.<br>
27+
* Handles normalization and storage selection while keeping the Sequence model clean.
28+
* @since 1.0.0
29+
*/
30+
final class SequenceBuilder {
31+
32+
/**
33+
* ### Create Sequence from storage
34+
*
35+
* Uses an existing storage implementation that supports sequential access.
36+
* @since 1.0.0
37+
*
38+
* @template TValue
39+
*
40+
* @param \FireHub\Core\Support\DataStructure\Storage<int, TValue>&\FireHub\Core\Support\DataStructure\Capability\Access\SequentialAccess $storage <p>
41+
* Storage instance that provides sequential access to the data.
42+
* </p>
43+
*
44+
* @return Sequence<TValue> New Sequence instance.
45+
*/
46+
public function fromStorage (Storage&SequentialAccess $storage):Sequence {
47+
48+
return new Sequence($storage);
49+
50+
}
51+
52+
53+
/**
54+
* ### Create Sequence from an array
55+
* Normalizes array keys into a sequential integer index.
56+
* @since 1.0.0
57+
*
58+
* @uses \FireHub\Core\Support\LowLevel\Arr::values() To reindex the input array with sequential integer keys.
59+
*
60+
* @template TValue
61+
*
62+
* @param array<array-key, TValue> $array <p>
63+
* The array to convert into a Sequence.
64+
* </p>
65+
*
66+
* @return Sequence<TValue> New Sequence instance.
67+
*/
68+
public function fromArray (array $array):Sequence {
69+
70+
return new Sequence(
71+
new ArrStorage(Arr::values($array))
72+
);
73+
74+
}
75+
76+
/**
77+
* ### Create Sequence from values
78+
* Builds a Sequence directly from given values without additional normalization.
79+
* @since 1.0.0
80+
*
81+
* @uses \FireHub\Core\Support\LowLevel\Arr::values() To reindex the input values with sequential integer keys.
82+
*
83+
* @template TValue
84+
*
85+
* @param TValue ...$values <p>
86+
* Variadic list of values to include in the Sequence.
87+
* </p>
88+
*
89+
* @return Sequence<TValue> New Sequence instance.
90+
*/
91+
public function of (mixed ...$values):Sequence {
92+
93+
return new Sequence(
94+
new ArrStorage(Arr::values($values))
95+
);
96+
97+
}
98+
99+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types = 1);
2+
3+
/**
4+
* This file is part of the FireHub Project ecosystem
5+
*
6+
* @author Danijel Galić <danijel.galic@outlook.com>
7+
* @copyright 2026 The FireHub Project - All rights reserved
8+
* @license https://opensource.org/license/Apache-2-0 Apache License, Version 2.0
9+
*
10+
* @php-version 7.0
11+
* @package Core\Support
12+
*/
13+
14+
namespace FireHub\Core\Support\DataStructure\Capability\Access;
15+
16+
/**
17+
* ### Random Access
18+
*
19+
* Defines the ability to access elements directly by key or index in constant or near-constant time. It allows
20+
* non-sequential retrieval of elements without iterating through the structure.
21+
* @since 1.0.0
22+
*/
23+
interface RandomAccess {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types = 1);
2+
3+
/**
4+
* This file is part of the FireHub Project ecosystem
5+
*
6+
* @author Danijel Galić <danijel.galic@outlook.com>
7+
* @copyright 2026 The FireHub Project - All rights reserved
8+
* @license https://opensource.org/license/Apache-2-0 Apache License, Version 2.0
9+
*
10+
* @php-version 7.0
11+
* @package Core\Support
12+
*/
13+
14+
namespace FireHub\Core\Support\DataStructure\Capability\Access;
15+
16+
/**
17+
* ### Sequential Access
18+
*
19+
* Defines the ability to access elements in a strict sequential order, one after another, from beginning to end. It
20+
* guarantees ordered traversal but does not provide direct access to arbitrary positions without iteration.
21+
* @since 1.0.0
22+
*/
23+
interface SequentialAccess {}

0 commit comments

Comments
 (0)