interstellar 0.2.0

A high-performance graph database with Gremlin-style traversals and GQL query language
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
//! Streaming executor for true O(1) lazy evaluation.
//!
//! This module provides [`StreamingExecutor`] and [`StreamingAdapter`] which enable
//! true pull-based streaming execution where traversers flow through the pipeline
//! one at a time, without eager collection.
//!
//! # Architecture
//!
//! ```text
//! StreamingExecutor
//!     |
//!     +-- holds SideEffects (Arc internally)
//!     +-- owns Box<dyn Iterator + 'static>
//!             |
//!             v
//!         StreamingAdapter [step N]
//!             +-- owns cloned step
//!             +-- owns StreamingContext (Arc refs)
//!             +-- owns input iterator
//!             +-- owns Option<current output iterator>
//!             |
//!             v
//!         StreamingAdapter [step N-1]
//!             ...
//!             |
//!             v
//!         Source Iterator ('static, owns data)
//! ```
//!
//! # Memory Model
//!
//! - **Per step**: O(1) memory overhead
//! - **Total**: O(steps + max_degree) constant regardless of result set size
//! - **Early termination**: `iter().take(n)` processes exactly n items per step
//!
//! # Example
//!
//! ```ignore
//! // Lazy streaming - only processes items as needed
//! let first = g.v().out().out().iter().next();
//!
//! // Early termination - stops after 10 items
//! let sample: Vec<_> = g.v().out("knows").iter().take(10).collect();
//! ```

use std::sync::Arc;

use crate::storage::interner::StringInterner;
use crate::storage::{GraphStorage, StreamableStorage};
use crate::traversal::context::{SideEffects, StreamingContext};
use crate::traversal::step::DynStep;
use crate::traversal::traverser::{TraversalSource, Traverser};
use crate::value::Value;

// =============================================================================
// StreamingAdapter - Iterator adapter that chains steps
// =============================================================================

/// Iterator adapter that streams one step's outputs lazily.
///
/// Each `StreamingAdapter` wraps a single step and an input iterator.
/// It pulls one traverser at a time from the input, applies the step's
/// `apply_streaming` method, and yields results from the resulting iterator.
///
/// When the current output iterator is exhausted, it pulls the next input
/// traverser and creates a new output iterator.
pub struct StreamingAdapter {
    /// Owned step (boxed for dynamic dispatch)
    step: Box<dyn DynStep>,
    /// Streaming context (cheaply cloneable via Arc)
    ctx: StreamingContext,
    /// Input iterator (previous adapter or source)
    input: Box<dyn Iterator<Item = Traverser> + Send>,
    /// Current output iterator from one input traverser
    current: Option<Box<dyn Iterator<Item = Traverser> + Send>>,
}

impl StreamingAdapter {
    /// Create a new streaming adapter.
    ///
    /// # Arguments
    ///
    /// * `step` - The step to apply to each traverser
    /// * `ctx` - The streaming context (Arc-wrapped storage/interner)
    /// * `input` - The input iterator (previous adapter or source)
    pub fn new(
        step: Box<dyn DynStep>,
        ctx: StreamingContext,
        input: Box<dyn Iterator<Item = Traverser> + Send>,
    ) -> Self {
        Self {
            step,
            ctx,
            input,
            current: None,
        }
    }
}

impl Iterator for StreamingAdapter {
    type Item = Traverser;

    fn next(&mut self) -> Option<Self::Item> {
        loop {
            // 1. Yield from current output iterator
            if let Some(ref mut current) = self.current {
                if let Some(t) = current.next() {
                    return Some(t);
                }
                // Current iterator exhausted
                self.current = None;
            }

            // 2. Pull next input traverser
            let input = self.input.next()?;

            // 3. Apply step to get new output iterator
            self.current = Some(self.step.apply_streaming(self.ctx.clone(), input));
        }
    }
}

// StreamingAdapter is Send because all fields are Send:
// - step: Box<dyn DynStep> where DynStep: Send
// - ctx: StreamingContext is Clone + Send
// - input: Box<dyn Iterator + Send>
// - current: Option<Box<dyn Iterator + Send>>
unsafe impl Send for StreamingAdapter {}

// =============================================================================
// StreamingExecutor - Builds and executes the streaming pipeline
// =============================================================================

/// Executor that streams results with O(1) memory per step.
///
/// The `StreamingExecutor` builds a chain of `StreamingAdapter`s from the
/// traversal steps and source, then provides an iterator interface over
/// the results.
///
/// # Side Effects
///
/// Side effects (from `store()`, `aggregate()`, etc.) are accumulated
/// during iteration and can be accessed via `side_effects()`.
///
/// # Example
///
/// ```ignore
/// let executor = StreamingExecutor::new(
///     storage,
///     interner,
///     steps,
///     Some(TraversalSource::AllVertices),
///     false,
/// );
///
/// for traverser in executor {
///     println!("{:?}", traverser.value);
/// }
/// ```
pub struct StreamingExecutor {
    /// The streaming iterator pipeline
    iter: Box<dyn Iterator<Item = Traverser> + Send>,
    /// Side effects accumulated during traversal
    side_effects: SideEffects,
}

impl StreamingExecutor {
    /// Create a new streaming executor.
    ///
    /// This is the primary constructor for streaming execution. It uses
    /// `StreamableStorage` methods for both source iteration and navigation
    /// steps, providing true O(1) streaming throughout the pipeline.
    ///
    /// # Arguments
    ///
    /// * `storage` - Arc-wrapped streamable storage
    /// * `interner` - Arc-wrapped string interner
    /// * `steps` - The traversal steps to execute
    /// * `source` - The source of traversers (vertices, edges, or injected values)
    /// * `track_paths` - Whether to track traversal paths
    pub fn new(
        storage: Arc<dyn StreamableStorage>,
        interner: Arc<StringInterner>,
        steps: Vec<Box<dyn DynStep>>,
        source: Option<TraversalSource>,
        track_paths: bool,
    ) -> Self {
        let side_effects = SideEffects::new();
        let ctx = StreamingContext::new(storage.clone(), interner.clone())
            .with_side_effects(side_effects.clone())
            .with_path_tracking(track_paths);

        // Build source iterator using streaming methods for true O(1)
        let source_iter = Self::build_streaming_source(storage, source, track_paths);

        // Chain adapters - fold steps into a pipeline
        let iter = steps.into_iter().fold(
            source_iter,
            |input, step| -> Box<dyn Iterator<Item = Traverser> + Send> {
                Box::new(StreamingAdapter::new(step, ctx.clone(), input))
            },
        );

        Self { iter, side_effects }
    }

    /// Alias for `new()` - provided for backwards compatibility.
    ///
    /// Since `new()` now always uses `StreamableStorage`, this method is
    /// identical to `new()`.
    #[inline]
    pub fn new_streaming(
        storage: Arc<dyn StreamableStorage>,
        interner: Arc<StringInterner>,
        steps: Vec<Box<dyn DynStep>>,
        source: Option<TraversalSource>,
        track_paths: bool,
    ) -> Self {
        Self::new(storage, interner, steps, source, track_paths)
    }

    /// Build the source iterator using StreamableStorage for true O(1) streaming.
    ///
    /// Uses `StreamableStorage::stream_*` methods which return owned iterators
    /// without collecting upfront.
    fn build_streaming_source(
        storage: Arc<dyn StreamableStorage>,
        source: Option<TraversalSource>,
        track_paths: bool,
    ) -> Box<dyn Iterator<Item = Traverser> + Send> {
        match source {
            Some(TraversalSource::AllVertices) => {
                // True streaming - no upfront collection
                Box::new(storage.stream_all_vertices().map(move |id| {
                    let mut t = Traverser::new(Value::Vertex(id));
                    if track_paths {
                        t.extend_path_unlabeled();
                    }
                    t
                }))
            }
            Some(TraversalSource::Vertices(ids)) => {
                let storage_clone = storage.clone();
                Box::new(ids.into_iter().filter_map(move |id| {
                    // Verify vertex exists
                    storage_clone.get_vertex(id).map(|_| {
                        let mut t = Traverser::new(Value::Vertex(id));
                        if track_paths {
                            t.extend_path_unlabeled();
                        }
                        t
                    })
                }))
            }
            Some(TraversalSource::AllEdges) => {
                // True streaming - no upfront collection
                Box::new(storage.stream_all_edges().map(move |id| {
                    let mut t = Traverser::new(Value::Edge(id));
                    if track_paths {
                        t.extend_path_unlabeled();
                    }
                    t
                }))
            }
            Some(TraversalSource::Edges(ids)) => {
                let storage_clone = storage.clone();
                Box::new(ids.into_iter().filter_map(move |id| {
                    // Verify edge exists
                    storage_clone.get_edge(id).map(|_| {
                        let mut t = Traverser::new(Value::Edge(id));
                        if track_paths {
                            t.extend_path_unlabeled();
                        }
                        t
                    })
                }))
            }
            Some(TraversalSource::Inject(values)) => Box::new(values.into_iter().map(move |v| {
                let mut t = Traverser::new(v);
                if track_paths {
                    t.extend_path_unlabeled();
                }
                t
            })),
            #[cfg(feature = "full-text")]
            Some(TraversalSource::VerticesWithTextScore(hits)) => {
                let storage_clone = storage.clone();
                Box::new(hits.into_iter().filter_map(move |(id, score)| {
                    storage_clone.get_vertex(id).map(|_| {
                        let mut t = Traverser::new(Value::Vertex(id));
                        t.set_sack(score);
                        if track_paths {
                            t.extend_path_unlabeled();
                        }
                        t
                    })
                }))
            }
            #[cfg(feature = "full-text")]
            Some(TraversalSource::EdgesWithTextScore(hits)) => {
                let storage_clone = storage.clone();
                Box::new(hits.into_iter().filter_map(move |(id, score)| {
                    storage_clone.get_edge(id).map(|_| {
                        let mut t = Traverser::new(Value::Edge(id));
                        t.set_sack(score);
                        if track_paths {
                            t.extend_path_unlabeled();
                        }
                        t
                    })
                }))
            }
            None => Box::new(std::iter::empty()),
        }
    }

    /// Get a reference to the side effects store.
    ///
    /// Side effects are populated as traversers flow through the pipeline,
    /// so this should typically be called after iteration is complete.
    #[inline]
    pub fn side_effects(&self) -> &SideEffects {
        &self.side_effects
    }

    /// Consume the executor and return the side effects.
    ///
    /// Note: The iterator must be fully consumed before calling this
    /// to ensure all side effects are captured.
    pub fn into_side_effects(self) -> SideEffects {
        self.side_effects
    }
}

impl Iterator for StreamingExecutor {
    type Item = Traverser;

    #[inline]
    fn next(&mut self) -> Option<Self::Item> {
        self.iter.next()
    }

    fn size_hint(&self) -> (usize, Option<usize>) {
        self.iter.size_hint()
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::storage::Graph;
    use crate::value::Value;
    use crate::VertexId;
    use std::collections::HashMap;

    fn create_test_graph() -> Graph {
        let graph = Graph::new();

        // Add vertices
        let alice = graph.add_vertex("person", {
            let mut props = HashMap::new();
            props.insert("name".to_string(), Value::String("Alice".to_string()));
            props.insert("age".to_string(), Value::Int(30));
            props
        });

        let bob = graph.add_vertex("person", {
            let mut props = HashMap::new();
            props.insert("name".to_string(), Value::String("Bob".to_string()));
            props.insert("age".to_string(), Value::Int(25));
            props
        });

        let charlie = graph.add_vertex("person", {
            let mut props = HashMap::new();
            props.insert("name".to_string(), Value::String("Charlie".to_string()));
            props.insert("age".to_string(), Value::Int(35));
            props
        });

        let software = graph.add_vertex("software", {
            let mut props = HashMap::new();
            props.insert("name".to_string(), Value::String("GraphDB".to_string()));
            props
        });

        // Add edges
        graph.add_edge(alice, bob, "knows", HashMap::new()).unwrap();
        graph
            .add_edge(alice, charlie, "knows", HashMap::new())
            .unwrap();
        graph
            .add_edge(bob, charlie, "knows", HashMap::new())
            .unwrap();
        graph
            .add_edge(alice, software, "created", HashMap::new())
            .unwrap();

        graph
    }

    #[test]
    fn streaming_executor_empty_source() {
        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        let executor = StreamingExecutor::new(
            snapshot.arc_streamable(),
            snapshot.arc_interner(),
            vec![],
            None,
            false,
        );

        let results: Vec<_> = executor.collect();
        assert!(results.is_empty());
    }

    #[test]
    fn streaming_executor_all_vertices() {
        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        let executor = StreamingExecutor::new(
            snapshot.arc_streamable(),
            snapshot.arc_interner(),
            vec![],
            Some(TraversalSource::AllVertices),
            false,
        );

        let results: Vec<_> = executor.collect();
        assert_eq!(results.len(), 4); // 3 people + 1 software
    }

    #[test]
    fn streaming_executor_specific_vertices() {
        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        let executor = StreamingExecutor::new(
            snapshot.arc_streamable(),
            snapshot.arc_interner(),
            vec![],
            Some(TraversalSource::Vertices(vec![VertexId(0), VertexId(1)])),
            false,
        );

        let results: Vec<_> = executor.collect();
        assert_eq!(results.len(), 2);
    }

    #[test]
    fn streaming_executor_inject() {
        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        let executor = StreamingExecutor::new(
            snapshot.arc_streamable(),
            snapshot.arc_interner(),
            vec![],
            Some(TraversalSource::Inject(vec![
                Value::Int(1),
                Value::Int(2),
                Value::Int(3),
            ])),
            false,
        );

        let results: Vec<_> = executor.collect();
        assert_eq!(results.len(), 3);
        assert_eq!(results[0].value, Value::Int(1));
        assert_eq!(results[1].value, Value::Int(2));
        assert_eq!(results[2].value, Value::Int(3));
    }

    #[test]
    fn streaming_executor_early_termination() {
        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        let mut executor = StreamingExecutor::new(
            snapshot.arc_streamable(),
            snapshot.arc_interner(),
            vec![],
            Some(TraversalSource::AllVertices),
            false,
        );

        // Take only 2 items
        let first = executor.next();
        let second = executor.next();

        assert!(first.is_some());
        assert!(second.is_some());
        // We didn't consume all items - this tests early termination works
    }

    #[test]
    fn streaming_executor_path_tracking() {
        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        let executor = StreamingExecutor::new(
            snapshot.arc_streamable(),
            snapshot.arc_interner(),
            vec![],
            Some(TraversalSource::AllVertices),
            true, // Enable path tracking
        );

        let results: Vec<_> = executor.collect();
        // With path tracking, each traverser should have a path entry
        for t in results {
            assert_eq!(t.path.len(), 1);
        }
    }

    #[test]
    fn streaming_adapter_identity() {
        use crate::traversal::step::IdentityStep;

        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        let ctx = StreamingContext::new(snapshot.arc_streamable(), snapshot.arc_interner());

        let source: Box<dyn Iterator<Item = Traverser> + Send> = Box::new(
            vec![Traverser::new(Value::Int(1)), Traverser::new(Value::Int(2))].into_iter(),
        );

        let step: Box<dyn DynStep> = Box::new(IdentityStep);
        let adapter = StreamingAdapter::new(step, ctx, source);

        let results: Vec<_> = adapter.collect();
        assert_eq!(results.len(), 2);
        assert_eq!(results[0].value, Value::Int(1));
        assert_eq!(results[1].value, Value::Int(2));
    }

    #[test]
    fn streaming_executor_side_effects() {
        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        let executor = StreamingExecutor::new(
            snapshot.arc_streamable(),
            snapshot.arc_interner(),
            vec![],
            Some(TraversalSource::Inject(vec![Value::Int(42)])),
            false,
        );

        // Side effects should be accessible
        let se = executor.side_effects();
        assert!(se.keys().is_empty());
    }

    // =========================================================================
    // True O(1) streaming tests
    // =========================================================================

    #[test]
    fn streaming_executor_true_streaming_all_vertices() {
        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        let executor = StreamingExecutor::new_streaming(
            snapshot.arc_streamable(),
            snapshot.arc_interner(),
            vec![],
            Some(TraversalSource::AllVertices),
            false,
        );

        let results: Vec<_> = executor.collect();
        assert_eq!(results.len(), 4); // 3 people + 1 software
    }

    #[test]
    fn streaming_executor_new_streaming_all_edges() {
        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        let executor = StreamingExecutor::new_streaming(
            snapshot.arc_streamable(),
            snapshot.arc_interner(),
            vec![],
            Some(TraversalSource::AllEdges),
            false,
        );

        let results: Vec<_> = executor.collect();
        assert_eq!(results.len(), 4); // 4 edges
    }

    #[test]
    fn streaming_executor_new_streaming_specific_vertices() {
        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        let executor = StreamingExecutor::new_streaming(
            snapshot.arc_streamable(),
            snapshot.arc_interner(),
            vec![],
            Some(TraversalSource::Vertices(vec![VertexId(0), VertexId(1)])),
            false,
        );

        let results: Vec<_> = executor.collect();
        assert_eq!(results.len(), 2);
    }

    #[test]
    fn streaming_executor_new_streaming_inject() {
        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        let executor = StreamingExecutor::new_streaming(
            snapshot.arc_streamable(),
            snapshot.arc_interner(),
            vec![],
            Some(TraversalSource::Inject(vec![
                Value::Int(1),
                Value::Int(2),
                Value::Int(3),
            ])),
            false,
        );

        let results: Vec<_> = executor.collect();
        assert_eq!(results.len(), 3);
        assert_eq!(results[0].value, Value::Int(1));
        assert_eq!(results[1].value, Value::Int(2));
        assert_eq!(results[2].value, Value::Int(3));
    }

    #[test]
    fn streaming_executor_new_streaming_early_termination() {
        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        let mut executor = StreamingExecutor::new_streaming(
            snapshot.arc_streamable(),
            snapshot.arc_interner(),
            vec![],
            Some(TraversalSource::AllVertices),
            false,
        );

        // Take only 2 items - with true streaming this shouldn't process all vertices
        let first = executor.next();
        let second = executor.next();

        assert!(first.is_some());
        assert!(second.is_some());
    }

    #[test]
    fn streaming_executor_new_streaming_path_tracking() {
        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        let executor = StreamingExecutor::new_streaming(
            snapshot.arc_streamable(),
            snapshot.arc_interner(),
            vec![],
            Some(TraversalSource::AllVertices),
            true, // Enable path tracking
        );

        let results: Vec<_> = executor.collect();
        for t in results {
            assert_eq!(t.path.len(), 1);
        }
    }

    #[test]
    fn arc_streamable_returns_correct_counts() {
        use crate::storage::StreamableStorage;

        let graph = create_test_graph();
        let snapshot = graph.snapshot();
        let streamable = snapshot.arc_streamable();

        // Test stream_all_vertices
        let vertex_count = streamable.stream_all_vertices().count();
        assert_eq!(vertex_count, 4);

        // Test stream_all_edges
        let edge_count = streamable.stream_all_edges().count();
        assert_eq!(edge_count, 4);
    }

    #[test]
    fn streamable_storage_trait_object_works() {
        use crate::storage::StreamableStorage;

        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        // Get Arc<dyn StreamableStorage>
        let streamable: std::sync::Arc<dyn StreamableStorage> = snapshot.arc_streamable();

        // Should be able to call methods through trait object
        let vertices: Vec<_> = streamable.stream_all_vertices().collect();
        assert_eq!(vertices.len(), 4);

        // GraphStorage methods should also work via supertrait
        assert_eq!(streamable.vertex_count(), 4);
        assert_eq!(streamable.edge_count(), 4);
    }

    #[test]
    fn streamable_storage_stream_vertices_with_label() {
        use crate::storage::StreamableStorage;

        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        // Test stream_vertices_with_label
        let people: Vec<_> = snapshot.stream_vertices_with_label("person").collect();
        assert_eq!(people.len(), 3);

        let software: Vec<_> = snapshot.stream_vertices_with_label("software").collect();
        assert_eq!(software.len(), 1);

        let unknown: Vec<_> = snapshot.stream_vertices_with_label("unknown").collect();
        assert_eq!(unknown.len(), 0);
    }

    #[test]
    fn streamable_storage_stream_edges_with_label() {
        use crate::storage::StreamableStorage;

        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        // Test stream_edges_with_label
        let knows: Vec<_> = snapshot.stream_edges_with_label("knows").collect();
        assert_eq!(knows.len(), 3);

        let created: Vec<_> = snapshot.stream_edges_with_label("created").collect();
        assert_eq!(created.len(), 1);

        let unknown: Vec<_> = snapshot.stream_edges_with_label("unknown").collect();
        assert_eq!(unknown.len(), 0);
    }

    #[test]
    fn streamable_storage_stream_neighbors() {
        use crate::storage::StreamableStorage;

        let graph = create_test_graph();
        let snapshot = graph.snapshot();

        // Alice (VertexId(0)) has outgoing edges to bob, charlie, software
        let alice_out: Vec<_> = snapshot.stream_out_neighbors(VertexId(0), &[]).collect();
        assert_eq!(alice_out.len(), 3);

        // Alice has no incoming edges
        let alice_in: Vec<_> = snapshot.stream_in_neighbors(VertexId(0), &[]).collect();
        assert_eq!(alice_in.len(), 0);

        // Charlie (VertexId(2)) has incoming edges from alice and bob
        let charlie_in: Vec<_> = snapshot.stream_in_neighbors(VertexId(2), &[]).collect();
        assert_eq!(charlie_in.len(), 2);
    }
}