{"id":21452935,"url":"https://github.com/arindas/lazy-prime-sieve","last_synced_at":"2025-03-17T02:44:46.229Z","repository":{"id":180466877,"uuid":"665059580","full_name":"arindas/lazy-prime-sieve","owner":"arindas","description":"Lazy Sieve of Eratosthenes for infinitely generating primes lazily in Rust. ","archived":false,"fork":false,"pushed_at":"2023-07-16T04:38:54.000Z","size":4814,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-25T17:43:07.358Z","etag":null,"topics":["functional-programming","lazy-evaluation","prime-sieve","sieve-of-eratosthenes"],"latest_commit_sha":null,"homepage":"https://docs.rs/lazy-prime-sieve","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/arindas.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}},"created_at":"2023-07-11T10:48:01.000Z","updated_at":"2024-04-25T17:43:07.359Z","dependencies_parsed_at":"2023-10-11T08:59:47.118Z","dependency_job_id":null,"html_url":"https://github.com/arindas/lazy-prime-sieve","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"c62764d493843fec733b4b91b5095464ee4618b4"},"previous_names":["arindas/lazy-prime-sieve"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arindas%2Flazy-prime-sieve","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arindas%2Flazy-prime-sieve/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arindas%2Flazy-prime-sieve/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arindas%2Flazy-prime-sieve/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arindas","download_url":"https://codeload.github.com/arindas/lazy-prime-sieve/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243965356,"owners_count":20375912,"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":["functional-programming","lazy-evaluation","prime-sieve","sieve-of-eratosthenes"],"created_at":"2024-11-23T04:33:11.285Z","updated_at":"2025-03-17T02:44:46.212Z","avatar_url":"https://github.com/arindas.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003ch1 align=\"center\"\u003e\u003ccode\u003elazy-prime-sieve\u003c/code\u003e\u003c/h1\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/arindas/lazy-prime-sieve/actions/workflows/rust-ci.yml\"\u003e\n    \u003cimg src=\"https://github.com/arindas/lazy-prime-sieve/actions/workflows/rust-ci.yml/badge.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/arindas/lazy-prime-sieve\"\u003e\n    \u003cimg src=\"https://codecov.io/gh/arindas/lazy-prime-sieve/branch/main/graph/badge.svg?token=MZfko4wvwc\"/\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://crates.io/crates/lazy-prime-sieve\"\u003e\n  \u003cimg src=\"https://img.shields.io/crates/v/lazy-prime-sieve\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/arindas/lazy-prime-sieve/actions/workflows/rustdoc.yml\"\u003e\n  \u003cimg src=\"https://github.com/arindas/lazy-prime-sieve/actions/workflows/rustdoc.yml/badge.svg\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\nLazy Sieve of Eratosthenes for infinitely generating primes lazily in Rust.\n\u003c/p\u003e\n\n## Usage\n\n`lazy-prime-sieve` is a library crate. You may add it to your `Cargo.toml` as\nfollows:\n\n```toml\n[dependencies]\nlazy-prime-sieve = \"0.1.3\"\n```\n\n`lazy-prime-sieve` provides iterators for infinitely generating primes. This\ncrate provides a convenience method `::primes()` which returns the most\nefficient iterator (in this crate) for generating primes.\n\n\n```rust\nuse lazy_prime_sieve::primes;\n\nfor i in primes().take(10) {\n    println!(\"{i}\");\n}\n```\n\n## Design\n\nThis crate provides two types of abstractions: `sieve`(s) and `source`(s).\n- `source`(s) represent infinite sources of integers from which we sample primes.\n- `sieve`(s) sample primes from `source`(s).\n\nBoth `source`(s) and `sieve`(s) implement `Iterator\u003cItem = u64\u003e`.\n\nThis crate provides the following sieves:\n- `UnfaithfulSieve`: Non-recursive `Iterator` based alternative to classic Haskell\nlazy recursive prime sieve:\n  ```haskell\n  primes = sieve [2..]\n  sieve (p : xs) = p : sieve [x | x \u003c− xs, x ‘mod‘ p \u003e 0]\n  ```\n- `TrialDivsionSieve`: The modulus-based memoized approach of generating primes\nthat we all know and love.\n- `GenuineSieve`: Priority Queue based solution, true to the original Sieve of\nEratosthenes algorithm.\n\nThis crate provides the following sources:\n- `integer_candidates()`: Returns an iterator which yields the sequence 2, 3, 4, 5, 6, 7, …\n- `odds_with_2()`: Returns an iterator which yields the sequence 2, 3, 5, 7, 9, …\n- `SpinWheel::default()`: Iterator of monotonically increasing integers which are not\nmultiples of 2, 3, 5 and 7.\n\nMostly, we initialize a `sieve` with a `source` and start generating primes:\n\n```rust\nuse lazy_prime_sieve::{sieve::TrialDivisionSieve, source::odds_with_2};\n\n// print the first 10 primes\nTrialDivisionSieve::with_source(odds_with_2())\n  .take(10)\n  .for_each(|x| println!(\"{x}\"));\n```\n\nHowever, some sources start from a high number. So we need to chain the initial\nprimes:\n\n```rust\nuse lazy_prime_sieve::{source::SpinWheel, sieve::GenuineSieve};\n\n// starts from 11\nlet source = SpinWheel::default();\n\n// print the first 10 primes\n[2, 3, 5, 7]\n    .iter()\n    .cloned()\n    .chain(GenuineSieve::with_source(source))\n    .take(10)\n    .for_each(|x| println!(\"{x}\"));\n```\n\nRefer to the [documentation](https://docs.rs/lazy-prime-sieve/) for further\ndetails.\n\n## Benchmarks\n\n![prime-sieves-bench](https://raw.githubusercontent.com/arindas/lazy-prime-sieve/main/assets/lines.svg)\n\nThis benchmark shows the time taken by the different `(source, sieve)`\ncombinations (fmt: `\"{sieve}_with_{source}\"`) in this crate to generate a\ncertain number of primes. The `x-axis` shows the number of primes generated,\nwhile the `y-axis` shows the time taken.\n\nThe fastest combination is `GenuineSieve` with `SpinWheel::default()`. This is\nthe combination used by `lazy_prime_sieve::primes()`.\n\nSee the generated benchmark report [here](https://arindas.github.io/lazy-prime-sieve/criterion/report/index.html).\n\nThese benchmarks were run on an AMD Ryzen 7 x86_64 machine in WSL with 8 GB RAM\nallocated to WSL.\n\n## References\n\nThis crate heavily draws from the paper [The Genuine Sieve of\nEratosthenes](https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf). This\nrepository attempts to provide non-recursive lazy Rust iterator based\nalternatives to the Haskell lazy list + recursion based methods proposed in the\npaper.\n\n## License\n\n`lazy-prime-sieve` is licensed under the MIT License. See\n[License](https://raw.githubusercontent.com/arindas/lazy-prime-sieve/main/LICENSE)\nfor more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farindas%2Flazy-prime-sieve","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farindas%2Flazy-prime-sieve","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farindas%2Flazy-prime-sieve/lists"}