Skip to main content

graphify_core/
lib.rs

1pub mod confidence;
2pub mod error;
3pub mod graph;
4pub mod id;
5pub mod model;
6
7use std::collections::HashMap;
8
9/// Build a reverse lookup from node ID to community ID.
10pub fn build_node_to_community(communities: &HashMap<usize, Vec<String>>) -> HashMap<&str, usize> {
11    let mut map = HashMap::new();
12    for (&cid, members) in communities {
13        for nid in members {
14            map.insert(nid.as_str(), cid);
15        }
16    }
17    map
18}
19
20/// Maximum bytes for a single filename component (excluding extension).
21/// macOS HFS+/APFS limit is 255 bytes per component; we reserve 15 for extension + safety.
22pub const MAX_FILENAME_BYTES: usize = 240;
23
24/// Truncate a string to at most `max_bytes` bytes while preserving UTF-8 validity.
25pub fn truncate_to_bytes(s: &str, max_bytes: usize) -> &str {
26    if s.len() <= max_bytes {
27        return s;
28    }
29    let mut end = max_bytes;
30    while end > 0 && !s.is_char_boundary(end) {
31        end -= 1;
32    }
33    &s[..end]
34}