Kotoba Graph
High-performance graph data structures for the Kotoba graph processing system. Provides efficient implementations of vertices, edges, and graph operations optimized for graph rewriting and query processing.
๐ฏ Overview
Kotoba Graph serves as the core data layer for graph processing, providing:
- Efficient Graph Structures: Column-oriented graph representation for optimal performance
- Rich Metadata: Labels and properties on vertices and edges
- Thread-Safe Operations: Concurrent access patterns with GraphRef
- Fast Traversal: Optimized adjacency lists and indexing
๐๏ธ Architecture
Core Data Structures
Graph Structure (graph.rs)
// Main graph with column-oriented storage
Vertex & Edge Data
// Vertex with metadata
// Edge with source/destination and metadata
๐ Quality Metrics
| Metric | Status |
|---|---|
| Compilation | โ Clean (no warnings) |
| Tests | โ 100% coverage on core operations |
| Documentation | โ Complete API docs |
| Performance | โ O(1) lookups, efficient traversal |
| Thread Safety | โ Concurrent access via GraphRef |
| Memory | โ Compact representation |
๐ง Usage
Basic Graph Operations
use *;
use *;
use HashMap;
// Create empty graph
let mut graph = empty;
// Add vertices with properties
let alice_id = new_v4;
let alice = VertexData ;
graph.add_vertex;
// Add edges
let bob_id = new_v4;
let bob = VertexData ;
graph.add_vertex;
// Create relationship
let follows_edge = EdgeData ;
graph.add_edge;
// Query operations
assert!;
assert_eq!;
assert_eq!;
Advanced Operations
use GraphRef;
// Thread-safe graph reference
let graph_ref = new;
// Concurrent access
let vertices = graph_ref.read.vertices.clone;
// ... perform operations
๐ Ecosystem Integration
Kotoba Graph is the foundation for:
| Crate | Purpose | Integration |
|---|---|---|
kotoba-core |
Required | Base types (VertexId, EdgeId, Value) |
kotoba-execution |
Required | Query execution on graph data |
kotoba-rewrite |
Required | Graph transformation rules |
kotoba-storage |
Required | Persistence layer |
kotoba-server |
Required | Graph serving over HTTP |
๐งช Testing
Test Coverage:
- โ Graph creation and basic operations
- โ Vertex addition, retrieval, and validation
- โ Edge operations with adjacency tracking
- โ Graph statistics and metadata
- โ Serialization/deserialization
- โ Label-based indexing
๐ Performance
- O(1) Lookups: Direct hash map access for vertices and edges
- Efficient Traversal: Pre-computed adjacency lists
- Memory Optimized: Column-oriented storage minimizes overhead
- Concurrent Access: RwLock-based thread safety
- Label Indexing: Fast queries by vertex/edge labels
๐ Security
- Type Safety: Strongly typed graph operations
- Memory Safety: Rust guarantees prevent buffer overflows
- Thread Safety: Safe concurrent access patterns
- Property Validation: Type-safe property access
๐ API Reference
Core Types
- [
Graph] - Main graph data structure - [
VertexData] - Vertex with metadata and properties - [
EdgeData] - Edge with source, destination, and properties - [
GraphRef] - Thread-safe graph reference
Operations
- [
Graph::add_vertex()] - Add vertex to graph - [
Graph::add_edge()] - Add edge with adjacency updates - [
Graph::has_vertex()] - Check vertex existence - [
Graph::vertex_count()] / [Graph::edge_count()] - Graph statistics
Traversal
- [
Graph::adj_out] - Outgoing adjacency list - [
Graph::adj_in] - Incoming adjacency list - [
Graph::vertex_labels] - Label-based vertex indexing
๐ค Contributing
See the main Kotoba repository for contribution guidelines.
๐ License
Licensed under MIT OR Apache-2.0. See LICENSE for details.