{"id":26339467,"url":"https://github.com/lucidfrontier45/fpq","last_synced_at":"2025-03-16T03:17:34.298Z","repository":{"id":203194121,"uuid":"709045632","full_name":"lucidfrontier45/fpq","owner":"lucidfrontier45","description":"Priority Queue with scoring Function","archived":false,"fork":false,"pushed_at":"2025-03-12T12:33:36.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-12T12:45:12.985Z","etag":null,"topics":["data-structures","queue","rust"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/fpq","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/lucidfrontier45.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2023-10-23T22:40:56.000Z","updated_at":"2025-03-12T12:33:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"6578dda0-129e-45b4-a789-be0499f61498","html_url":"https://github.com/lucidfrontier45/fpq","commit_stats":null,"previous_names":["lucidfrontier45/heapq","lucidfrontier45/fpq"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidfrontier45%2Ffpq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidfrontier45%2Ffpq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidfrontier45%2Ffpq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidfrontier45%2Ffpq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucidfrontier45","download_url":"https://codeload.github.com/lucidfrontier45/fpq/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243818111,"owners_count":20352629,"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":["data-structures","queue","rust"],"created_at":"2025-03-16T03:17:33.721Z","updated_at":"2025-03-16T03:17:34.276Z","avatar_url":"https://github.com/lucidfrontier45.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FPQ \nPriority Queue with scoring function\n\n# Usage\n\n- Rust Edition: 2024\n- MSRV: 1.85\n\n```toml\n[dependencies]\nfpq = \"0.3.0\"\n```\n\nIn the code, you first need to create an instance with `fpq::PriorityQueue::new`. It takes a boxed closure that converts your item type `\u0026T` into score type `S: Ord`. Then you can use `push/pop/peek` methods in the same way as `std::collections::BinaryHeap`.\n\n# Example\n\n```rust\nuse std::cmp::Reverse;\n\nuse fpq::PriorityQueue;\n\nfn main() {\n    // a score function that returns the length of a string\n    let score_fn = Box::new(|s: \u0026String| s.len());\n    // create a new priority queue with the score function\n    let mut queue = PriorityQueue::new(score_fn);\n\n    // the queue is empty at the beginning\n    assert!(queue.peek().is_none());\n\n    // push some items into the queue\n    // the score function is used to calculate the score of each item\n    queue.push(\"a\".to_string()); // score = 1\n    queue.push(\"ccc\".to_string()); // score = 3\n    queue.push(\"bb\".to_string()); // score = 2\n\n    // you can also push an item with a explicit score\n    queue.push_with_score(\"b\".to_string(), 10); // score = 10\n\n    // peek the item with the highest priority\n    assert_eq!(queue.peek(), Some((10, \u0026\"b\".to_string())));\n\n    // pop the item with the highest priority\n    assert_eq!(queue.pop(), Some((10, \"b\".to_string())));\n    assert_eq!(queue.pop(), Some((3, \"ccc\".to_string())));\n    assert_eq!(queue.pop(), Some((2, \"bb\".to_string())));\n    assert_eq!(queue.pop(), Some((1, \"a\".to_string())));\n\n    // the queue is empty again\n    assert!(queue.peek().is_none());\n\n    // you can also use a reverse order\n    let score_fn = Box::new(|s: \u0026String| Reverse(s.len()));\n    let mut queue = PriorityQueue::new(score_fn);\n\n    queue.push(\"a\".to_string()); // score = -1\n    queue.push(\"ccc\".to_string()); // score = -3\n    queue.push(\"bb\".to_string()); // score = -2\n\n    // remember to use Reverse when pushing an item with an explicit score\n    queue.push_with_score(\"b\".to_string(), Reverse(10)); // score = -10\n\n    assert_eq!(queue.peek(), Some((Reverse(1), \u0026\"a\".to_string())));\n    assert_eq!(queue.pop(), Some((Reverse(1), \"a\".to_string())));\n    assert_eq!(queue.pop(), Some((Reverse(2), \"bb\".to_string())));\n    assert_eq!(queue.pop(), Some((Reverse(3), \"ccc\".to_string())));\n    assert_eq!(queue.pop(), Some((Reverse(10), \"b\".to_string())));\n\n    assert!(queue.peek().is_none());\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidfrontier45%2Ffpq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucidfrontier45%2Ffpq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidfrontier45%2Ffpq/lists"}