|
77 | 77 | //! // Use domain-specific optimized collections |
78 | 78 | //! let facet_map: FacetToCellsMap = FacetToCellsMap::default(); |
79 | 79 | //! ``` |
| 80 | +//! |
| 81 | +//! ## Phase 1 Migration: Key-Based Internal Operations |
| 82 | +//! |
| 83 | +//! Phase 1 of the UUID-to-Key migration provides optimized collections for internal operations: |
| 84 | +//! |
| 85 | +//! ```rust |
| 86 | +//! use delaunay::core::collections::{CellKeySet, VertexKeySet, KeyBasedCellMap}; |
| 87 | +//! use delaunay::core::triangulation_data_structure::{CellKey, VertexKey}; |
| 88 | +//! |
| 89 | +//! // Phase 1: Direct key-based collections for internal algorithms |
| 90 | +//! let mut internal_cells: CellKeySet = CellKeySet::default(); |
| 91 | +//! let mut internal_vertices: VertexKeySet = VertexKeySet::default(); |
| 92 | +//! let mut key_mappings: KeyBasedCellMap<String> = KeyBasedCellMap::default(); |
| 93 | +//! ``` |
80 | 94 |
|
81 | 95 | use fxhash::{FxHashMap, FxHashSet}; |
82 | 96 | use smallvec::SmallVec; |
@@ -158,13 +172,24 @@ pub type FastHashMap<K, V> = FxHashMap<K, V>; |
158 | 172 | /// |
159 | 173 | /// # Examples |
160 | 174 | /// |
| 175 | +/// External API usage (UUID-based for compatibility): |
161 | 176 | /// ```rust |
162 | 177 | /// use delaunay::core::collections::FastHashSet; |
163 | 178 | /// use uuid::Uuid; |
164 | 179 | /// |
165 | 180 | /// let mut set: FastHashSet<Uuid> = FastHashSet::default(); |
166 | 181 | /// set.insert(Uuid::new_v4()); |
167 | 182 | /// ``` |
| 183 | +/// |
| 184 | +/// **Phase 1**: Internal operations (key-based for performance): |
| 185 | +/// ```rust |
| 186 | +/// use delaunay::core::collections::{FastHashSet, CellKeySet}; |
| 187 | +/// use delaunay::core::triangulation_data_structure::CellKey; |
| 188 | +/// |
| 189 | +/// // For internal algorithms, prefer direct key-based collections |
| 190 | +/// let mut internal_set: CellKeySet = CellKeySet::default(); |
| 191 | +/// // internal_set.insert(cell_key); // No UUID lookup needed |
| 192 | +/// ``` |
168 | 193 | pub type FastHashSet<T> = FxHashSet<T>; |
169 | 194 |
|
170 | 195 | /// Small-optimized Vec that uses stack allocation for small collections. |
@@ -486,6 +511,168 @@ pub type UuidToVertexKeyMap = FastHashMap<Uuid, VertexKey>; |
486 | 511 | /// ``` |
487 | 512 | pub type UuidToCellKeyMap = FastHashMap<Uuid, CellKey>; |
488 | 513 |
|
| 514 | +// ============================================================================= |
| 515 | +// PHASE 1 MIGRATION: KEY-BASED INTERNAL TYPES |
| 516 | +// ============================================================================= |
| 517 | + |
| 518 | +/// **Phase 1 Migration**: Optimized set for `CellKey` collections in internal operations. |
| 519 | +/// |
| 520 | +/// This eliminates UUID dependencies in internal algorithms by working directly with `SlotMap` keys. |
| 521 | +/// Provides the same performance benefits as `FastHashSet` but for direct key operations. |
| 522 | +/// |
| 523 | +/// # Performance Benefits |
| 524 | +/// |
| 525 | +/// - **No UUID→Key lookups**: O(0) hash operations vs O(1) UUID→Key mapping |
| 526 | +/// - **Direct `SlotMap` compatibility**: Keys can be used directly for data structure access |
| 527 | +/// - **Memory efficiency**: `CellKey` is typically smaller than `Uuid` (8 bytes vs 16 bytes) |
| 528 | +/// - **Cache friendly**: Better memory locality for key-based algorithms |
| 529 | +/// |
| 530 | +/// # Use Cases |
| 531 | +/// |
| 532 | +/// - Internal cell tracking during algorithms |
| 533 | +/// - Validation operations that work with cell keys |
| 534 | +/// - Temporary cell collections in geometric operations |
| 535 | +/// |
| 536 | +/// # Examples |
| 537 | +/// |
| 538 | +/// ```rust |
| 539 | +/// use delaunay::core::collections::CellKeySet; |
| 540 | +/// use delaunay::core::triangulation_data_structure::CellKey; |
| 541 | +/// |
| 542 | +/// // Direct key-based operations (Phase 1 internal algorithms) |
| 543 | +/// let mut cell_set: CellKeySet = CellKeySet::default(); |
| 544 | +/// // cell_key comes from SlotMap operations, no UUID lookups needed |
| 545 | +/// // cell_set.insert(cell_key); |
| 546 | +/// ``` |
| 547 | +pub type CellKeySet = FastHashSet<CellKey>; |
| 548 | + |
| 549 | +/// **Phase 1 Migration**: Optimized set for `VertexKey` collections in internal operations. |
| 550 | +/// |
| 551 | +/// This eliminates UUID dependencies in internal algorithms by working directly with `SlotMap` keys. |
| 552 | +/// Provides the same performance benefits as `FastHashSet` but for direct key operations. |
| 553 | +/// |
| 554 | +/// # Performance Benefits |
| 555 | +/// |
| 556 | +/// - **No UUID→Key lookups**: O(0) hash operations vs O(1) UUID→Key mapping |
| 557 | +/// - **Direct `SlotMap` compatibility**: Keys can be used directly for data structure access |
| 558 | +/// - **Memory efficiency**: `VertexKey` is typically smaller than `Uuid` (8 bytes vs 16 bytes) |
| 559 | +/// - **Cache friendly**: Better memory locality for key-based algorithms |
| 560 | +/// |
| 561 | +/// # Use Cases |
| 562 | +/// |
| 563 | +/// - Internal vertex tracking during algorithms |
| 564 | +/// - Validation operations that work with vertex keys |
| 565 | +/// - Temporary vertex collections in geometric operations |
| 566 | +/// |
| 567 | +/// # Examples |
| 568 | +/// |
| 569 | +/// ```rust |
| 570 | +/// use delaunay::core::collections::VertexKeySet; |
| 571 | +/// use delaunay::core::triangulation_data_structure::VertexKey; |
| 572 | +/// |
| 573 | +/// // Direct key-based operations (Phase 1 internal algorithms) |
| 574 | +/// let mut vertex_set: VertexKeySet = VertexKeySet::default(); |
| 575 | +/// // vertex_key comes from SlotMap operations, no UUID lookups needed |
| 576 | +/// // vertex_set.insert(vertex_key); |
| 577 | +/// ``` |
| 578 | +pub type VertexKeySet = FastHashSet<VertexKey>; |
| 579 | + |
| 580 | +/// **Phase 1 Migration**: Key-based mapping for internal cell operations. |
| 581 | +/// |
| 582 | +/// This provides direct `CellKey` → Value mapping without requiring UUID lookups, |
| 583 | +/// optimizing internal algorithms that work with cell keys. |
| 584 | +/// |
| 585 | +/// # Performance Benefits |
| 586 | +/// |
| 587 | +/// - **Direct key access**: No intermediate UUID→Key mapping required |
| 588 | +/// - **`SlotMap` integration**: Keys align perfectly with internal data structure access patterns |
| 589 | +/// - **Memory efficiency**: Avoids storing redundant UUID→Key associations |
| 590 | +/// - **Algorithm optimization**: Enables O(0) key operations in hot paths |
| 591 | +/// |
| 592 | +/// # Use Cases |
| 593 | +/// |
| 594 | +/// - Internal cell metadata storage |
| 595 | +/// - Algorithm state tracking per cell |
| 596 | +/// - Temporary mappings during geometric operations |
| 597 | +/// - Validation data associated with specific cells |
| 598 | +/// |
| 599 | +/// # Examples |
| 600 | +/// |
| 601 | +/// ```rust |
| 602 | +/// use delaunay::core::collections::KeyBasedCellMap; |
| 603 | +/// use delaunay::core::triangulation_data_structure::CellKey; |
| 604 | +/// |
| 605 | +/// // Direct key-based mapping (Phase 1 internal algorithms) |
| 606 | +/// let mut cell_data: KeyBasedCellMap<f64> = KeyBasedCellMap::default(); |
| 607 | +/// // cell_key comes from SlotMap, value is algorithm-specific data |
| 608 | +/// // cell_data.insert(cell_key, 42.0); |
| 609 | +/// ``` |
| 610 | +pub type KeyBasedCellMap<V> = FastHashMap<CellKey, V>; |
| 611 | + |
| 612 | +/// **Phase 1 Migration**: Key-based mapping for internal vertex operations. |
| 613 | +/// |
| 614 | +/// This provides direct `VertexKey` → Value mapping without requiring UUID lookups, |
| 615 | +/// optimizing internal algorithms that work with vertex keys. |
| 616 | +/// |
| 617 | +/// # Performance Benefits |
| 618 | +/// |
| 619 | +/// - **Direct key access**: No intermediate UUID→Key mapping required |
| 620 | +/// - **`SlotMap` integration**: Keys align perfectly with internal data structure access patterns |
| 621 | +/// - **Memory efficiency**: Avoids storing redundant UUID→Key associations |
| 622 | +/// - **Algorithm optimization**: Enables O(0) key operations in hot paths |
| 623 | +/// |
| 624 | +/// # Use Cases |
| 625 | +/// |
| 626 | +/// - Internal vertex metadata storage |
| 627 | +/// - Algorithm state tracking per vertex |
| 628 | +/// - Temporary mappings during geometric operations |
| 629 | +/// - Validation data associated with specific vertices |
| 630 | +/// |
| 631 | +/// # Examples |
| 632 | +/// |
| 633 | +/// ```rust |
| 634 | +/// use delaunay::core::collections::KeyBasedVertexMap; |
| 635 | +/// use delaunay::core::triangulation_data_structure::VertexKey; |
| 636 | +/// |
| 637 | +/// // Direct key-based mapping (Phase 1 internal algorithms) |
| 638 | +/// let mut vertex_data: KeyBasedVertexMap<String> = KeyBasedVertexMap::default(); |
| 639 | +/// // vertex_key comes from SlotMap, value is algorithm-specific data |
| 640 | +/// // vertex_data.insert(vertex_key, "metadata".to_string()); |
| 641 | +/// ``` |
| 642 | +pub type KeyBasedVertexMap<V> = FastHashMap<VertexKey, V>; |
| 643 | + |
| 644 | +/// **Phase 1 Migration**: Optimized neighbor mapping using direct key relationships. |
| 645 | +/// |
| 646 | +/// This replaces UUID-based neighbor mappings with direct key-to-key relationships, |
| 647 | +/// eliminating UUID lookups in neighbor assignment and traversal operations. |
| 648 | +/// |
| 649 | +/// # Performance Benefits |
| 650 | +/// |
| 651 | +/// - **No UUID lookups**: Direct key-to-key mapping eliminates hash table lookups |
| 652 | +/// - **`SlotMap` alignment**: Both keys and values work directly with internal data structures |
| 653 | +/// - **Memory efficiency**: Keys are typically smaller than UUIDs |
| 654 | +/// - **Cache optimization**: Better memory locality for neighbor traversals |
| 655 | +/// |
| 656 | +/// # Use Cases |
| 657 | +/// |
| 658 | +/// - Internal neighbor assignment algorithms |
| 659 | +/// - Topology validation operations |
| 660 | +/// - Graph traversal algorithms on the triangulation |
| 661 | +/// - Geometric operations requiring neighbor access |
| 662 | +/// |
| 663 | +/// # Examples |
| 664 | +/// |
| 665 | +/// ```rust |
| 666 | +/// use delaunay::core::collections::KeyBasedNeighborMap; |
| 667 | +/// use delaunay::core::triangulation_data_structure::{CellKey, VertexKey}; |
| 668 | +/// |
| 669 | +/// // Direct key-based neighbor mapping (Phase 1 internal algorithms) |
| 670 | +/// let mut neighbors: KeyBasedNeighborMap = KeyBasedNeighborMap::default(); |
| 671 | +/// // Both cell_key and neighbor_key come from SlotMap operations |
| 672 | +/// // neighbors.insert(cell_key, neighbor_key); |
| 673 | +/// ``` |
| 674 | +pub type KeyBasedNeighborMap = FastHashMap<CellKey, CellKey>; |
| 675 | + |
489 | 676 | /// Size constant for batch point processing operations. |
490 | 677 | /// 16 provides sufficient capacity for typical geometric algorithm batches. |
491 | 678 | const BATCH_PROCESSING_BUFFER_SIZE: usize = 16; |
@@ -540,13 +727,23 @@ pub fn fast_hash_map_with_capacity<K, V>(capacity: usize) -> FastHashMap<K, V> { |
540 | 727 | /// |
541 | 728 | /// # Examples |
542 | 729 | /// |
| 730 | +/// External API usage (UUID-based): |
543 | 731 | /// ```rust |
544 | 732 | /// use delaunay::core::collections::fast_hash_set_with_capacity; |
545 | 733 | /// use uuid::Uuid; |
546 | 734 | /// |
547 | 735 | /// let set = fast_hash_set_with_capacity::<Uuid>(500); |
548 | 736 | /// // Can insert up to ~375 UUIDs without rehashing |
549 | 737 | /// ``` |
| 738 | +/// |
| 739 | +/// **Phase 1**: Internal operations (key-based for better performance): |
| 740 | +/// ```rust |
| 741 | +/// use delaunay::core::collections::fast_hash_set_with_capacity; |
| 742 | +/// use delaunay::core::triangulation_data_structure::CellKey; |
| 743 | +/// |
| 744 | +/// let set = fast_hash_set_with_capacity::<CellKey>(500); |
| 745 | +/// // Can insert up to ~375 CellKeys without rehashing, more memory efficient |
| 746 | +/// ``` |
550 | 747 | #[inline] |
551 | 748 | #[must_use] |
552 | 749 | pub fn fast_hash_set_with_capacity<T>(capacity: usize) -> FastHashSet<T> { |
@@ -645,4 +842,23 @@ mod tests { |
645 | 842 |
|
646 | 843 | // Just test that they compile and can be instantiated |
647 | 844 | } |
| 845 | + |
| 846 | + #[test] |
| 847 | + fn test_phase1_key_based_types() { |
| 848 | + // Test that Phase 1 key-based types compile and can be instantiated |
| 849 | + let _cell_set: CellKeySet = CellKeySet::default(); |
| 850 | + let _vertex_set: VertexKeySet = VertexKeySet::default(); |
| 851 | + let _cell_map: KeyBasedCellMap<i32> = KeyBasedCellMap::default(); |
| 852 | + let _vertex_map: KeyBasedVertexMap<String> = KeyBasedVertexMap::default(); |
| 853 | + let _neighbor_map: KeyBasedNeighborMap = KeyBasedNeighborMap::default(); |
| 854 | + |
| 855 | + // Test basic operations work |
| 856 | + let cell_set: CellKeySet = CellKeySet::default(); |
| 857 | + assert!(cell_set.is_empty()); |
| 858 | + assert_eq!(cell_set.len(), 0); |
| 859 | + |
| 860 | + let cell_map: KeyBasedCellMap<f64> = KeyBasedCellMap::default(); |
| 861 | + assert!(cell_map.is_empty()); |
| 862 | + assert_eq!(cell_map.len(), 0); |
| 863 | + } |
648 | 864 | } |
0 commit comments