ruvector-mincut 2.0.6

World's first subpolynomial dynamic min-cut: self-healing networks, AI optimization, real-time graph analysis
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
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
# API Quick Reference

Complete reference for all public types in ruvector-mincut.

---

## 1. Core Types

### MinCutBuilder

Builder pattern for creating `DynamicMinCut` instances.

| Method | Description | Example |
|--------|-------------|---------|
| `new()` | Create new builder | `MinCutBuilder::new()` |
| `exact()` | Use exact algorithm | `.exact()` |
| `approximate(ε)` | Use (1+ε)-approximate algorithm | `.approximate(0.1)` |
| `max_cut_size(n)` | Set max cut size for exact mode | `.max_cut_size(1000)` |
| `parallel(bool)` | Enable/disable parallel computation | `.parallel(true)` |
| `with_edges(vec)` | Initialize with edges | `.with_edges(vec![(1,2,1.0)])` |
| `build()` | Build the structure | `.build()` |

**Example:**
```rust
use ruvector_mincut::MinCutBuilder;

let mincut = MinCutBuilder::new()
    .exact()
    .max_cut_size(500)
    .parallel(true)
    .with_edges(vec![(1, 2, 1.0), (2, 3, 1.0)])
    .build()?;
```

---

### DynamicMinCut

Main dynamic minimum cut structure.

| Method | Return Type | Description | Example |
|--------|-------------|-------------|---------|
| `new(config)` | `Self` | Create with config | `DynamicMinCut::new(config)` |
| `from_graph(g, cfg)` | `Result<Self>` | Build from existing graph | `DynamicMinCut::from_graph(graph, config)` |
| `insert_edge(u, v, w)` | `Result<f64>` | Insert edge, returns new min cut | `.insert_edge(1, 2, 1.0)?` |
| `delete_edge(u, v)` | `Result<f64>` | Delete edge, returns new min cut | `.delete_edge(1, 2)?` |
| `min_cut_value()` | `f64` | Get current min cut (O(1)) | `.min_cut_value()` |
| `min_cut()` | `MinCutResult` | Get detailed result | `.min_cut()` |
| `partition()` | `(Vec<u64>, Vec<u64>)` | Get cut partition | `.partition()` |
| `cut_edges()` | `Vec<Edge>` | Get edges in the cut | `.cut_edges()` |
| `is_connected()` | `bool` | Check connectivity | `.is_connected()` |
| `num_vertices()` | `usize` | Vertex count | `.num_vertices()` |
| `num_edges()` | `usize` | Edge count | `.num_edges()` |
| `stats()` | `AlgorithmStats` | Performance statistics | `.stats()` |
| `reset_stats()` | `()` | Reset statistics | `.reset_stats()` |
| `config()` | `&MinCutConfig` | Get configuration | `.config()` |
| `graph()` | `Arc<RwLock<Graph>>` | Get graph reference | `.graph()` |

**Example:**
```rust
let mut mincut = MinCutBuilder::new()
    .with_edges(vec![(1, 2, 1.0)])
    .build()?;

let new_cut = mincut.insert_edge(2, 3, 1.0)?;
println!("New min cut: {}", new_cut);

let result = mincut.min_cut();
let (s, t) = mincut.partition();
```

---

### MinCutResult

Result of a minimum cut query.

| Field | Type | Description |
|-------|------|-------------|
| `value` | `f64` | Minimum cut value |
| `cut_edges` | `Option<Vec<Edge>>` | Edges in the cut |
| `partition` | `Option<(Vec<u64>, Vec<u64>)>` | Vertex partition (S, T) |
| `is_exact` | `bool` | Whether result is exact |
| `approximation_ratio` | `f64` | Approximation ratio (1.0 if exact) |

**Example:**
```rust
let result = mincut.min_cut();
println!("Min cut value: {}", result.value);
println!("Is exact: {}", result.is_exact);
if let Some((s, t)) = result.partition {
    println!("Partition sizes: {} and {}", s.len(), t.len());
}
```

---

### MinCutConfig

Configuration for minimum cut algorithm.

| Field | Type | Default | Description |
|-------|------|---------|-------------|
| `max_exact_cut_size` | `usize` | `1000` | Max cut size for exact algorithm |
| `epsilon` | `f64` | `0.1` | Approximation parameter (0 < ε ≤ 1) |
| `approximate` | `bool` | `false` | Use approximate mode |
| `parallel` | `bool` | `true` | Enable parallel computation |
| `cache_size` | `usize` | `10000` | Cache size for intermediate results |

**Example:**
```rust
use ruvector_mincut::MinCutConfig;

let config = MinCutConfig {
    max_exact_cut_size: 500,
    epsilon: 0.2,
    approximate: false,
    parallel: true,
    cache_size: 5000,
};
```

---

### AlgorithmStats

Performance statistics.

| Field | Type | Description |
|-------|------|-------------|
| `insertions` | `u64` | Total insertions performed |
| `deletions` | `u64` | Total deletions performed |
| `queries` | `u64` | Total queries performed |
| `avg_update_time_us` | `f64` | Average update time (microseconds) |
| `avg_query_time_us` | `f64` | Average query time (microseconds) |
| `restructures` | `u64` | Number of tree restructures |

**Example:**
```rust
let stats = mincut.stats();
println!("Updates: {} insertions, {} deletions",
    stats.insertions, stats.deletions);
println!("Avg update time: {:.2}μs", stats.avg_update_time_us);
```

---

## 2. Graph Types

### DynamicGraph

Thread-safe dynamic graph structure.

| Method | Return Type | Description | Example |
|--------|-------------|-------------|---------|
| `new()` | `Self` | Create empty graph | `DynamicGraph::new()` |
| `with_capacity(v, e)` | `Self` | Create with capacity hint | `.with_capacity(100, 200)` |
| `add_vertex(v)` | `bool` | Add vertex (returns true if new) | `.add_vertex(1)` |
| `has_vertex(v)` | `bool` | Check if vertex exists | `.has_vertex(1)` |
| `insert_edge(u, v, w)` | `Result<EdgeId>` | Insert weighted edge | `.insert_edge(1, 2, 1.0)?` |
| `delete_edge(u, v)` | `Result<Edge>` | Delete edge | `.delete_edge(1, 2)?` |
| `has_edge(u, v)` | `bool` | Check if edge exists | `.has_edge(1, 2)` |
| `get_edge(u, v)` | `Option<Edge>` | Get edge by endpoints | `.get_edge(1, 2)` |
| `neighbors(v)` | `Vec<(u64, EdgeId)>` | Get vertex neighbors | `.neighbors(1)` |
| `degree(v)` | `usize` | Get vertex degree | `.degree(1)` |
| `num_vertices()` | `usize` | Vertex count | `.num_vertices()` |
| `num_edges()` | `usize` | Edge count | `.num_edges()` |
| `vertices()` | `Vec<VertexId>` | All vertices | `.vertices()` |
| `edges()` | `Vec<Edge>` | All edges | `.edges()` |
| `stats()` | `GraphStats` | Graph statistics | `.stats()` |
| `is_connected()` | `bool` | Check connectivity | `.is_connected()` |
| `connected_components()` | `Vec<Vec<VertexId>>` | Find components | `.connected_components()` |
| `clear()` | `()` | Clear all data | `.clear()` |
| `remove_vertex(v)` | `Result<()>` | Remove vertex and incident edges | `.remove_vertex(1)?` |
| `edge_weight(u, v)` | `Option<f64>` | Get edge weight | `.edge_weight(1, 2)` |
| `update_edge_weight(u, v, w)` | `Result<()>` | Update edge weight | `.update_edge_weight(1, 2, 2.0)?` |

**Example:**
```rust
let graph = DynamicGraph::new();
graph.add_vertex(1);
graph.add_vertex(2);
let edge_id = graph.insert_edge(1, 2, 1.5)?;
println!("Created edge {}", edge_id);
```

---

### Edge

An edge in the graph.

| Field | Type | Description |
|-------|------|-------------|
| `id` | `EdgeId` (`u64`) | Unique edge identifier |
| `source` | `VertexId` (`u64`) | Source vertex |
| `target` | `VertexId` (`u64`) | Target vertex |
| `weight` | `Weight` (`f64`) | Edge weight |

| Method | Return Type | Description |
|--------|-------------|-------------|
| `new(id, src, tgt, w)` | `Self` | Create new edge |
| `canonical_endpoints()` | `(u64, u64)` | Get ordered endpoints |
| `other(v)` | `Option<u64>` | Get other endpoint |

**Example:**
```rust
use ruvector_mincut::Edge;

let edge = Edge::new(0, 1, 2, 1.5);
assert_eq!(edge.canonical_endpoints(), (1, 2));
assert_eq!(edge.other(1), Some(2));
```

---

### GraphStats

Graph statistics.

| Field | Type | Description |
|-------|------|-------------|
| `num_vertices` | `usize` | Number of vertices |
| `num_edges` | `usize` | Number of edges |
| `total_weight` | `f64` | Sum of all edge weights |
| `min_degree` | `usize` | Minimum vertex degree |
| `max_degree` | `usize` | Maximum vertex degree |
| `avg_degree` | `f64` | Average vertex degree |

**Example:**
```rust
let stats = graph.stats();
println!("Graph: {} vertices, {} edges",
    stats.num_vertices, stats.num_edges);
println!("Degree range: {} to {}",
    stats.min_degree, stats.max_degree);
```

---

### Type Aliases

| Type | Alias | Description |
|------|-------|-------------|
| `VertexId` | `u64` | Unique vertex identifier |
| `EdgeId` | `u64` | Unique edge identifier |
| `Weight` | `f64` | Edge weight type |

---

## 3. Algorithm Variants

### ApproxMinCut

(1+ε)-approximate minimum cut for all cut sizes (SODA 2025).

| Method | Return Type | Description | Example |
|--------|-------------|-------------|---------|
| `new(config)` | `Self` | Create with config | `ApproxMinCut::new(config)` |
| `with_epsilon(ε)` | `Self` | Create with specific ε | `ApproxMinCut::with_epsilon(0.1)` |
| `insert_edge(u, v, w)` | `()` | Insert edge | `.insert_edge(1, 2, 1.0)` |
| `delete_edge(u, v)` | `()` | Delete edge | `.delete_edge(1, 2)` |
| `min_cut()` | `ApproxMinCutResult` | Query min cut | `.min_cut()` |
| `min_cut_value()` | `f64` | Get value only | `.min_cut_value()` |
| `is_connected()` | `bool` | Check connectivity | `.is_connected()` |
| `vertex_count()` | `usize` | Vertex count | `.vertex_count()` |
| `edge_count()` | `usize` | Edge count | `.edge_count()` |
| `stats()` | `&ApproxMinCutStats` | Get statistics | `.stats()` |

**Example:**
```rust
use ruvector_mincut::ApproxMinCut;

let mut approx = ApproxMinCut::with_epsilon(0.1);
approx.insert_edge(1, 2, 1.0);
approx.insert_edge(2, 3, 1.0);

let result = approx.min_cut();
println!("Approx cut: {}", result.value);
println!("Bounds: [{}, {}]", result.lower_bound, result.upper_bound);
```

---

### ApproxMinCutConfig

Configuration for approximate algorithm.

| Field | Type | Default | Description |
|-------|------|---------|-------------|
| `epsilon` | `f64` | `0.1` | Approximation parameter |
| `num_samples` | `usize` | `3` | Number of sparsifier samples |
| `seed` | `u64` | `42` | Random seed |

---

### ApproxMinCutResult

Result from approximate algorithm.

| Field | Type | Description |
|-------|------|-------------|
| `value` | `f64` | Approximate cut value |
| `lower_bound` | `f64` | Lower bound (value / (1+ε)) |
| `upper_bound` | `f64` | Upper bound (value × (1+ε)) |
| `partition` | `Option<(Vec<u64>, Vec<u64>)>` | Partition if computed |
| `epsilon` | `f64` | Approximation ratio used |

---

### PolylogConnectivity

Polylogarithmic worst-case dynamic connectivity.

| Method | Return Type | Description | Time Complexity |
|--------|-------------|-------------|-----------------|
| `new()` | `Self` | Create new structure | O(1) |
| `insert(u, v)` | `Result<()>` | Insert edge | O(log³ n) expected |
| `delete(u, v)` | `Result<()>` | Delete edge | O(log³ n) expected |
| `connected(u, v)` | `bool` | Query connectivity | O(log n) |
| `stats()` | `PolylogStats` | Get statistics | O(1) |

**Example:**
```rust
use ruvector_mincut::PolylogConnectivity;

let mut conn = PolylogConnectivity::new();
conn.insert(1, 2)?;
conn.insert(2, 3)?;
assert!(conn.connected(1, 3));
```

---

### PolylogStats

Statistics for polylog connectivity.

| Field | Type | Description |
|-------|------|-------------|
| `num_levels` | `usize` | Number of hierarchy levels |
| `total_edges` | `usize` | Total edges across all levels |
| `rebuilds` | `u64` | Number of level rebuilds |
| `avg_insert_time_us` | `f64` | Average insertion time |
| `avg_delete_time_us` | `f64` | Average deletion time |

---

## 4. Paper Implementation Types

### ThreeLevelHierarchy

3-level cluster decomposition (arXiv:2512.13105).

| Type | Description |
|------|-------------|
| `Expander` | Level 0: φ-expander subgraphs |
| `Precluster` | Level 1: Groups of expanders |
| `HierarchyCluster` | Level 2: Top-level clusters |

#### Expander

| Field | Type | Description |
|-------|------|-------------|
| `id` | `u64` | Unique ID |
| `vertices` | `HashSet<VertexId>` | Vertices in expander |
| `internal_edges` | `Vec<(u64, u64)>` | Internal edges |
| `boundary_edges` | `Vec<(u64, u64)>` | Boundary edges |
| `volume` | `usize` | Sum of degrees |
| `expansion_ratio` | `f64` | Verified expansion φ |
| `precluster_id` | `Option<u64>` | Parent precluster |

| Method | Description |
|--------|-------------|
| `new(id, vertices)` | Create new expander |
| `size()` | Number of vertices |
| `contains(v)` | Check membership |
| `boundary_sparsity()` | Compute boundary/volume ratio |

---

#### Precluster

| Field | Type | Description |
|-------|------|-------------|
| `id` | `u64` | Unique ID |
| `expanders` | `Vec<u64>` | Expander IDs |
| `vertices` | `HashSet<VertexId>` | All vertices |
| `boundary_edges` | `Vec<(u64, u64)>` | Boundary edges |
| `volume` | `usize` | Total volume |
| `cluster_id` | `Option<u64>` | Parent cluster |

| Method | Description |
|--------|-------------|
| `new(id)` | Create new precluster |
| `add_expander(exp)` | Add expander |
| `size()` | Number of vertices |
| `boundary_ratio()` | Boundary/volume ratio |

---

#### HierarchyCluster

| Field | Type | Description |
|-------|------|-------------|
| `id` | `u64` | Unique ID |
| `preclusters` | `Vec<u64>` | Precluster IDs |
| `vertices` | `HashSet<VertexId>` | All vertices |
| `boundary_edges` | `Vec<(u64, u64)>` | Boundary edges |
| `mirror_cuts` | `Vec<MirrorCut>` | Tracked cuts |
| `internal_min_cut` | `f64` | Internal min cut |

---

### DeterministicLocalKCut

Deterministic local minimum cut algorithm.

| Type | Description |
|------|-------------|
| `EdgeColor` | Edge coloring (Red, Blue, Green, Yellow) |
| `EdgeColoring` | Coloring assignment with parameters a, b |
| `GreedyForestPacking` | Forest packing structure |

#### EdgeColor

```rust
pub enum EdgeColor {
    Red,    // Forest edge, class 1
    Blue,   // Forest edge, class 2
    Green,  // Non-forest edge, class 1
    Yellow, // Non-forest edge, class 2
}
```

#### EdgeColoring

| Field | Type | Description |
|-------|------|-------------|
| `a` | `usize` | Cut size parameter |
| `b` | `usize` | Volume parameter |

| Method | Description |
|--------|-------------|
| `new(a, b)` | Create new coloring |
| `get(u, v)` | Get edge color |
| `set(u, v, color)` | Set edge color |
| `has_color(u, v, c)` | Check specific color |

---

#### GreedyForestPacking

| Field | Type | Description |
|-------|------|-------------|
| `num_forests` | `usize` | Number of forests (k) |

| Method | Description |
|--------|-------------|
| `new(k)` | Create k forests |
| `insert_edge(u, v)` | Insert into first available forest |
| `delete_edge(u, v)` | Remove edge |
| `is_tree_edge(u, v)` | Check if edge is in some forest |

**Example:**
```rust
use ruvector_mincut::GreedyForestPacking;

let mut packing = GreedyForestPacking::new(10);
if let Some(forest_id) = packing.insert_edge(1, 2) {
    println!("Edge added to forest {}", forest_id);
}
```

---

### MinCutWrapper

Wrapper managing O(log n) bounded instances.

| Method | Return Type | Description | Example |
|--------|-------------|-------------|---------|
| `new(graph)` | `Self` | Create with default factory | `MinCutWrapper::new(graph)` |
| `with_factory(g, f)` | `Self` | Create with custom factory | `.with_factory(g, factory)` |
| `insert_edge(id, u, v)` | `()` | Buffer edge insertion | `.insert_edge(0, 1, 2)` |
| `delete_edge(id, u, v)` | `()` | Buffer edge deletion | `.delete_edge(0, 1, 2)` |
| `query()` | `MinCutResult` | Query min cut | `.query()` |

**Example:**
```rust
use ruvector_mincut::{MinCutWrapper, DynamicGraph};
use std::sync::Arc;

let graph = Arc::new(DynamicGraph::new());
let edge_id = graph.insert_edge(1, 2, 1.0)?;

let mut wrapper = MinCutWrapper::new(Arc::clone(&graph));
wrapper.insert_edge(edge_id, 1, 2);

let result = wrapper.query();
println!("Min cut: {}", result.value());
```

---

### CutCertificate

Verifiable certificate for minimum cut.

| Field | Type | Description |
|-------|------|-------------|
| `witnesses` | `Vec<WitnessHandle>` | Candidate cuts maintained |
| `witness_summaries` | `Vec<WitnessSummary>` | Serializable summaries |
| `localkcut_responses` | `Vec<LocalKCutResponse>` | Proof of no smaller cut |
| `best_witness_idx` | `Option<usize>` | Index of best witness |
| `timestamp` | `SystemTime` | Creation timestamp |
| `version` | `u32` | Certificate version |

| Method | Description |
|--------|-------------|
| `new()` | Create empty certificate |
| `with_witnesses(w)` | Create with witnesses |
| `add_witness(w)` | Add witness |
| `add_localkcut_response(r)` | Add LocalKCut proof |
| `find_best_witness()` | Find smallest boundary |
| `verify()` | Verify certificate validity |

**Example:**
```rust
use ruvector_mincut::CutCertificate;

let mut cert = CutCertificate::new();
cert.add_witness(witness);
cert.find_best_witness();
println!("Certificate valid: {}", cert.verify());
```

---

## 5. Integration Types

### RuVectorGraphAnalyzer

Graph analysis for ruvector ecosystem.

| Method | Return Type | Description | Example |
|--------|-------------|-------------|---------|
| `new(graph)` | `Self` | Create analyzer | `RuVectorGraphAnalyzer::new(g)` |
| `from_similarity_matrix(...)` | `Self` | Build from similarity | `.from_similarity_matrix(&sim, n, 0.8)` |
| `from_knn(neighbors)` | `Self` | Build from k-NN graph | `.from_knn(&neighbors)` |
| `min_cut()` | `u64` | Compute min cut | `.min_cut()` |
| `partition()` | `Option<(Vec, Vec)>` | Get partition | `.partition()` |
| `is_well_connected(t)` | `bool` | Check if cut ≥ threshold | `.is_well_connected(5)` |
| `find_bridges()` | `Vec<EdgeId>` | Find bridge edges | `.find_bridges()` |
| `add_edge(u, v, w)` | `Result<EdgeId>` | Add edge | `.add_edge(1, 2, 1.0)?` |
| `remove_edge(u, v)` | `Result<()>` | Remove edge | `.remove_edge(1, 2)?` |
| `invalidate_cache()` | `()` | Clear cached results | `.invalidate_cache()` |

**Example:**
```rust
use ruvector_mincut::{RuVectorGraphAnalyzer, DynamicGraph};
use std::sync::Arc;

let graph = Arc::new(DynamicGraph::new());
let mut analyzer = RuVectorGraphAnalyzer::new(graph);

analyzer.add_edge(1, 2, 1.0)?;
println!("Min cut: {}", analyzer.min_cut());
```

---

### CommunityDetector

Detect communities using recursive min-cut.

| Method | Return Type | Description | Example |
|--------|-------------|-------------|---------|
| `new(graph)` | `Self` | Create detector | `CommunityDetector::new(g)` |
| `detect(min_size)` | `&[Vec<VertexId>]` | Detect communities | `.detect(5)` |
| `communities()` | `&[Vec<VertexId>]` | Get communities | `.communities()` |

**Example:**
```rust
use ruvector_mincut::{CommunityDetector, DynamicGraph};
use std::sync::Arc;

let graph = Arc::new(DynamicGraph::new());
let mut detector = CommunityDetector::new(graph);

let communities = detector.detect(5);
println!("Found {} communities", communities.len());
```

---

### GraphPartitioner

Partition graph for distributed processing.

| Method | Return Type | Description | Example |
|--------|-------------|-------------|---------|
| `new(graph)` | `Self` | Create partitioner | `GraphPartitioner::new(g)` |
| `partition(k)` | `Vec<Vec<VertexId>>` | Partition into k parts | `.partition(4)` |
| `balanced_partition(k)` | `Vec<Vec<VertexId>>` | Balanced k-way partition | `.balanced_partition(4)` |

**Example:**
```rust
use ruvector_mincut::{GraphPartitioner, DynamicGraph};
use std::sync::Arc;

let graph = Arc::new(DynamicGraph::new());
let mut partitioner = GraphPartitioner::new(graph);

let parts = partitioner.balanced_partition(4);
println!("Partition sizes: {:?}",
    parts.iter().map(|p| p.len()).collect::<Vec<_>>());
```

---

## 6. Compact/Parallel Types (agentic feature)

### BitSet256

Compact bit-packed set for 256 vertices (32 bytes).

| Method | Description | Example |
|--------|-------------|---------|
| `new()` | Create empty set | `BitSet256::new()` |
| `insert(v)` | Insert vertex | `.insert(42)` |
| `contains(v)` | Check membership | `.contains(42)` |
| `remove(v)` | Remove vertex | `.remove(42)` |
| `count()` | Count members | `.count()` |
| `union(other)` | Set union | `.union(&other)` |
| `intersection(other)` | Set intersection | `.intersection(&other)` |
| `xor(other)` | Symmetric difference | `.xor(&other)` |
| `iter()` | Iterate members | `.iter()` |

**Example:**
```rust
use ruvector_mincut::BitSet256;

let mut set = BitSet256::new();
set.insert(10);
set.insert(20);
assert_eq!(set.count(), 2);
assert!(set.contains(10));
```

---

### CompactCoreState

Complete min-cut state for 8KB WASM core.

| Field | Type | Description |
|-------|------|-------------|
| `vertices` | `BitSet256` | Active vertices |
| `edges` | `[CompactEdge; MAX_EDGES]` | Edge array |
| `num_edges` | `u16` | Number of active edges |
| `witnesses` | `[CompactWitness; 8]` | Maintained witnesses |
| `num_witnesses` | `u8` | Number of witnesses |
| `current_min_cut` | `u16` | Current min cut value |

| Constant | Value | Description |
|----------|-------|-------------|
| `MAX_VERTICES_PER_CORE` | `256` | Max vertices per core |
| `MAX_EDGES_PER_CORE` | `384` | Max edges per core |

---

### CompactEdge

Compact edge (8 bytes).

| Field | Type | Description |
|-------|------|-------------|
| `source` | `u16` | Source vertex |
| `target` | `u16` | Target vertex |
| `weight` | `u16` | Weight (0.01 precision) |
| `flags` | `u16` | Status flags |

| Flag | Value | Description |
|------|-------|-------------|
| `FLAG_ACTIVE` | `0x0001` | Edge is active |
| `FLAG_IN_CUT` | `0x0002` | Edge is in current cut |
| `FLAG_TREE_EDGE` | `0x0004` | Edge is in spanning tree |

---

### CoreDistributor

Distributes work across 256 cores.

| Field | Type | Description |
|-------|------|-------------|
| `strategy` | `CoreStrategy` | Distribution strategy |
| `num_vertices` | `u16` | Total vertices |
| `num_edges` | `u16` | Total edges |

| Method | Description |
|--------|-------------|
| `new(strategy, v, e)` | Create distributor |
| `vertex_to_core(v)` | Determine core for vertex |
| `distribute_ranges()` | Distribute geometric ranges |

---

### CoreExecutor

Execute min-cut on single core.

| Method | Return Type | Description |
|--------|-------------|-------------|
| `new(id, range)` | `Self` | Create executor for core |
| `load_state(state)` | `()` | Load graph state |
| `execute()` | `CoreResult` | Execute min-cut |
| `get_result()` | `CoreResult` | Get result |

---

### SharedCoordinator

Atomic coordination across cores (64 bytes).

| Field | Type | Description |
|-------|------|-------------|
| `global_min_cut` | `AtomicU16` | Global minimum found |
| `completed_cores` | `AtomicU8` | Completion count |
| `phase` | `AtomicU8` | Current phase |
| `best_core` | `AtomicU8` | Core with best result |

| Method | Description |
|--------|-------------|
| `new()` | Create coordinator |
| `try_update_min(val, id)` | Atomic min update |
| `mark_completed()` | Mark core done |
| `all_completed()` | Check if all done |

**Constants:**
```rust
pub const NUM_CORES: usize = 256;
pub const RANGES_PER_CORE: usize = 1;
pub const RANGE_FACTOR: f32 = 1.2;
```

---

### Helper Functions

| Function | Description |
|----------|-------------|
| `compute_core_range(id)` | Get (λ_min, λ_max) for core |

**Example:**
```rust
use ruvector_mincut::compute_core_range;

let (min, max) = compute_core_range(10);
println!("Core 10 handles range [{}, {}]", min, max);
```

---

## 7. Monitoring Types (monitoring feature)

### MonitorBuilder

Builder for `MinCutMonitor`.

| Method | Description | Example |
|--------|-------------|---------|
| `new()` | Create builder | `MonitorBuilder::new()` |
| `with_config(cfg)` | Set configuration | `.with_config(config)` |
| `threshold_below(v, name)` | Add below-threshold alert | `.threshold_below(10.0, "low")` |
| `threshold_above(v, name)` | Add above-threshold alert | `.threshold_above(100.0, "high")` |
| `on_change(name, cb)` | Add change callback | `.on_change("test", \|e\| {...})` |
| `on_event_type(type, name, cb)` | Add type-filtered callback | `.on_event_type(EventType::CutIncreased, "inc", \|e\| {...})` |
| `build()` | Build monitor | `.build()` |

**Example:**
```rust
use ruvector_mincut::{MonitorBuilder, EventType};

let monitor = MonitorBuilder::new()
    .threshold_below(5.0, "critical")
    .threshold_above(50.0, "high")
    .on_event_type(EventType::CutDecreased, "alert", |event| {
        println!("Cut decreased to {}", event.new_value);
    })
    .build();
```

---

### MinCutMonitor

Real-time monitoring for min-cut changes.

| Method | Return Type | Description | Example |
|--------|-------------|-------------|---------|
| `new(config)` | `Self` | Create monitor | `MinCutMonitor::new(cfg)` |
| `on_event(name, cb)` | `Result<()>` | Register callback | `.on_event("test", \|e\| {...})?` |
| `on_event_type(type, name, cb)` | `Result<()>` | Register filtered callback | `.on_event_type(EventType::CutIncreased, "inc", \|e\| {...})?` |
| `add_threshold(t)` | `Result<()>` | Add threshold | `.add_threshold(threshold)?` |
| `remove_threshold(name)` | `bool` | Remove threshold | `.remove_threshold("low")` |
| `remove_callback(name)` | `bool` | Remove callback | `.remove_callback("test")` |
| `notify(old, new, edge)` | `()` | Notify of change | `.notify(5.0, 10.0, None)` |
| `metrics()` | `MonitorMetrics` | Get metrics | `.metrics()` |
| `reset_metrics()` | `()` | Reset metrics | `.reset_metrics()` |
| `current_cut()` | `f64` | Get current value | `.current_cut()` |
| `threshold_status()` | `Vec<(String, bool)>` | Threshold states | `.threshold_status()` |

**Example:**
```rust
use ruvector_mincut::{MinCutMonitor, MonitorConfig};

let monitor = MinCutMonitor::new(MonitorConfig::default());

monitor.on_event("logger", |event| {
    println!("Event: {:?}", event.event_type);
})?;

monitor.notify(10.0, 5.0, None);
```

---

### EventType

Type of monitoring event.

```rust
pub enum EventType {
    CutIncreased,           // Min cut value increased
    CutDecreased,           // Min cut value decreased
    ThresholdCrossedBelow,  // Crossed below threshold
    ThresholdCrossedAbove,  // Crossed above threshold
    Disconnected,           // Graph became disconnected
    Connected,              // Graph became connected
    EdgeInserted,           // Edge was inserted
    EdgeDeleted,            // Edge was deleted
}
```

---

### MinCutEvent

Event from monitoring system.

| Field | Type | Description |
|-------|------|-------------|
| `event_type` | `EventType` | Type of event |
| `new_value` | `f64` | New min cut value |
| `old_value` | `f64` | Previous min cut value |
| `timestamp` | `Instant` | When event occurred |
| `threshold` | `Option<f64>` | Threshold crossed (if applicable) |
| `edge` | `Option<(u64, u64)>` | Edge involved (if applicable) |

---

### Threshold

Threshold configuration.

| Field | Type | Description |
|-------|------|-------------|
| `value` | `f64` | Threshold value |
| `name` | `String` | Identifier |
| `alert_below` | `bool` | Alert when below (vs above) |
| `enabled` | `bool` | Whether active |

| Method | Description |
|--------|-------------|
| `new(v, name, below)` | Create threshold |

**Example:**
```rust
use ruvector_mincut::Threshold;

let threshold = Threshold::new(10.0, "critical".to_string(), true);
```

---

### MonitorMetrics

Collected monitoring metrics.

| Field | Type | Description |
|-------|------|-------------|
| `total_events` | `u64` | Total events processed |
| `events_by_type` | `HashMap<String, u64>` | Events by type |
| `cut_history` | `Vec<(Instant, f64)>` | Sampled history |
| `avg_cut` | `f64` | Average cut value |
| `min_observed` | `f64` | Minimum observed |
| `max_observed` | `f64` | Maximum observed |
| `threshold_violations` | `u64` | Threshold crossings |
| `time_since_last_event` | `Option<Duration>` | Time since last event |

**Example:**
```rust
let metrics = monitor.metrics();
println!("Total events: {}", metrics.total_events);
println!("Average cut: {:.2}", metrics.avg_cut);
println!("Range: [{}, {}]", metrics.min_observed, metrics.max_observed);
```

---

### MonitorConfig

Monitor configuration.

| Field | Type | Default | Description |
|-------|------|---------|-------------|
| `max_callbacks` | `usize` | `100` | Max registered callbacks |
| `sample_interval` | `Duration` | `1s` | History sampling interval |
| `max_history_size` | `usize` | `1000` | Max history entries |
| `collect_metrics` | `bool` | `true` | Enable metrics collection |

---

## Common Operation Quick Reference

### Initialize and Build

```rust
// Basic exact algorithm
let mincut = MinCutBuilder::new()
    .exact()
    .with_edges(vec![(1, 2, 1.0)])
    .build()?;

// Approximate algorithm
let approx = MinCutBuilder::new()
    .approximate(0.1)
    .with_edges(edges)
    .build()?;
```

### Dynamic Updates

```rust
// Insert edge
let new_cut = mincut.insert_edge(3, 4, 2.0)?;

// Delete edge
let new_cut = mincut.delete_edge(1, 2)?;

// Query
let value = mincut.min_cut_value();
let result = mincut.min_cut();
```

### Monitoring

```rust
let monitor = MonitorBuilder::new()
    .threshold_below(5.0, "critical")
    .on_change("log", |e| println!("{:?}", e))
    .build();

monitor.notify(old_value, new_value, None);
```

### Integration

```rust
let analyzer = RuVectorGraphAnalyzer::new(graph);
let cut = analyzer.min_cut();
let (s, t) = analyzer.partition().unwrap();

let detector = CommunityDetector::new(graph);
let communities = detector.detect(5);
```

---

## Error Handling

All fallible operations return `Result<T, MinCutError>`:

```rust
use ruvector_mincut::{MinCutBuilder, MinCutError};

match mincut.insert_edge(1, 2, 1.0) {
    Ok(new_cut) => println!("New cut: {}", new_cut),
    Err(MinCutError::EdgeExists(u, v)) => {
        println!("Edge {}-{} already exists", u, v);
    }
    Err(e) => println!("Error: {:?}", e),
}
```

Common errors:
- `EdgeExists(u, v)` - Edge already present
- `EdgeNotFound(u, v)` - Edge doesn't exist
- `InvalidEdge(u, v)` - Self-loop or invalid
- `InvalidVertex(v)` - Vertex doesn't exist
- `InvalidParameter(msg)` - Invalid configuration

---

## Performance Tips

1. **Use exact mode for small cuts** (<1000), approximate for larger
2. **Enable parallel** computation for graphs with >1000 edges
3. **Batch updates** when possible, query after batch complete
4. **Monitor selectively** - use event type filters
5. **For agentic chip**: Keep per-core state under 8KB
6. **Cache invalidation**: Only when necessary for integration types

---

## Version Information

```rust
use ruvector_mincut::{VERSION, NAME};

println!("{} v{}", NAME, VERSION);
```

Current certificate version: `CERTIFICATE_VERSION = 1`

---

## See Also

- [Getting Started Guide]01-getting-started.md
- [Algorithm Details]02-algorithm-details.md
- [Performance Guide]03-performance.md
- [Paper Algorithms]04-paper-algorithms.md
- [Agentic Chip]05-agentic-chip.md
- [Monitoring Guide]06-monitoring.md