{"id":21721813,"url":"https://github.com/bgpkit/ipnet-trie","last_synced_at":"2025-04-12T21:33:56.760Z","repository":{"id":220875997,"uuid":"743776085","full_name":"bgpkit/ipnet-trie","owner":"bgpkit","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-25T22:14:09.000Z","size":67,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-25T22:30:05.845Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bgpkit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-16T00:52:19.000Z","updated_at":"2025-03-25T22:14:01.000Z","dependencies_parsed_at":"2024-02-04T23:08:15.127Z","dependency_job_id":"6c6f1e7f-2541-4b61-828e-253cf90a8d81","html_url":"https://github.com/bgpkit/ipnet-trie","commit_stats":null,"previous_names":["bgpkit/ipnet-trie"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgpkit%2Fipnet-trie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgpkit%2Fipnet-trie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgpkit%2Fipnet-trie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bgpkit%2Fipnet-trie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bgpkit","download_url":"https://codeload.github.com/bgpkit/ipnet-trie/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248636840,"owners_count":21137527,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-26T02:19:03.872Z","updated_at":"2025-04-12T21:33:56.739Z","avatar_url":"https://github.com/bgpkit.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"ipnet-trie\n========\n\nIPv4 and IPv6 network fast lookup prefix trie.\n\n[![Rust](https://github.com/bgpkit/ipnet-trie/actions/workflows/rust.yml/badge.svg)](https://github.com/bgpkit/ipnet-trie/actions/workflows/rust.yml)\n[![Documentation](https://docs.rs/ipnet-trie/badge.svg)](https://docs.rs/ipnet-trie)\n[![Crates.io](https://img.shields.io/crates/v/ipnet-trie.svg)](https://crates.io/crates/ipnet-trie)\n[![License](https://img.shields.io/crates/l/ipnet-trie)](https://raw.githubusercontent.com/bgpkit/ipnet-trie/master/LICENSE)\n\n## Description\n\nThis crate provides storage and retrieval of IPv4 and IPv6 network prefixes. It uses the [`ipnet`](https://docs.rs/ipnet/latest/ipnet/) crate as the IP network data structure and [`prefix-trie`](https://github.com/tiborschneider/prefix-trie) as the backend, offering fast lookup times and a small memory footprint.\n\n## Features\n\n- Fast prefix lookup for both IPv4 and IPv6 networks\n- Efficient storage of IP prefixes and associated data\n- Support for exact match and longest prefix match operations\n- Ability to iterate over all stored prefixes\n- Export and import functionality (with the `export` feature flag)\n- Diff operation to compare two tries\n\n## Feature flags\n\n- `export`: Enable export of the trie to bytes or a writer, and import from bytes or a reader.\n\n## Usage\n\nAdd this to your `Cargo.toml`:\n\n```toml\n[dependencies]\nipnet = \"2\"\nipnet-trie = \"0.2\"\n```\n\nand then you can use it like this:\n\n```rust\nuse std::net::{IpAddr, Ipv6Addr};\nuse ipnet::{IpNet, Ipv6Net};\nuse ipnet_trie::IpnetTrie;\n\nlet mut table = IpnetTrie::new();\nlet network = IpNet::from(Ipv6Net::new(Ipv6Addr::new(0x2001, 0xdb8, 0xdead, 0xbeef, 0, 0, 0, 0), 64).unwrap());\nlet ip_address = Ipv6Addr::new(0x2001, 0xdb8, 0xdead, 0xbeef, 0, 0, 0, 0x1);\n\nassert_eq!(table.insert(network, \"foo\"), None);\n// Get value for network from table\nassert_eq!(table.longest_match(ip_address), Some((network, \u0026\"foo\")));\n```\n\n### Insertion and Retrieval\n\n```rust\n// Insert a network\ntable.insert(network, value);\n\n// Exact match\nlet value = table.exact_match(network);\n\n// Longest prefix match\nlet (matched_network, value) = table.longest_match(\u0026ip_address);\n```\n\n### Iteration\n\n```rust\n// Iterate over all networks\nfor (network, value) in table.iter() {\n    // ...\n}\n```\n\n### IP Count\n\n```rust\n// Get the total number of unique IPv4 and IPv6 addresses in the trie\nlet (ipv4_count, ipv6_count) = table.ip_count();\n```\n\n### Diff Operation\n\n```rust\n// Compare two tries\nlet (added, removed) = trie1.diff(\u0026trie2);\n```\n\n### Export and Import (with `export` feature)\n\n```rust\n// Export to bytes\nlet bytes = table.export_to_bytes();\n\n// Import from bytes\ntable.import_from_bytes(\u0026bytes);\n\n// Export to writer\ntable.export_to_writer(\u0026mut writer)?;\n\n// Import from reader\ntable.import_from_reader(\u0026mut reader)?;\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbgpkit%2Fipnet-trie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbgpkit%2Fipnet-trie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbgpkit%2Fipnet-trie/lists"}