| Crates.io | kotoba-graph |
| lib.rs | kotoba-graph |
| version | 0.1.21 |
| created_at | 2025-09-14 07:45:19.407307+00 |
| updated_at | 2025-09-18 13:22:28.288089+00 |
| description | High-performance graph data structures for Kotoba graph processing system |
| homepage | https://github.com/com-junkawasaki/kotoba |
| repository | https://github.com/com-junkawasaki/kotoba |
| max_upload_size | |
| id | 1838439 |
| size | 106,125 |
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.
Kotoba Graph serves as the core data layer for graph processing, providing:
graph.rs)// Main graph with column-oriented storage
#[derive(Debug, Clone)]
pub struct Graph {
// Vertex storage (ID โ Data)
pub vertices: HashMap<VertexId, VertexData>,
// Edge storage (ID โ Data)
pub edges: HashMap<EdgeId, EdgeData>,
// Adjacency lists for fast traversal
pub adj_out: HashMap<VertexId, HashSet<VertexId>>, // Outgoing edges
pub adj_in: HashMap<VertexId, HashSet<VertexId>>, // Incoming edges
// Label-based indexing
pub vertex_labels: HashMap<Label, HashSet<VertexId>>,
pub edge_labels: HashMap<Label, HashSet<EdgeId>>,
}
// Vertex with metadata
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VertexData {
pub id: VertexId,
pub labels: Vec<Label>,
pub props: Properties,
}
// Edge with source/destination and metadata
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EdgeData {
pub id: EdgeId,
pub src: VertexId,
pub dst: VertexId,
pub label: Label,
pub props: Properties,
}
| 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 |
use kotoba_graph::prelude::*;
use kotoba_core::types::*;
use std::collections::HashMap;
// Create empty graph
let mut graph = Graph::empty();
// Add vertices with properties
let alice_id = VertexId::new_v4();
let alice = VertexData {
id: alice_id,
labels: vec!["Person".to_string()],
props: {
let mut props = HashMap::new();
props.insert("name".to_string(), Value::String("Alice".to_string()));
props.insert("age".to_string(), Value::Int(30));
props
},
};
graph.add_vertex(alice);
// Add edges
let bob_id = VertexId::new_v4();
let bob = VertexData {
id: bob_id,
labels: vec!["Person".to_string()],
props: HashMap::new(),
};
graph.add_vertex(bob);
// Create relationship
let follows_edge = EdgeData {
id: EdgeId::new_v4(),
src: alice_id,
dst: bob_id,
label: "FOLLOWS".to_string(),
props: HashMap::new(),
};
graph.add_edge(follows_edge);
// Query operations
assert!(graph.has_vertex(&alice_id));
assert_eq!(graph.vertex_count(), 2);
assert_eq!(graph.edge_count(), 1);
use kotoba_graph::GraphRef;
// Thread-safe graph reference
let graph_ref = GraphRef::new(graph);
// Concurrent access
let vertices = graph_ref.read().vertices.clone();
// ... perform operations
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 |
cargo test -p kotoba-graph
Test Coverage:
Graph] - Main graph data structureVertexData] - Vertex with metadata and propertiesEdgeData] - Edge with source, destination, and propertiesGraphRef] - Thread-safe graph referenceGraph::add_vertex()] - Add vertex to graphGraph::add_edge()] - Add edge with adjacency updatesGraph::has_vertex()] - Check vertex existenceGraph::vertex_count()] / [Graph::edge_count()] - Graph statisticsGraph::adj_out] - Outgoing adjacency listGraph::adj_in] - Incoming adjacency listGraph::vertex_labels] - Label-based vertex indexingSee the main Kotoba repository for contribution guidelines.
Licensed under MIT OR Apache-2.0. See LICENSE for details.