exonware-xwnode 0.0.1.12__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.
Files changed (132) hide show
  1. exonware/__init__.py +14 -0
  2. exonware/xwnode/__init__.py +127 -0
  3. exonware/xwnode/base.py +676 -0
  4. exonware/xwnode/config.py +178 -0
  5. exonware/xwnode/contracts.py +730 -0
  6. exonware/xwnode/errors.py +503 -0
  7. exonware/xwnode/facade.py +460 -0
  8. exonware/xwnode/strategies/__init__.py +158 -0
  9. exonware/xwnode/strategies/advisor.py +463 -0
  10. exonware/xwnode/strategies/edges/__init__.py +32 -0
  11. exonware/xwnode/strategies/edges/adj_list.py +227 -0
  12. exonware/xwnode/strategies/edges/adj_matrix.py +391 -0
  13. exonware/xwnode/strategies/edges/base.py +169 -0
  14. exonware/xwnode/strategies/flyweight.py +328 -0
  15. exonware/xwnode/strategies/impls/__init__.py +13 -0
  16. exonware/xwnode/strategies/impls/_base_edge.py +403 -0
  17. exonware/xwnode/strategies/impls/_base_node.py +307 -0
  18. exonware/xwnode/strategies/impls/edge_adj_list.py +353 -0
  19. exonware/xwnode/strategies/impls/edge_adj_matrix.py +445 -0
  20. exonware/xwnode/strategies/impls/edge_bidir_wrapper.py +455 -0
  21. exonware/xwnode/strategies/impls/edge_block_adj_matrix.py +539 -0
  22. exonware/xwnode/strategies/impls/edge_coo.py +533 -0
  23. exonware/xwnode/strategies/impls/edge_csc.py +447 -0
  24. exonware/xwnode/strategies/impls/edge_csr.py +492 -0
  25. exonware/xwnode/strategies/impls/edge_dynamic_adj_list.py +503 -0
  26. exonware/xwnode/strategies/impls/edge_flow_network.py +555 -0
  27. exonware/xwnode/strategies/impls/edge_hyperedge_set.py +516 -0
  28. exonware/xwnode/strategies/impls/edge_neural_graph.py +650 -0
  29. exonware/xwnode/strategies/impls/edge_octree.py +574 -0
  30. exonware/xwnode/strategies/impls/edge_property_store.py +655 -0
  31. exonware/xwnode/strategies/impls/edge_quadtree.py +519 -0
  32. exonware/xwnode/strategies/impls/edge_rtree.py +820 -0
  33. exonware/xwnode/strategies/impls/edge_temporal_edgeset.py +558 -0
  34. exonware/xwnode/strategies/impls/edge_tree_graph_basic.py +271 -0
  35. exonware/xwnode/strategies/impls/edge_weighted_graph.py +411 -0
  36. exonware/xwnode/strategies/manager.py +775 -0
  37. exonware/xwnode/strategies/metrics.py +538 -0
  38. exonware/xwnode/strategies/migration.py +432 -0
  39. exonware/xwnode/strategies/nodes/__init__.py +50 -0
  40. exonware/xwnode/strategies/nodes/_base_node.py +307 -0
  41. exonware/xwnode/strategies/nodes/adjacency_list.py +267 -0
  42. exonware/xwnode/strategies/nodes/aho_corasick.py +345 -0
  43. exonware/xwnode/strategies/nodes/array_list.py +209 -0
  44. exonware/xwnode/strategies/nodes/base.py +247 -0
  45. exonware/xwnode/strategies/nodes/deque.py +200 -0
  46. exonware/xwnode/strategies/nodes/hash_map.py +135 -0
  47. exonware/xwnode/strategies/nodes/heap.py +307 -0
  48. exonware/xwnode/strategies/nodes/linked_list.py +232 -0
  49. exonware/xwnode/strategies/nodes/node_aho_corasick.py +520 -0
  50. exonware/xwnode/strategies/nodes/node_array_list.py +175 -0
  51. exonware/xwnode/strategies/nodes/node_avl_tree.py +371 -0
  52. exonware/xwnode/strategies/nodes/node_b_plus_tree.py +542 -0
  53. exonware/xwnode/strategies/nodes/node_bitmap.py +420 -0
  54. exonware/xwnode/strategies/nodes/node_bitset_dynamic.py +513 -0
  55. exonware/xwnode/strategies/nodes/node_bloom_filter.py +347 -0
  56. exonware/xwnode/strategies/nodes/node_btree.py +357 -0
  57. exonware/xwnode/strategies/nodes/node_count_min_sketch.py +470 -0
  58. exonware/xwnode/strategies/nodes/node_cow_tree.py +473 -0
  59. exonware/xwnode/strategies/nodes/node_cuckoo_hash.py +392 -0
  60. exonware/xwnode/strategies/nodes/node_fenwick_tree.py +301 -0
  61. exonware/xwnode/strategies/nodes/node_hash_map.py +269 -0
  62. exonware/xwnode/strategies/nodes/node_heap.py +191 -0
  63. exonware/xwnode/strategies/nodes/node_hyperloglog.py +407 -0
  64. exonware/xwnode/strategies/nodes/node_linked_list.py +409 -0
  65. exonware/xwnode/strategies/nodes/node_lsm_tree.py +400 -0
  66. exonware/xwnode/strategies/nodes/node_ordered_map.py +390 -0
  67. exonware/xwnode/strategies/nodes/node_ordered_map_balanced.py +565 -0
  68. exonware/xwnode/strategies/nodes/node_patricia.py +512 -0
  69. exonware/xwnode/strategies/nodes/node_persistent_tree.py +378 -0
  70. exonware/xwnode/strategies/nodes/node_radix_trie.py +452 -0
  71. exonware/xwnode/strategies/nodes/node_red_black_tree.py +497 -0
  72. exonware/xwnode/strategies/nodes/node_roaring_bitmap.py +570 -0
  73. exonware/xwnode/strategies/nodes/node_segment_tree.py +289 -0
  74. exonware/xwnode/strategies/nodes/node_set_hash.py +354 -0
  75. exonware/xwnode/strategies/nodes/node_set_tree.py +480 -0
  76. exonware/xwnode/strategies/nodes/node_skip_list.py +316 -0
  77. exonware/xwnode/strategies/nodes/node_splay_tree.py +393 -0
  78. exonware/xwnode/strategies/nodes/node_suffix_array.py +487 -0
  79. exonware/xwnode/strategies/nodes/node_treap.py +387 -0
  80. exonware/xwnode/strategies/nodes/node_tree_graph_hybrid.py +1434 -0
  81. exonware/xwnode/strategies/nodes/node_trie.py +252 -0
  82. exonware/xwnode/strategies/nodes/node_union_find.py +187 -0
  83. exonware/xwnode/strategies/nodes/node_xdata_optimized.py +369 -0
  84. exonware/xwnode/strategies/nodes/priority_queue.py +209 -0
  85. exonware/xwnode/strategies/nodes/queue.py +161 -0
  86. exonware/xwnode/strategies/nodes/sparse_matrix.py +206 -0
  87. exonware/xwnode/strategies/nodes/stack.py +152 -0
  88. exonware/xwnode/strategies/nodes/trie.py +274 -0
  89. exonware/xwnode/strategies/nodes/union_find.py +283 -0
  90. exonware/xwnode/strategies/pattern_detector.py +603 -0
  91. exonware/xwnode/strategies/performance_monitor.py +487 -0
  92. exonware/xwnode/strategies/queries/__init__.py +24 -0
  93. exonware/xwnode/strategies/queries/base.py +236 -0
  94. exonware/xwnode/strategies/queries/cql.py +201 -0
  95. exonware/xwnode/strategies/queries/cypher.py +181 -0
  96. exonware/xwnode/strategies/queries/datalog.py +70 -0
  97. exonware/xwnode/strategies/queries/elastic_dsl.py +70 -0
  98. exonware/xwnode/strategies/queries/eql.py +70 -0
  99. exonware/xwnode/strategies/queries/flux.py +70 -0
  100. exonware/xwnode/strategies/queries/gql.py +70 -0
  101. exonware/xwnode/strategies/queries/graphql.py +240 -0
  102. exonware/xwnode/strategies/queries/gremlin.py +181 -0
  103. exonware/xwnode/strategies/queries/hiveql.py +214 -0
  104. exonware/xwnode/strategies/queries/hql.py +70 -0
  105. exonware/xwnode/strategies/queries/jmespath.py +219 -0
  106. exonware/xwnode/strategies/queries/jq.py +66 -0
  107. exonware/xwnode/strategies/queries/json_query.py +66 -0
  108. exonware/xwnode/strategies/queries/jsoniq.py +248 -0
  109. exonware/xwnode/strategies/queries/kql.py +70 -0
  110. exonware/xwnode/strategies/queries/linq.py +238 -0
  111. exonware/xwnode/strategies/queries/logql.py +70 -0
  112. exonware/xwnode/strategies/queries/mql.py +68 -0
  113. exonware/xwnode/strategies/queries/n1ql.py +210 -0
  114. exonware/xwnode/strategies/queries/partiql.py +70 -0
  115. exonware/xwnode/strategies/queries/pig.py +215 -0
  116. exonware/xwnode/strategies/queries/promql.py +70 -0
  117. exonware/xwnode/strategies/queries/sparql.py +220 -0
  118. exonware/xwnode/strategies/queries/sql.py +275 -0
  119. exonware/xwnode/strategies/queries/xml_query.py +66 -0
  120. exonware/xwnode/strategies/queries/xpath.py +223 -0
  121. exonware/xwnode/strategies/queries/xquery.py +258 -0
  122. exonware/xwnode/strategies/queries/xwnode_executor.py +332 -0
  123. exonware/xwnode/strategies/queries/xwquery_strategy.py +424 -0
  124. exonware/xwnode/strategies/registry.py +604 -0
  125. exonware/xwnode/strategies/simple.py +273 -0
  126. exonware/xwnode/strategies/utils.py +532 -0
  127. exonware/xwnode/types.py +912 -0
  128. exonware/xwnode/version.py +78 -0
  129. exonware_xwnode-0.0.1.12.dist-info/METADATA +169 -0
  130. exonware_xwnode-0.0.1.12.dist-info/RECORD +132 -0
  131. exonware_xwnode-0.0.1.12.dist-info/WHEEL +4 -0
  132. exonware_xwnode-0.0.1.12.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,460 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ XWNode Facade - Main Public API
4
+
5
+ This module provides the main public API for the xwnode library,
6
+ implementing the facade pattern to hide complexity and provide
7
+ a clean, intuitive interface.
8
+
9
+ Company: eXonware.com
10
+ Author: Eng. Muhammad AlShehri
11
+ Email: connect@exonware.com
12
+ Version: 0.0.1.12
13
+ Generation Date: 07-Sep-2025
14
+ """
15
+
16
+ import logging
17
+ from typing import Any, Dict, List, Optional, Union, Iterator
18
+
19
+ from .base import XWNodeBase
20
+ from .config import get_config, set_config
21
+ from .errors import XWNodeError, XWNodeTypeError, XWNodeValueError
22
+ from .strategies import StrategyManager, get_registry
23
+
24
+ logger = logging.getLogger(__name__)
25
+
26
+
27
+ class XWNode(XWNodeBase):
28
+ """
29
+ Main XWNode class providing a unified interface for all node operations.
30
+
31
+ This class implements the facade pattern, hiding the complexity of the
32
+ underlying strategy system while providing a clean, intuitive API.
33
+ """
34
+
35
+ def __init__(self, data: Any = None, mode: str = 'AUTO', **options):
36
+ """
37
+ Initialize XWNode with data and configuration.
38
+
39
+ Args:
40
+ data: Initial data to store in the node
41
+ mode: Strategy mode ('AUTO', 'HASH_MAP', 'ARRAY_LIST', etc.)
42
+ **options: Additional configuration options
43
+ """
44
+ self._data = data
45
+ self._mode = mode
46
+ self._options = options
47
+ self._strategy_manager = StrategyManager()
48
+ self._setup_strategy()
49
+ # Initialize base class with the created strategy
50
+ super().__init__(self._strategy)
51
+
52
+ def _setup_strategy(self):
53
+ """Setup the appropriate strategy based on mode and data."""
54
+ try:
55
+ # For now, use the create_node_strategy method which handles data properly
56
+ self._strategy = self._strategy_manager.create_node_strategy(self._data or {})
57
+ except Exception as e:
58
+ logger.warning(f"Failed to setup strategy: {e}, using default")
59
+ # Create a simple strategy as fallback
60
+ from .strategies.simple import SimpleNodeStrategy
61
+ self._strategy = SimpleNodeStrategy.create_from_data(self._data or {})
62
+
63
+ # ============================================================================
64
+ # CORE OPERATIONS
65
+ # ============================================================================
66
+
67
+ def put(self, key: Any, value: Any = None) -> None:
68
+ """Store a value with the given key."""
69
+ try:
70
+ self._strategy.insert(key, value)
71
+ except Exception as e:
72
+ raise XWNodeError(f"Failed to put key '{key}': {e}")
73
+
74
+ def get(self, key: Any, default: Any = None) -> Any:
75
+ """Retrieve a value by key."""
76
+ try:
77
+ result = self._strategy.find(key)
78
+ return result if result is not None else default
79
+ except Exception as e:
80
+ raise XWNodeError(f"Failed to get key '{key}': {e}")
81
+
82
+ def has(self, key: Any) -> bool:
83
+ """Check if key exists."""
84
+ try:
85
+ return self._strategy.find(key) is not None
86
+ except Exception as e:
87
+ raise XWNodeError(f"Failed to check key '{key}': {e}")
88
+
89
+ def remove(self, key: Any) -> bool:
90
+ """Remove a key-value pair."""
91
+ try:
92
+ return self._strategy.delete(key)
93
+ except Exception as e:
94
+ raise XWNodeError(f"Failed to remove key '{key}': {e}")
95
+
96
+ def clear(self) -> None:
97
+ """Clear all data."""
98
+ try:
99
+ # Create new strategy instance
100
+ self._setup_strategy()
101
+ except Exception as e:
102
+ raise XWNodeError(f"Failed to clear: {e}")
103
+
104
+ def size(self) -> int:
105
+ """Get the number of items."""
106
+ try:
107
+ return self._strategy.size()
108
+ except Exception as e:
109
+ raise XWNodeError(f"Failed to get size: {e}")
110
+
111
+ def is_empty(self) -> bool:
112
+ """Check if the node is empty."""
113
+ try:
114
+ return self._strategy.is_empty()
115
+ except Exception as e:
116
+ raise XWNodeError(f"Failed to check if empty: {e}")
117
+
118
+ # ============================================================================
119
+ # ITERATION
120
+ # ============================================================================
121
+
122
+ def keys(self) -> Iterator[str]:
123
+ """Get all keys."""
124
+ try:
125
+ # Convert to string keys for consistency
126
+ return (str(key) for key in self._strategy.keys())
127
+ except Exception as e:
128
+ raise XWNodeError(f"Failed to get keys: {e}")
129
+
130
+ def values(self) -> Iterator[Any]:
131
+ """Get all values."""
132
+ try:
133
+ return self._strategy.values()
134
+ except Exception as e:
135
+ raise XWNodeError(f"Failed to get values: {e}")
136
+
137
+ def items(self) -> Iterator[tuple[str, Any]]:
138
+ """Get all key-value pairs."""
139
+ try:
140
+ return ((str(key), value) for key, value in self._strategy.items())
141
+ except Exception as e:
142
+ raise XWNodeError(f"Failed to get items: {e}")
143
+
144
+ def __iter__(self) -> Iterator[str]:
145
+ """Iterate over keys."""
146
+ return self.keys()
147
+
148
+ def __len__(self) -> int:
149
+ """Get the number of items."""
150
+ return self.size()
151
+
152
+ # ============================================================================
153
+ # CONVERSION
154
+ # ============================================================================
155
+
156
+ def to_dict(self) -> Dict[str, Any]:
157
+ """Convert to dictionary."""
158
+ try:
159
+ return dict(self.items())
160
+ except Exception as e:
161
+ raise XWNodeError(f"Failed to convert to dict: {e}")
162
+
163
+ def to_list(self) -> List[Any]:
164
+ """Convert to list."""
165
+ try:
166
+ return list(self.values())
167
+ except Exception as e:
168
+ raise XWNodeError(f"Failed to convert to list: {e}")
169
+
170
+ def to_native(self) -> Any:
171
+ """Convert to native Python object."""
172
+ try:
173
+ return self._strategy.to_native()
174
+ except Exception as e:
175
+ raise XWNodeError(f"Failed to convert to native: {e}")
176
+
177
+ # ============================================================================
178
+ # STRATEGY INFORMATION
179
+ # ============================================================================
180
+
181
+ def get_strategy_info(self) -> Dict[str, Any]:
182
+ """Get information about the current strategy."""
183
+ try:
184
+ return {
185
+ 'mode': self._strategy.get_mode(),
186
+ 'traits': str(self._strategy.get_traits()) if self._strategy.get_traits() else None,
187
+ 'backend_info': getattr(self._strategy, 'backend_info', {}),
188
+ 'metrics': getattr(self._strategy, 'metrics', {})
189
+ }
190
+ except Exception as e:
191
+ raise XWNodeError(f"Failed to get strategy info: {e}")
192
+
193
+ def get_supported_operations(self) -> List[str]:
194
+ """Get list of supported operations."""
195
+ try:
196
+ # Get operations based on strategy type
197
+ operations = ['put', 'get', 'has', 'remove', 'clear', 'size', 'is_empty']
198
+
199
+ # Add strategy-specific operations
200
+ if hasattr(self._strategy, 'push_front'):
201
+ operations.extend(['push_front', 'push_back', 'pop_front', 'pop_back'])
202
+
203
+ if hasattr(self._strategy, 'get_parent'):
204
+ operations.extend(['get_parent', 'get_children', 'traverse'])
205
+
206
+ if hasattr(self._strategy, 'add_edge'):
207
+ operations.extend(['add_edge', 'remove_edge', 'has_edge', 'get_neighbors'])
208
+
209
+ return operations
210
+ except Exception as e:
211
+ raise XWNodeError(f"Failed to get supported operations: {e}")
212
+
213
+ # ============================================================================
214
+ # STRATEGY MIGRATION
215
+ # ============================================================================
216
+
217
+ def migrate_to(self, new_mode: str, **options) -> None:
218
+ """Migrate to a different strategy mode."""
219
+ try:
220
+ # Get current data
221
+ current_data = self.to_native()
222
+
223
+ # Create new strategy
224
+ new_strategy = self._strategy_manager.get_strategy(new_mode, **options)
225
+
226
+ # Migrate data
227
+ if hasattr(new_strategy, 'migrate_from'):
228
+ new_strategy.migrate_from(self._strategy)
229
+ else:
230
+ # Fallback: recreate from data
231
+ for key, value in self.items():
232
+ new_strategy.insert(key, value)
233
+
234
+ # Update strategy
235
+ self._strategy = new_strategy
236
+ self._mode = new_mode
237
+
238
+ except Exception as e:
239
+ raise XWNodeError(f"Failed to migrate to '{new_mode}': {e}")
240
+
241
+ # ============================================================================
242
+ # CONVENIENCE METHODS
243
+ # ============================================================================
244
+
245
+ def __getitem__(self, key: Any) -> Any:
246
+ """Get item using bracket notation."""
247
+ return self.get(key)
248
+
249
+ def __setitem__(self, key: Any, value: Any) -> None:
250
+ """Set item using bracket notation."""
251
+ self.put(key, value)
252
+
253
+ def __delitem__(self, key: Any) -> None:
254
+ """Delete item using bracket notation."""
255
+ if not self.remove(key):
256
+ raise KeyError(key)
257
+
258
+ def __contains__(self, key: Any) -> bool:
259
+ """Check if key exists using 'in' operator."""
260
+ return self.has(key)
261
+
262
+ def __str__(self) -> str:
263
+ """String representation."""
264
+ try:
265
+ return f"XWNode({self.to_dict()})"
266
+ except:
267
+ return f"XWNode(mode={self._mode}, size={self.size()})"
268
+
269
+ def __repr__(self) -> str:
270
+ """Detailed string representation."""
271
+ try:
272
+ return f"XWNode({self.to_dict()}, mode='{self._mode}')"
273
+ except:
274
+ return f"XWNode(mode='{self._mode}', size={self.size()})"
275
+
276
+
277
+ class XWQuery:
278
+ """Query interface for XWNode."""
279
+
280
+ def __init__(self, node: XWNode):
281
+ """Initialize query interface."""
282
+ self._node = node
283
+
284
+ def find(self, pattern: str) -> List[Any]:
285
+ """Find items matching pattern."""
286
+ # TODO: Implement pattern matching
287
+ return []
288
+
289
+ def filter(self, predicate) -> List[Any]:
290
+ """Filter items by predicate."""
291
+ # TODO: Implement filtering
292
+ return []
293
+
294
+
295
+ class XWFactory:
296
+ """Factory for creating XWNode instances."""
297
+
298
+ @staticmethod
299
+ def create(mode: str = 'AUTO', **options) -> XWNode:
300
+ """Create XWNode with specified mode."""
301
+ return XWNode(mode=mode, **options)
302
+
303
+ @staticmethod
304
+ def from_dict(data: Dict[str, Any], mode: str = 'AUTO') -> XWNode:
305
+ """Create XWNode from dictionary."""
306
+ node = XWNode(mode=mode)
307
+ for key, value in data.items():
308
+ node.put(key, value)
309
+ return node
310
+
311
+ @staticmethod
312
+ def from_list(data: List[Any], mode: str = 'ARRAY_LIST') -> XWNode:
313
+ """Create XWNode from list."""
314
+ node = XWNode(mode=mode)
315
+ for i, value in enumerate(data):
316
+ node.put(i, value)
317
+ return node
318
+
319
+
320
+ # A+ Usability Presets
321
+ def create_with_preset(data: Any = None, preset: str = 'DEFAULT') -> XWNode:
322
+ """Create XWNode with A+ usability preset."""
323
+ from .types import get_preset
324
+
325
+ try:
326
+ preset_config = get_preset(preset)
327
+ # For now, create with basic configuration
328
+ # TODO: Integrate with StrategyManager for full preset support
329
+ return XWNode(data)
330
+ except ValueError as e:
331
+ logger.warning(f"Unknown preset '{preset}', using DEFAULT: {e}")
332
+ return XWNode(data)
333
+
334
+ def list_available_presets() -> List[str]:
335
+ """List all available A+ usability presets."""
336
+ from .types import list_presets
337
+ return list_presets()
338
+
339
+ # Performance Mode Factory Methods
340
+ def fast(data: Any = None) -> XWNode:
341
+ """Create XWNode optimized for speed."""
342
+ return XWNode(data, mode='HASH_MAP')
343
+
344
+ def optimized(data: Any = None) -> XWNode:
345
+ """Create XWNode optimized for memory."""
346
+ return XWNode(data, mode='ARRAY_LIST')
347
+
348
+ def adaptive(data: Any = None) -> XWNode:
349
+ """Create XWNode with adaptive strategy selection."""
350
+ return XWNode(data, mode='AUTO')
351
+
352
+ def dual_adaptive(data: Any = None) -> XWNode:
353
+ """Create XWNode with dual adaptive strategy."""
354
+ return XWNode(data, mode='AUTO', adaptive=True)
355
+
356
+
357
+ class XWEdge:
358
+ """
359
+ XWEdge class for managing edges between nodes.
360
+
361
+ This class provides a simple interface for creating and managing
362
+ edges between XWNode instances with support for different edge types.
363
+ """
364
+
365
+ def __init__(self, source: str, target: str, edge_type: str = "default",
366
+ weight: float = 1.0, properties: Optional[Dict[str, Any]] = None,
367
+ is_bidirectional: bool = False, edge_id: Optional[str] = None):
368
+ """
369
+ Initialize an edge between source and target nodes.
370
+
371
+ Args:
372
+ source: Source node identifier
373
+ target: Target node identifier
374
+ edge_type: Type of edge (default, directed, weighted, etc.)
375
+ weight: Edge weight (default: 1.0)
376
+ properties: Additional edge properties
377
+ is_bidirectional: Whether the edge is bidirectional
378
+ edge_id: Optional unique edge identifier
379
+ """
380
+ self.source = source
381
+ self.target = target
382
+ self.edge_type = edge_type
383
+ self.weight = weight
384
+ self.properties = properties or {}
385
+ self.is_bidirectional = is_bidirectional
386
+ self.edge_id = edge_id or f"{source}->{target}"
387
+
388
+ def to_dict(self) -> Dict[str, Any]:
389
+ """Convert edge to dictionary representation."""
390
+ return {
391
+ 'source': self.source,
392
+ 'target': self.target,
393
+ 'edge_type': self.edge_type,
394
+ 'weight': self.weight,
395
+ 'properties': self.properties,
396
+ 'is_bidirectional': self.is_bidirectional,
397
+ 'edge_id': self.edge_id
398
+ }
399
+
400
+ @classmethod
401
+ def from_dict(cls, data: Dict[str, Any]) -> 'XWEdge':
402
+ """Create edge from dictionary representation."""
403
+ return cls(
404
+ source=data['source'],
405
+ target=data['target'],
406
+ edge_type=data.get('edge_type', 'default'),
407
+ weight=data.get('weight', 1.0),
408
+ properties=data.get('properties', {}),
409
+ is_bidirectional=data.get('is_bidirectional', False),
410
+ edge_id=data.get('edge_id')
411
+ )
412
+
413
+ def __repr__(self) -> str:
414
+ direction = "<->" if self.is_bidirectional else "->"
415
+ return f"XWEdge({self.source}{direction}{self.target}, type={self.edge_type}, weight={self.weight})"
416
+
417
+ def __eq__(self, other) -> bool:
418
+ if not isinstance(other, XWEdge):
419
+ return False
420
+ return (self.source == other.source and
421
+ self.target == other.target and
422
+ self.edge_type == other.edge_type)
423
+
424
+
425
+ # Convenience functions
426
+ def create_node(data: Any = None) -> XWNode:
427
+ """Create a new XWNode instance."""
428
+ return XWNode(data)
429
+
430
+ def from_dict(data: Dict[str, Any]) -> XWNode:
431
+ """Create XWNode from dictionary."""
432
+ return XWFactory.from_dict(data)
433
+
434
+ def from_list(data: List[Any]) -> XWNode:
435
+ """Create XWNode from list."""
436
+ return XWFactory.from_list(data)
437
+
438
+ def empty_node() -> XWNode:
439
+ """Create an empty XWNode."""
440
+ return XWNode()
441
+
442
+ # Export main classes
443
+ __all__ = [
444
+ 'XWNode',
445
+ 'XWEdge',
446
+ 'XWQuery',
447
+ 'XWFactory',
448
+ 'create_node',
449
+ 'from_dict',
450
+ 'from_list',
451
+ 'empty_node',
452
+ # A+ Usability Presets
453
+ 'create_with_preset',
454
+ 'list_available_presets',
455
+ # Performance Modes
456
+ 'fast',
457
+ 'optimized',
458
+ 'adaptive',
459
+ 'dual_adaptive'
460
+ ]
@@ -0,0 +1,158 @@
1
+ """
2
+ Enhanced Strategy System for XWNode
3
+
4
+ This package implements the enhanced strategy system with xwsystem-inspired optimizations:
5
+ - 28 Node Modes (comprehensive data structure coverage)
6
+ - 16 Edge Modes (complete graph support)
7
+ - 12 Traits (cross-cutting capabilities)
8
+ - Flyweight pattern for memory optimization
9
+ - Intelligent pattern detection for AUTO mode selection
10
+ - Performance monitoring and optimization recommendations
11
+ - Comprehensive metrics and statistics tracking
12
+ - Lazy materialization and strategy management
13
+ - 100% backward compatibility with existing XWNode
14
+
15
+ Company: eXonware.com
16
+ Author: Eng. Muhammad AlShehri
17
+ Email: connect@exonware.com
18
+ Version: 0.0.1.12
19
+ Generation Date: 07-Sep-2025
20
+ """
21
+
22
+ from ..types import (
23
+ NodeMode, EdgeMode, QueryMode, NodeTrait, EdgeTrait, QueryTrait,
24
+ AUTO, LEGACY, HASH_MAP, ORDERED_MAP, ORDERED_MAP_BALANCED,
25
+ ARRAY_LIST, LINKED_LIST, TRIE, RADIX_TRIE, PATRICIA,
26
+ HEAP, SET_HASH, SET_TREE, BLOOM_FILTER, CUCKOO_HASH,
27
+ BITMAP, BITSET_DYNAMIC, ROARING_BITMAP, B_TREE, B_PLUS_TREE,
28
+ LSM_TREE, PERSISTENT_TREE, COW_TREE, UNION_FIND, SEGMENT_TREE, FENWICK_TREE,
29
+ SUFFIX_ARRAY, AHO_CORASICK, COUNT_MIN_SKETCH, HYPERLOGLOG,
30
+ ADJ_LIST, DYNAMIC_ADJ_LIST, ADJ_MATRIX, BLOCK_ADJ_MATRIX,
31
+ CSR, CSC, COO, BIDIR_WRAPPER, TEMPORAL_EDGESET,
32
+ HYPEREDGE_SET, EDGE_PROPERTY_STORE, R_TREE, QUADTREE, OCTREE,
33
+ SQL, HIVEQL, PIG, CQL, N1QL, EQL, KQL, FLUX, DATALOG,
34
+ GRAPHQL, SPARQL, GREMLIN, CYPHER,
35
+ LINQ, JSONIQ, JMESPATH, XQUERY, XPATH,
36
+ XML_QUERY, JSON_QUERY
37
+ )
38
+
39
+ # Node strategies
40
+ from .nodes.base import ANodeStrategy, ANodeLinearStrategy, ANodeTreeStrategy, ANodeGraphStrategy, ANodeMatrixStrategy
41
+ from .nodes.array_list import ArrayListStrategy
42
+ from .nodes.linked_list import LinkedListStrategy
43
+ from .nodes.stack import StackStrategy
44
+ from .nodes.queue import QueueStrategy
45
+ from .nodes.priority_queue import PriorityQueueStrategy
46
+ from .nodes.deque import DequeStrategy
47
+ from .nodes.trie import xTrieStrategy
48
+ from .nodes.heap import xHeapStrategy
49
+ from .nodes.aho_corasick import xAhoCorasickStrategy
50
+ from .nodes.hash_map import HashMapStrategy
51
+ from .nodes.union_find import xUnionFindStrategy
52
+ from .nodes.adjacency_list import AdjacencyListStrategy
53
+ from .nodes.sparse_matrix import SparseMatrixStrategy
54
+
55
+ # Edge strategies
56
+ from .edges.base import AEdgeStrategy, ALinearEdgeStrategy, ATreeEdgeStrategy, AGraphEdgeStrategy
57
+ from .edges.adj_list import AdjListStrategy
58
+ from .edges.adj_matrix import AdjMatrixStrategy
59
+
60
+ # Query strategies
61
+ from .queries.base import AQueryStrategy, AStructuredQueryStrategy, AGraphQueryStrategy, ADocumentQueryStrategy
62
+ from .queries.xwquery_strategy import XWQueryScriptStrategy
63
+ from .queries.xwnode_executor import XWNodeQueryActionExecutor
64
+ from .queries.sql import SQLStrategy
65
+ from .queries.hiveql import HiveQLStrategy
66
+ from .queries.pig import PigStrategy
67
+ from .queries.cql import CQLStrategy
68
+ from .queries.n1ql import N1QLStrategy
69
+ from .queries.kql import KQLStrategy
70
+ from .queries.datalog import DatalogStrategy
71
+ from .queries.mql import MQLStrategy
72
+ from .queries.partiql import PartiQLStrategy
73
+ from .queries.elastic_dsl import ElasticDSLStrategy
74
+ from .queries.eql import EQLStrategy
75
+ from .queries.flux import FluxStrategy
76
+ from .queries.promql import PromQLStrategy
77
+ from .queries.graphql import GraphQLStrategy
78
+ from .queries.sparql import SPARQLStrategy
79
+ from .queries.gremlin import GremlinStrategy
80
+ from .queries.cypher import CypherStrategy
81
+ from .queries.gql import GQLStrategy
82
+ from .queries.linq import LINQStrategy
83
+ from .queries.hql import HQLStrategy
84
+ from .queries.jsoniq import JSONiqStrategy
85
+ from .queries.jmespath import JMESPathStrategy
86
+ from .queries.jq import JQStrategy
87
+ from .queries.xquery import XQueryStrategy
88
+ from .queries.xpath import XPathStrategy
89
+ from .queries.logql import LogQLStrategy
90
+ from .queries.xml_query import XMLQueryStrategy
91
+ from .queries.json_query import JSONQueryStrategy
92
+
93
+ from .registry import StrategyRegistry, get_registry, register_node_strategy, register_edge_strategy
94
+ from .advisor import StrategyAdvisor, get_advisor
95
+ from .manager import StrategyManager
96
+
97
+ # Enhanced components
98
+ from .flyweight import StrategyFlyweight, get_flyweight, get_flyweight_stats, clear_flyweight_cache
99
+ from .pattern_detector import DataPatternDetector, get_detector, analyze_data_patterns, recommend_strategy
100
+ from .performance_monitor import StrategyPerformanceMonitor, get_monitor, record_operation, get_performance_summary
101
+ from .metrics import StrategyMetricsCollector, get_metrics_collector, collect_comprehensive_metrics, get_metrics_summary
102
+
103
+ __all__ = [
104
+ # Types and enums
105
+ 'NodeMode', 'EdgeMode', 'QueryMode', 'NodeTrait', 'EdgeTrait', 'QueryTrait',
106
+ 'AUTO', 'LEGACY', 'HASH_MAP', 'ORDERED_MAP', 'ORDERED_MAP_BALANCED',
107
+ 'ARRAY_LIST', 'LINKED_LIST', 'TRIE', 'RADIX_TRIE', 'PATRICIA',
108
+ 'HEAP', 'SET_HASH', 'SET_TREE', 'BLOOM_FILTER', 'CUCKOO_HASH',
109
+ 'BITMAP', 'BITSET_DYNAMIC', 'ROARING_BITMAP', 'B_TREE', 'B_PLUS_TREE',
110
+ 'LSM_TREE', 'PERSISTENT_TREE', 'COW_TREE', 'UNION_FIND', 'SEGMENT_TREE', 'FENWICK_TREE',
111
+ 'SUFFIX_ARRAY', 'AHO_CORASICK', 'COUNT_MIN_SKETCH', 'HYPERLOGLOG',
112
+ 'ADJ_LIST', 'DYNAMIC_ADJ_LIST', 'ADJ_MATRIX', 'BLOCK_ADJ_MATRIX',
113
+ 'CSR', 'CSC', 'COO', 'BIDIR_WRAPPER', 'TEMPORAL_EDGESET',
114
+ 'HYPEREDGE_SET', 'EDGE_PROPERTY_STORE', 'R_TREE', 'QUADTREE', 'OCTREE',
115
+ 'SQL', 'HIVEQL', 'PIG', 'CQL', 'N1QL', 'EQL', 'KQL', 'FLUX', 'DATALOG',
116
+ 'GRAPHQL', 'SPARQL', 'GREMLIN', 'CYPHER',
117
+ 'LINQ', 'JSONIQ', 'JMESPATH', 'XQUERY', 'XPATH',
118
+ 'XML_QUERY', 'JSON_QUERY',
119
+
120
+ # Node strategy base classes
121
+ 'ANodeStrategy', 'ANodeLinearStrategy', 'ANodeTreeStrategy', 'ANodeGraphStrategy', 'ANodeMatrixStrategy',
122
+
123
+ # Node strategy implementations
124
+ 'ArrayListStrategy', 'LinkedListStrategy', 'StackStrategy', 'QueueStrategy',
125
+ 'PriorityQueueStrategy', 'DequeStrategy', 'TrieStrategy', 'HeapStrategy',
126
+ 'AhoCorasickStrategy', 'HashMapStrategy', 'UnionFindStrategy',
127
+ 'AdjacencyListStrategy', 'SparseMatrixStrategy',
128
+
129
+ # Edge strategy base classes
130
+ 'AEdgeStrategy', 'ALinearEdgeStrategy', 'ATreeEdgeStrategy', 'AGraphEdgeStrategy',
131
+
132
+ # Edge strategy implementations
133
+ 'AdjListStrategy', 'AdjMatrixStrategy',
134
+
135
+ # Query strategy base classes
136
+ 'AQueryStrategy', 'AStructuredQueryStrategy', 'AGraphQueryStrategy', 'ADocumentQueryStrategy',
137
+
138
+ # Query strategy implementations
139
+ 'XWQueryScriptStrategy', 'XWNodeQueryActionExecutor',
140
+ 'SQLStrategy', 'HiveQLStrategy', 'PigStrategy', 'CQLStrategy', 'N1QLStrategy',
141
+ 'KQLStrategy', 'DatalogStrategy', 'MQLStrategy', 'PartiQLStrategy',
142
+ 'ElasticDSLStrategy', 'EQLStrategy', 'FluxStrategy', 'PromQLStrategy',
143
+ 'GraphQLStrategy', 'SPARQLStrategy', 'GremlinStrategy', 'CypherStrategy', 'GQLStrategy',
144
+ 'LINQStrategy', 'HQLStrategy', 'JSONiqStrategy', 'JMESPathStrategy', 'JQStrategy',
145
+ 'XQueryStrategy', 'XPathStrategy', 'LogQLStrategy',
146
+ 'XMLQueryStrategy', 'JSONQueryStrategy',
147
+
148
+ # Strategy management
149
+ 'StrategyRegistry', 'get_registry', 'register_node_strategy', 'register_edge_strategy',
150
+ 'StrategyAdvisor', 'get_advisor',
151
+ 'StrategyManager',
152
+
153
+ # Enhanced components
154
+ 'StrategyFlyweight', 'get_flyweight', 'get_flyweight_stats', 'clear_flyweight_cache',
155
+ 'DataPatternDetector', 'get_detector', 'analyze_data_patterns', 'recommend_strategy',
156
+ 'StrategyPerformanceMonitor', 'get_monitor', 'record_operation', 'get_performance_summary',
157
+ 'StrategyMetricsCollector', 'get_metrics_collector', 'collect_comprehensive_metrics', 'get_metrics_summary'
158
+ ]