exonware-xwnode 0.0.1.22__py3-none-any.whl → 0.0.1.23__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- exonware/__init__.py +1 -1
- exonware/xwnode/__init__.py +18 -5
- exonware/xwnode/add_strategy_types.py +165 -0
- exonware/xwnode/common/__init__.py +1 -1
- exonware/xwnode/common/graph/__init__.py +30 -0
- exonware/xwnode/common/graph/caching.py +131 -0
- exonware/xwnode/common/graph/contracts.py +100 -0
- exonware/xwnode/common/graph/errors.py +44 -0
- exonware/xwnode/common/graph/indexing.py +260 -0
- exonware/xwnode/common/graph/manager.py +568 -0
- exonware/xwnode/common/management/__init__.py +3 -5
- exonware/xwnode/common/management/manager.py +2 -2
- exonware/xwnode/common/management/migration.py +3 -3
- exonware/xwnode/common/monitoring/__init__.py +3 -5
- exonware/xwnode/common/monitoring/metrics.py +6 -2
- exonware/xwnode/common/monitoring/pattern_detector.py +1 -1
- exonware/xwnode/common/monitoring/performance_monitor.py +5 -1
- exonware/xwnode/common/patterns/__init__.py +3 -5
- exonware/xwnode/common/patterns/flyweight.py +5 -1
- exonware/xwnode/common/patterns/registry.py +202 -183
- exonware/xwnode/common/utils/__init__.py +25 -11
- exonware/xwnode/common/utils/simple.py +1 -1
- exonware/xwnode/config.py +3 -8
- exonware/xwnode/contracts.py +4 -105
- exonware/xwnode/defs.py +413 -159
- exonware/xwnode/edges/strategies/__init__.py +86 -4
- exonware/xwnode/edges/strategies/_base_edge.py +2 -2
- exonware/xwnode/edges/strategies/adj_list.py +287 -121
- exonware/xwnode/edges/strategies/adj_matrix.py +316 -222
- exonware/xwnode/edges/strategies/base.py +1 -1
- exonware/xwnode/edges/strategies/{edge_bidir_wrapper.py → bidir_wrapper.py} +45 -4
- exonware/xwnode/edges/strategies/bitemporal.py +520 -0
- exonware/xwnode/edges/strategies/{edge_block_adj_matrix.py → block_adj_matrix.py} +77 -6
- exonware/xwnode/edges/strategies/bv_graph.py +664 -0
- exonware/xwnode/edges/strategies/compressed_graph.py +217 -0
- exonware/xwnode/edges/strategies/{edge_coo.py → coo.py} +46 -4
- exonware/xwnode/edges/strategies/{edge_csc.py → csc.py} +45 -4
- exonware/xwnode/edges/strategies/{edge_csr.py → csr.py} +94 -12
- exonware/xwnode/edges/strategies/{edge_dynamic_adj_list.py → dynamic_adj_list.py} +46 -4
- exonware/xwnode/edges/strategies/edge_list.py +168 -0
- exonware/xwnode/edges/strategies/edge_property_store.py +2 -2
- exonware/xwnode/edges/strategies/euler_tour.py +560 -0
- exonware/xwnode/edges/strategies/{edge_flow_network.py → flow_network.py} +2 -2
- exonware/xwnode/edges/strategies/graphblas.py +449 -0
- exonware/xwnode/edges/strategies/hnsw.py +637 -0
- exonware/xwnode/edges/strategies/hop2_labels.py +467 -0
- exonware/xwnode/edges/strategies/{edge_hyperedge_set.py → hyperedge_set.py} +2 -2
- exonware/xwnode/edges/strategies/incidence_matrix.py +250 -0
- exonware/xwnode/edges/strategies/k2_tree.py +613 -0
- exonware/xwnode/edges/strategies/link_cut.py +626 -0
- exonware/xwnode/edges/strategies/multiplex.py +532 -0
- exonware/xwnode/edges/strategies/{edge_neural_graph.py → neural_graph.py} +2 -2
- exonware/xwnode/edges/strategies/{edge_octree.py → octree.py} +69 -11
- exonware/xwnode/edges/strategies/{edge_quadtree.py → quadtree.py} +66 -10
- exonware/xwnode/edges/strategies/roaring_adj.py +438 -0
- exonware/xwnode/edges/strategies/{edge_rtree.py → rtree.py} +43 -5
- exonware/xwnode/edges/strategies/{edge_temporal_edgeset.py → temporal_edgeset.py} +24 -5
- exonware/xwnode/edges/strategies/{edge_tree_graph_basic.py → tree_graph_basic.py} +78 -7
- exonware/xwnode/edges/strategies/{edge_weighted_graph.py → weighted_graph.py} +188 -10
- exonware/xwnode/errors.py +3 -6
- exonware/xwnode/facade.py +20 -20
- exonware/xwnode/nodes/strategies/__init__.py +29 -9
- exonware/xwnode/nodes/strategies/adjacency_list.py +650 -177
- exonware/xwnode/nodes/strategies/aho_corasick.py +358 -183
- exonware/xwnode/nodes/strategies/array_list.py +36 -3
- exonware/xwnode/nodes/strategies/art.py +581 -0
- exonware/xwnode/nodes/strategies/{node_avl_tree.py → avl_tree.py} +77 -6
- exonware/xwnode/nodes/strategies/{node_b_plus_tree.py → b_plus_tree.py} +81 -40
- exonware/xwnode/nodes/strategies/{node_btree.py → b_tree.py} +79 -9
- exonware/xwnode/nodes/strategies/base.py +469 -98
- exonware/xwnode/nodes/strategies/{node_bitmap.py → bitmap.py} +12 -12
- exonware/xwnode/nodes/strategies/{node_bitset_dynamic.py → bitset_dynamic.py} +11 -11
- exonware/xwnode/nodes/strategies/{node_bloom_filter.py → bloom_filter.py} +15 -2
- exonware/xwnode/nodes/strategies/bloomier_filter.py +519 -0
- exonware/xwnode/nodes/strategies/bw_tree.py +531 -0
- exonware/xwnode/nodes/strategies/contracts.py +1 -1
- exonware/xwnode/nodes/strategies/{node_count_min_sketch.py → count_min_sketch.py} +3 -2
- exonware/xwnode/nodes/strategies/{node_cow_tree.py → cow_tree.py} +135 -13
- exonware/xwnode/nodes/strategies/crdt_map.py +629 -0
- exonware/xwnode/nodes/strategies/{node_cuckoo_hash.py → cuckoo_hash.py} +2 -2
- exonware/xwnode/nodes/strategies/{node_xdata_optimized.py → data_interchange_optimized.py} +21 -4
- exonware/xwnode/nodes/strategies/dawg.py +876 -0
- exonware/xwnode/nodes/strategies/deque.py +321 -153
- exonware/xwnode/nodes/strategies/extendible_hash.py +93 -0
- exonware/xwnode/nodes/strategies/{node_fenwick_tree.py → fenwick_tree.py} +111 -19
- exonware/xwnode/nodes/strategies/hamt.py +403 -0
- exonware/xwnode/nodes/strategies/hash_map.py +354 -67
- exonware/xwnode/nodes/strategies/heap.py +105 -5
- exonware/xwnode/nodes/strategies/hopscotch_hash.py +525 -0
- exonware/xwnode/nodes/strategies/{node_hyperloglog.py → hyperloglog.py} +6 -5
- exonware/xwnode/nodes/strategies/interval_tree.py +742 -0
- exonware/xwnode/nodes/strategies/kd_tree.py +703 -0
- exonware/xwnode/nodes/strategies/learned_index.py +533 -0
- exonware/xwnode/nodes/strategies/linear_hash.py +93 -0
- exonware/xwnode/nodes/strategies/linked_list.py +316 -119
- exonware/xwnode/nodes/strategies/{node_lsm_tree.py → lsm_tree.py} +219 -15
- exonware/xwnode/nodes/strategies/masstree.py +130 -0
- exonware/xwnode/nodes/strategies/{node_persistent_tree.py → persistent_tree.py} +149 -9
- exonware/xwnode/nodes/strategies/priority_queue.py +544 -132
- exonware/xwnode/nodes/strategies/queue.py +249 -120
- exonware/xwnode/nodes/strategies/{node_red_black_tree.py → red_black_tree.py} +183 -72
- exonware/xwnode/nodes/strategies/{node_roaring_bitmap.py → roaring_bitmap.py} +19 -6
- exonware/xwnode/nodes/strategies/rope.py +717 -0
- exonware/xwnode/nodes/strategies/{node_segment_tree.py → segment_tree.py} +106 -106
- exonware/xwnode/nodes/strategies/{node_set_hash.py → set_hash.py} +30 -29
- exonware/xwnode/nodes/strategies/{node_skip_list.py → skip_list.py} +74 -6
- exonware/xwnode/nodes/strategies/sparse_matrix.py +427 -131
- exonware/xwnode/nodes/strategies/{node_splay_tree.py → splay_tree.py} +55 -6
- exonware/xwnode/nodes/strategies/stack.py +244 -112
- exonware/xwnode/nodes/strategies/{node_suffix_array.py → suffix_array.py} +5 -1
- exonware/xwnode/nodes/strategies/t_tree.py +94 -0
- exonware/xwnode/nodes/strategies/{node_treap.py → treap.py} +75 -6
- exonware/xwnode/nodes/strategies/{node_tree_graph_hybrid.py → tree_graph_hybrid.py} +46 -5
- exonware/xwnode/nodes/strategies/trie.py +153 -9
- exonware/xwnode/nodes/strategies/union_find.py +111 -5
- exonware/xwnode/nodes/strategies/veb_tree.py +856 -0
- exonware/xwnode/strategies/__init__.py +5 -51
- exonware/xwnode/version.py +3 -3
- {exonware_xwnode-0.0.1.22.dist-info → exonware_xwnode-0.0.1.23.dist-info}/METADATA +23 -3
- exonware_xwnode-0.0.1.23.dist-info/RECORD +130 -0
- exonware/xwnode/edges/strategies/edge_adj_list.py +0 -353
- exonware/xwnode/edges/strategies/edge_adj_matrix.py +0 -445
- exonware/xwnode/nodes/strategies/_base_node.py +0 -307
- exonware/xwnode/nodes/strategies/node_aho_corasick.py +0 -525
- exonware/xwnode/nodes/strategies/node_array_list.py +0 -179
- exonware/xwnode/nodes/strategies/node_hash_map.py +0 -273
- exonware/xwnode/nodes/strategies/node_heap.py +0 -196
- exonware/xwnode/nodes/strategies/node_linked_list.py +0 -413
- exonware/xwnode/nodes/strategies/node_trie.py +0 -257
- exonware/xwnode/nodes/strategies/node_union_find.py +0 -192
- exonware/xwnode/queries/executors/__init__.py +0 -47
- exonware/xwnode/queries/executors/advanced/__init__.py +0 -37
- exonware/xwnode/queries/executors/advanced/aggregate_executor.py +0 -50
- exonware/xwnode/queries/executors/advanced/ask_executor.py +0 -50
- exonware/xwnode/queries/executors/advanced/construct_executor.py +0 -50
- exonware/xwnode/queries/executors/advanced/describe_executor.py +0 -50
- exonware/xwnode/queries/executors/advanced/for_loop_executor.py +0 -50
- exonware/xwnode/queries/executors/advanced/foreach_executor.py +0 -50
- exonware/xwnode/queries/executors/advanced/join_executor.py +0 -50
- exonware/xwnode/queries/executors/advanced/let_executor.py +0 -50
- exonware/xwnode/queries/executors/advanced/mutation_executor.py +0 -50
- exonware/xwnode/queries/executors/advanced/options_executor.py +0 -50
- exonware/xwnode/queries/executors/advanced/pipe_executor.py +0 -50
- exonware/xwnode/queries/executors/advanced/subscribe_executor.py +0 -50
- exonware/xwnode/queries/executors/advanced/subscription_executor.py +0 -50
- exonware/xwnode/queries/executors/advanced/union_executor.py +0 -50
- exonware/xwnode/queries/executors/advanced/window_executor.py +0 -51
- exonware/xwnode/queries/executors/advanced/with_cte_executor.py +0 -50
- exonware/xwnode/queries/executors/aggregation/__init__.py +0 -21
- exonware/xwnode/queries/executors/aggregation/avg_executor.py +0 -50
- exonware/xwnode/queries/executors/aggregation/count_executor.py +0 -38
- exonware/xwnode/queries/executors/aggregation/distinct_executor.py +0 -50
- exonware/xwnode/queries/executors/aggregation/group_executor.py +0 -50
- exonware/xwnode/queries/executors/aggregation/having_executor.py +0 -50
- exonware/xwnode/queries/executors/aggregation/max_executor.py +0 -50
- exonware/xwnode/queries/executors/aggregation/min_executor.py +0 -50
- exonware/xwnode/queries/executors/aggregation/sum_executor.py +0 -50
- exonware/xwnode/queries/executors/aggregation/summarize_executor.py +0 -50
- exonware/xwnode/queries/executors/array/__init__.py +0 -9
- exonware/xwnode/queries/executors/array/indexing_executor.py +0 -51
- exonware/xwnode/queries/executors/array/slicing_executor.py +0 -51
- exonware/xwnode/queries/executors/base.py +0 -257
- exonware/xwnode/queries/executors/capability_checker.py +0 -204
- exonware/xwnode/queries/executors/contracts.py +0 -166
- exonware/xwnode/queries/executors/core/__init__.py +0 -17
- exonware/xwnode/queries/executors/core/create_executor.py +0 -96
- exonware/xwnode/queries/executors/core/delete_executor.py +0 -99
- exonware/xwnode/queries/executors/core/drop_executor.py +0 -100
- exonware/xwnode/queries/executors/core/insert_executor.py +0 -39
- exonware/xwnode/queries/executors/core/select_executor.py +0 -152
- exonware/xwnode/queries/executors/core/update_executor.py +0 -102
- exonware/xwnode/queries/executors/data/__init__.py +0 -13
- exonware/xwnode/queries/executors/data/alter_executor.py +0 -50
- exonware/xwnode/queries/executors/data/load_executor.py +0 -50
- exonware/xwnode/queries/executors/data/merge_executor.py +0 -50
- exonware/xwnode/queries/executors/data/store_executor.py +0 -50
- exonware/xwnode/queries/executors/defs.py +0 -93
- exonware/xwnode/queries/executors/engine.py +0 -221
- exonware/xwnode/queries/executors/errors.py +0 -68
- exonware/xwnode/queries/executors/filtering/__init__.py +0 -25
- exonware/xwnode/queries/executors/filtering/between_executor.py +0 -80
- exonware/xwnode/queries/executors/filtering/filter_executor.py +0 -79
- exonware/xwnode/queries/executors/filtering/has_executor.py +0 -70
- exonware/xwnode/queries/executors/filtering/in_executor.py +0 -70
- exonware/xwnode/queries/executors/filtering/like_executor.py +0 -76
- exonware/xwnode/queries/executors/filtering/optional_executor.py +0 -76
- exonware/xwnode/queries/executors/filtering/range_executor.py +0 -80
- exonware/xwnode/queries/executors/filtering/term_executor.py +0 -77
- exonware/xwnode/queries/executors/filtering/values_executor.py +0 -71
- exonware/xwnode/queries/executors/filtering/where_executor.py +0 -44
- exonware/xwnode/queries/executors/graph/__init__.py +0 -15
- exonware/xwnode/queries/executors/graph/in_traverse_executor.py +0 -51
- exonware/xwnode/queries/executors/graph/match_executor.py +0 -51
- exonware/xwnode/queries/executors/graph/out_executor.py +0 -51
- exonware/xwnode/queries/executors/graph/path_executor.py +0 -51
- exonware/xwnode/queries/executors/graph/return_executor.py +0 -51
- exonware/xwnode/queries/executors/ordering/__init__.py +0 -9
- exonware/xwnode/queries/executors/ordering/by_executor.py +0 -50
- exonware/xwnode/queries/executors/ordering/order_executor.py +0 -51
- exonware/xwnode/queries/executors/projection/__init__.py +0 -9
- exonware/xwnode/queries/executors/projection/extend_executor.py +0 -50
- exonware/xwnode/queries/executors/projection/project_executor.py +0 -50
- exonware/xwnode/queries/executors/registry.py +0 -173
- exonware/xwnode/queries/parsers/__init__.py +0 -26
- exonware/xwnode/queries/parsers/base.py +0 -86
- exonware/xwnode/queries/parsers/contracts.py +0 -46
- exonware/xwnode/queries/parsers/errors.py +0 -53
- exonware/xwnode/queries/parsers/sql_param_extractor.py +0 -318
- exonware/xwnode/queries/strategies/__init__.py +0 -24
- exonware/xwnode/queries/strategies/base.py +0 -236
- exonware/xwnode/queries/strategies/cql.py +0 -201
- exonware/xwnode/queries/strategies/cypher.py +0 -181
- exonware/xwnode/queries/strategies/datalog.py +0 -70
- exonware/xwnode/queries/strategies/elastic_dsl.py +0 -70
- exonware/xwnode/queries/strategies/eql.py +0 -70
- exonware/xwnode/queries/strategies/flux.py +0 -70
- exonware/xwnode/queries/strategies/gql.py +0 -70
- exonware/xwnode/queries/strategies/graphql.py +0 -240
- exonware/xwnode/queries/strategies/gremlin.py +0 -181
- exonware/xwnode/queries/strategies/hiveql.py +0 -214
- exonware/xwnode/queries/strategies/hql.py +0 -70
- exonware/xwnode/queries/strategies/jmespath.py +0 -219
- exonware/xwnode/queries/strategies/jq.py +0 -66
- exonware/xwnode/queries/strategies/json_query.py +0 -66
- exonware/xwnode/queries/strategies/jsoniq.py +0 -248
- exonware/xwnode/queries/strategies/kql.py +0 -70
- exonware/xwnode/queries/strategies/linq.py +0 -238
- exonware/xwnode/queries/strategies/logql.py +0 -70
- exonware/xwnode/queries/strategies/mql.py +0 -68
- exonware/xwnode/queries/strategies/n1ql.py +0 -210
- exonware/xwnode/queries/strategies/partiql.py +0 -70
- exonware/xwnode/queries/strategies/pig.py +0 -215
- exonware/xwnode/queries/strategies/promql.py +0 -70
- exonware/xwnode/queries/strategies/sparql.py +0 -220
- exonware/xwnode/queries/strategies/sql.py +0 -275
- exonware/xwnode/queries/strategies/xml_query.py +0 -66
- exonware/xwnode/queries/strategies/xpath.py +0 -223
- exonware/xwnode/queries/strategies/xquery.py +0 -258
- exonware/xwnode/queries/strategies/xwnode_executor.py +0 -332
- exonware/xwnode/queries/strategies/xwquery.py +0 -456
- exonware_xwnode-0.0.1.22.dist-info/RECORD +0 -214
- /exonware/xwnode/nodes/strategies/{node_ordered_map.py → ordered_map.py} +0 -0
- /exonware/xwnode/nodes/strategies/{node_ordered_map_balanced.py → ordered_map_balanced.py} +0 -0
- /exonware/xwnode/nodes/strategies/{node_patricia.py → patricia.py} +0 -0
- /exonware/xwnode/nodes/strategies/{node_radix_trie.py → radix_trie.py} +0 -0
- /exonware/xwnode/nodes/strategies/{node_set_tree.py → set_tree.py} +0 -0
- {exonware_xwnode-0.0.1.22.dist-info → exonware_xwnode-0.0.1.23.dist-info}/WHEEL +0 -0
- {exonware_xwnode-0.0.1.22.dist-info → exonware_xwnode-0.0.1.23.dist-info}/licenses/LICENSE +0 -0
@@ -1,16 +1,25 @@
|
|
1
1
|
"""
|
2
|
+
#exonware/xwnode/src/exonware/xwnode/nodes/strategies/queue.py
|
3
|
+
|
2
4
|
Queue Strategy Implementation
|
3
5
|
|
4
|
-
|
6
|
+
Production-grade FIFO (First In, First Out) data structure.
|
7
|
+
|
8
|
+
Best Practices Implemented:
|
9
|
+
- Pure queue operations using collections.deque
|
10
|
+
- O(1) enqueue and dequeue operations
|
11
|
+
- Thread-safe for single-producer single-consumer
|
12
|
+
- Memory-efficient with minimal overhead
|
13
|
+
- Proper FIFO semantics following CLRS and industry standards
|
5
14
|
|
6
15
|
Company: eXonware.com
|
7
16
|
Author: Eng. Muhammad AlShehri
|
8
17
|
Email: connect@exonware.com
|
9
|
-
Version: 0.0.1.
|
10
|
-
Generation Date:
|
18
|
+
Version: 0.0.1.23
|
19
|
+
Generation Date: October 12, 2025
|
11
20
|
"""
|
12
21
|
|
13
|
-
from typing import Any, Iterator, Optional, Dict
|
22
|
+
from typing import Any, Iterator, List, Optional, Dict
|
14
23
|
from collections import deque
|
15
24
|
from .base import ANodeLinearStrategy
|
16
25
|
from .contracts import NodeType
|
@@ -19,44 +28,181 @@ from ...defs import NodeMode, NodeTrait
|
|
19
28
|
|
20
29
|
class QueueStrategy(ANodeLinearStrategy):
|
21
30
|
"""
|
22
|
-
Queue node strategy
|
31
|
+
Production-grade Queue (FIFO) node strategy.
|
32
|
+
|
33
|
+
Optimized for:
|
34
|
+
- Task scheduling (job queues, worker pools)
|
35
|
+
- Breadth-first search (BFS algorithms)
|
36
|
+
- Request buffering (rate limiting, throttling)
|
37
|
+
- Message passing (producer-consumer patterns)
|
38
|
+
- Event handling (event loops, message queues)
|
39
|
+
|
40
|
+
Performance:
|
41
|
+
- Enqueue: O(1)
|
42
|
+
- Dequeue: O(1)
|
43
|
+
- Peek: O(1)
|
44
|
+
- Space: O(n)
|
23
45
|
|
24
|
-
|
25
|
-
|
46
|
+
Security:
|
47
|
+
- Bounds checking on all operations
|
48
|
+
- Safe empty queue handling
|
49
|
+
- Optional max size for memory protection
|
50
|
+
|
51
|
+
Thread-Safety:
|
52
|
+
- Thread-safe for single-producer single-consumer
|
53
|
+
- Use queue.Queue for multi-threaded scenarios
|
54
|
+
|
55
|
+
Follows eXonware Priorities:
|
56
|
+
1. Security: Proper bounds checking, memory limits
|
57
|
+
2. Usability: Standard FIFO interface
|
58
|
+
3. Maintainability: Clean, well-documented implementation
|
59
|
+
4. Performance: O(1) operations using deque
|
60
|
+
5. Extensibility: Easy to extend for specific use cases
|
61
|
+
"""
|
26
62
|
|
27
63
|
# Strategy type classification
|
28
64
|
STRATEGY_TYPE = NodeType.LINEAR
|
29
|
-
nd breadth-first search.
|
30
|
-
"""
|
31
65
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
def
|
53
|
-
"""
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
66
|
+
__slots__ = ('_queue', '_max_size')
|
67
|
+
|
68
|
+
def __init__(self, traits: NodeTrait = NodeTrait.NONE, **options):
|
69
|
+
"""
|
70
|
+
Initialize an empty queue.
|
71
|
+
|
72
|
+
Args:
|
73
|
+
traits: Additional node traits
|
74
|
+
**options:
|
75
|
+
max_size: Optional maximum queue size (default: unlimited)
|
76
|
+
initial_values: Optional list of initial values
|
77
|
+
"""
|
78
|
+
super().__init__(
|
79
|
+
NodeMode.QUEUE,
|
80
|
+
traits | NodeTrait.FIFO | NodeTrait.FAST_INSERT | NodeTrait.FAST_DELETE,
|
81
|
+
**options
|
82
|
+
)
|
83
|
+
self._max_size: Optional[int] = options.get('max_size')
|
84
|
+
self._queue: deque = deque(options.get('initial_values', []))
|
85
|
+
|
86
|
+
def get_supported_traits(self) -> NodeTrait:
|
87
|
+
"""Get the traits supported by the queue strategy."""
|
88
|
+
return NodeTrait.FIFO | NodeTrait.FAST_INSERT | NodeTrait.FAST_DELETE
|
89
|
+
|
90
|
+
# ============================================================================
|
91
|
+
# CORE QUEUE OPERATIONS (Industry Standard)
|
92
|
+
# ============================================================================
|
93
|
+
|
94
|
+
def enqueue(self, value: Any) -> None:
|
95
|
+
"""
|
96
|
+
Add an item to the back of the queue.
|
97
|
+
|
98
|
+
Time: O(1)
|
99
|
+
Space: O(1)
|
100
|
+
|
101
|
+
Raises:
|
102
|
+
OverflowError: If max_size is set and queue is full
|
103
|
+
"""
|
104
|
+
if self._max_size and len(self._queue) >= self._max_size:
|
105
|
+
raise OverflowError(f"Queue overflow: max size {self._max_size} reached")
|
106
|
+
|
107
|
+
self._queue.append(value)
|
108
|
+
|
109
|
+
def dequeue(self) -> Any:
|
110
|
+
"""
|
111
|
+
Remove and return the front item from the queue.
|
112
|
+
|
113
|
+
Time: O(1)
|
114
|
+
Space: O(1)
|
115
|
+
|
116
|
+
Returns:
|
117
|
+
The front item
|
118
|
+
|
119
|
+
Raises:
|
120
|
+
IndexError: If queue is empty
|
121
|
+
"""
|
122
|
+
if self.is_empty():
|
123
|
+
raise IndexError("dequeue from empty queue")
|
124
|
+
|
125
|
+
return self._queue.popleft()
|
126
|
+
|
127
|
+
def front(self) -> Any:
|
128
|
+
"""
|
129
|
+
Peek at the front item without removing it.
|
130
|
+
|
131
|
+
Time: O(1)
|
132
|
+
Space: O(1)
|
133
|
+
|
134
|
+
Returns:
|
135
|
+
The front item
|
136
|
+
|
137
|
+
Raises:
|
138
|
+
IndexError: If queue is empty
|
139
|
+
"""
|
140
|
+
if self.is_empty():
|
141
|
+
raise IndexError("peek from empty queue")
|
142
|
+
|
143
|
+
return self._queue[0]
|
144
|
+
|
145
|
+
def rear(self) -> Any:
|
146
|
+
"""
|
147
|
+
Peek at the back item without removing it.
|
148
|
+
|
149
|
+
Time: O(1)
|
150
|
+
Space: O(1)
|
151
|
+
|
152
|
+
Returns:
|
153
|
+
The back item
|
154
|
+
|
155
|
+
Raises:
|
156
|
+
IndexError: If queue is empty
|
157
|
+
"""
|
158
|
+
if self.is_empty():
|
159
|
+
raise IndexError("peek from empty queue")
|
160
|
+
|
161
|
+
return self._queue[-1]
|
162
|
+
|
163
|
+
# ============================================================================
|
164
|
+
# REQUIRED ABSTRACT METHODS (from ANodeStrategy)
|
165
|
+
# ============================================================================
|
166
|
+
|
167
|
+
def put(self, key: Any, value: Any = None) -> None:
|
168
|
+
"""Store value (enqueues to queue, ignores key)."""
|
169
|
+
self.enqueue(value if value is not None else key)
|
170
|
+
|
171
|
+
def get(self, key: Any, default: Any = None) -> Any:
|
172
|
+
"""Get value by key (O(n) search - not recommended for queue)."""
|
173
|
+
for val in self._queue:
|
174
|
+
if val == key:
|
175
|
+
return val
|
176
|
+
return default
|
177
|
+
|
178
|
+
def has(self, key: Any) -> bool:
|
179
|
+
"""Check if key exists (O(n) - not recommended for queue)."""
|
180
|
+
return key in self._queue
|
181
|
+
|
182
|
+
def delete(self, key: Any) -> bool:
|
183
|
+
"""Delete specific value (O(n) - not recommended for queue)."""
|
184
|
+
try:
|
185
|
+
self._queue.remove(key)
|
186
|
+
return True
|
187
|
+
except ValueError:
|
188
|
+
return False
|
189
|
+
|
190
|
+
def keys(self) -> Iterator[Any]:
|
191
|
+
"""Get all values as keys (queue doesn't have traditional keys)."""
|
192
|
+
return iter(self._queue)
|
193
|
+
|
194
|
+
def values(self) -> Iterator[Any]:
|
195
|
+
"""Get all values."""
|
196
|
+
return iter(self._queue)
|
197
|
+
|
198
|
+
def items(self) -> Iterator[tuple[Any, Any]]:
|
199
|
+
"""Get all items as (value, value) pairs."""
|
200
|
+
for val in self._queue:
|
201
|
+
yield (val, val)
|
202
|
+
|
203
|
+
# ============================================================================
|
204
|
+
# UTILITY METHODS
|
205
|
+
# ============================================================================
|
60
206
|
|
61
207
|
def size(self) -> int:
|
62
208
|
"""Get the number of items in the queue."""
|
@@ -66,101 +212,84 @@ nd breadth-first search.
|
|
66
212
|
"""Check if the queue is empty."""
|
67
213
|
return len(self._queue) == 0
|
68
214
|
|
215
|
+
def is_full(self) -> bool:
|
216
|
+
"""Check if queue has reached max_size."""
|
217
|
+
return self._max_size is not None and len(self._queue) >= self._max_size
|
218
|
+
|
219
|
+
def clear(self) -> None:
|
220
|
+
"""Clear all items from the queue."""
|
221
|
+
self._queue.clear()
|
222
|
+
|
223
|
+
def to_list(self) -> List[Any]:
|
224
|
+
"""Convert queue to list (front to back)."""
|
225
|
+
return list(self._queue)
|
226
|
+
|
69
227
|
def to_native(self) -> Dict[str, Any]:
|
70
228
|
"""Convert queue to native dictionary format."""
|
71
|
-
return
|
229
|
+
return {str(i): val for i, val in enumerate(self._queue)}
|
72
230
|
|
73
231
|
def from_native(self, data: Dict[str, Any]) -> None:
|
74
232
|
"""Load queue from native dictionary format."""
|
75
|
-
self._queue
|
233
|
+
self._queue.clear()
|
234
|
+
# Sort by keys to maintain order
|
235
|
+
sorted_items = sorted(data.items(), key=lambda x: int(x[0]) if x[0].isdigit() else 0)
|
236
|
+
self._queue.extend(val for _, val in sorted_items)
|
76
237
|
|
77
|
-
def enqueue(self, value: Any) -> None:
|
78
|
-
"""Enqueue a value into the queue."""
|
79
|
-
key = f"item_{len(self._queue)}"
|
80
|
-
self.insert(key, value)
|
81
238
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
return None
|
86
|
-
key, value = self._queue.popleft()
|
87
|
-
self._record_access("dequeue")
|
88
|
-
return value
|
239
|
+
# ============================================================================
|
240
|
+
# PYTHON SPECIAL METHODS
|
241
|
+
# ============================================================================
|
89
242
|
|
90
|
-
def
|
91
|
-
"""
|
92
|
-
|
93
|
-
return None
|
94
|
-
key, value = self._queue[0]
|
95
|
-
self._record_access("front")
|
96
|
-
return value
|
243
|
+
def __len__(self) -> int:
|
244
|
+
"""Return the number of items in the queue."""
|
245
|
+
return len(self._queue)
|
97
246
|
|
98
|
-
def
|
99
|
-
"""
|
100
|
-
|
101
|
-
return None
|
102
|
-
key, value = self._queue[-1]
|
103
|
-
self._record_access("back")
|
104
|
-
return value
|
247
|
+
def __bool__(self) -> bool:
|
248
|
+
"""Return True if queue is not empty."""
|
249
|
+
return bool(self._queue)
|
105
250
|
|
106
|
-
def
|
107
|
-
"""
|
108
|
-
self._queue
|
109
|
-
self._record_access("clear")
|
251
|
+
def __iter__(self) -> Iterator[Any]:
|
252
|
+
"""Iterate through queue items (front to back)."""
|
253
|
+
return iter(self._queue)
|
110
254
|
|
111
|
-
def
|
112
|
-
"""
|
113
|
-
|
114
|
-
key, value = self._queue[index]
|
115
|
-
self._record_access("get_at_index")
|
116
|
-
return value
|
117
|
-
return None
|
255
|
+
def __repr__(self) -> str:
|
256
|
+
"""Professional string representation."""
|
257
|
+
return f"QueueStrategy(size={len(self._queue)}, front={self.front() if not self.is_empty() else None})"
|
118
258
|
|
119
|
-
def
|
120
|
-
"""
|
121
|
-
|
122
|
-
self.
|
259
|
+
def __str__(self) -> str:
|
260
|
+
"""Human-readable string representation."""
|
261
|
+
items = ', '.join(str(item) for item in list(self._queue)[:5])
|
262
|
+
suffix = '...' if len(self._queue) > 5 else ''
|
263
|
+
return f"Queue[{items}{suffix}]"
|
123
264
|
|
124
|
-
|
125
|
-
|
126
|
-
|
265
|
+
# ============================================================================
|
266
|
+
# PERFORMANCE METADATA
|
267
|
+
# ============================================================================
|
127
268
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
269
|
+
@property
|
270
|
+
def backend_info(self) -> Dict[str, Any]:
|
271
|
+
"""Get backend implementation info."""
|
272
|
+
return {
|
273
|
+
'strategy': 'QUEUE',
|
274
|
+
'backend': 'collections.deque (doubly-linked list)',
|
275
|
+
'complexity': {
|
276
|
+
'enqueue': 'O(1)',
|
277
|
+
'dequeue': 'O(1)',
|
278
|
+
'front': 'O(1)',
|
279
|
+
'search': 'O(n)', # Not recommended
|
280
|
+
'space': 'O(n)'
|
281
|
+
},
|
282
|
+
'thread_safe': 'single-producer single-consumer only',
|
283
|
+
'max_size': self._max_size if self._max_size else 'unlimited'
|
284
|
+
}
|
132
285
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
"""Remove element from back (not applicable for queue)."""
|
144
|
-
raise NotImplementedError("Queue doesn't support pop_back")
|
145
|
-
|
146
|
-
def set_at_index(self, index: int, value: Any) -> None:
|
147
|
-
"""Set element at index (not recommended for queue)."""
|
148
|
-
if 0 <= index < len(self._queue):
|
149
|
-
key, old_value = self._queue[index]
|
150
|
-
self._queue[index] = (key, value)
|
151
|
-
|
152
|
-
def as_linked_list(self):
|
153
|
-
"""Provide LinkedList behavioral view."""
|
154
|
-
return self
|
155
|
-
|
156
|
-
def as_stack(self):
|
157
|
-
"""Provide Stack behavioral view (not recommended)."""
|
158
|
-
raise NotImplementedError("Queue cannot behave as Stack")
|
159
|
-
|
160
|
-
def as_queue(self):
|
161
|
-
"""Provide Queue behavioral view."""
|
162
|
-
return self
|
163
|
-
|
164
|
-
def as_deque(self):
|
165
|
-
"""Provide Deque behavioral view."""
|
166
|
-
return self
|
286
|
+
@property
|
287
|
+
def metrics(self) -> Dict[str, Any]:
|
288
|
+
"""Get performance metrics."""
|
289
|
+
return {
|
290
|
+
'size': len(self._queue),
|
291
|
+
'is_empty': self.is_empty(),
|
292
|
+
'is_full': self.is_full(),
|
293
|
+
'max_size': self._max_size,
|
294
|
+
'memory_usage': f"{len(self._queue) * 8} bytes (estimated)"
|
295
|
+
}
|