{"id":18498333,"url":"https://github.com/softdevteam/sparsevec","last_synced_at":"2025-10-07T10:25:14.392Z","repository":{"id":48065874,"uuid":"152113482","full_name":"softdevteam/sparsevec","owner":"softdevteam","description":"Compress sparse tables using row displacement","archived":false,"fork":false,"pushed_at":"2025-03-18T13:33:10.000Z","size":47,"stargazers_count":9,"open_issues_count":1,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-31T22:02:11.685Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/softdevteam.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","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":"2018-10-08T16:42:29.000Z","updated_at":"2025-03-18T13:33:13.000Z","dependencies_parsed_at":"2024-11-06T18:16:53.870Z","dependency_job_id":null,"html_url":"https://github.com/softdevteam/sparsevec","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.3571428571428571,"last_synced_commit":"b91291ffcba223fe8e1180d4c702ff3e7c49457a"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softdevteam%2Fsparsevec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softdevteam%2Fsparsevec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softdevteam%2Fsparsevec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softdevteam%2Fsparsevec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/softdevteam","download_url":"https://codeload.github.com/softdevteam/sparsevec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253673321,"owners_count":21945584,"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-06T13:38:47.265Z","updated_at":"2025-10-07T10:25:09.360Z","avatar_url":"https://github.com/softdevteam.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://api.travis-ci.org/softdevteam/sparsevec.svg?branch=master)](https://travis-ci.org/softdevteam/sparsevec)\n[![Latest version](https://img.shields.io/crates/v/sparsevec.svg)](https://crates.io/crates/sparsevec)\n[![Documentation](https://docs.rs/sparsevec/badge.svg)](https://docs.rs/sparsevec)\n\n# Sparse Vector (SparseVec)\n\nA SparseVec efficiently encodes a two-dimensional matrix of integers. The input\nmatrix must be encoded as a one-dimensional vector of integers with a\nrow-length. Given an empty value, the SparseVec uses row displacement as\ndescribed in [1] for the compression and encodes the result further using a\nPackedVec.\n\n[1] Tarjan, Robert Endre, and Andrew Chi-Chih Yao. \"Storing a sparse table.\"\nCommunications of the ACM 22.11 (1979): 606-611.\n\n# Usage\n\n```rust\nextern crate sparsevec;\nuse sparsevec::SparseVec;\n\nfn main() {\n    use sparsevec::SparseVec;\n    let v:Vec\u003cusize\u003e = vec![1,0,0,0,\n                            0,0,7,8,\n                            9,0,0,3];\n    let sv = SparseVec::from(\u0026v, 0, 4);\n    assert_eq!(sv.get(0,0).unwrap(), 1);\n    assert_eq!(sv.get(1,2).unwrap(), 7);\n    assert_eq!(sv.get(2,3).unwrap(), 3);\n}\n```\n\n# How it works\n\nThe following describes the general idea of row displacement for sparse\nvectors, excluding some additional optimisations from the implementation.\nLet's take as an example the two-dimensional vector\n```\n1 0 0\n2 0 0\n3 0 0\n0 0 4\n```\nrepresented as a one dimensional vector `v = [1,0,0,2,0,0,3,0,0,0,0,4]` with row-length 3.\nStoring this vector in memory is wasteful as the majority of its elements is 0. We can compress\nthis vector using row displacement, which merges all rows into a vector such that no two\nnon-zero entries are mapped to the same position. For the above example, this would result in\nthe compressed vector `c = [1,2,3,0,4]`:\n```\n1 0 0\n  2 0 0\n    3 0 0\n    0 0 4\n---------\n1 2 3 0 4\n```\nTo retrieve values from the compressed vector, we need a displacement vector, which\ndescribes how much each row was shifted during the compression. For the above example, the\ndisplacement vector would be `d = [0, 1, 2, 2]`. In order to retrieve the value at\nposition (2, 0), we can calculate its compressed position with `pos = d[row] + col`:\n```\npos = d[2] + 0 // =2\nvalue = c[pos] // =3\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftdevteam%2Fsparsevec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftdevteam%2Fsparsevec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftdevteam%2Fsparsevec/lists"}