https://github.com/andrewcodedev/random_access
https://github.com/andrewcodedev/random_access
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/andrewcodedev/random_access
- Owner: andrewCodeDev
- Created: 2024-07-26T16:06:51.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-26T16:42:39.000Z (almost 2 years ago)
- Last Synced: 2025-04-02T05:56:11.112Z (about 1 year ago)
- Language: Zig
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This is a simple type that enables pointer arithmetic on raw addresses in a type safe way.
Use file as direct import:
```zig
const ra = @import("random_access.zig");
```
Create address objects from pointers:
```zig
// requires one-item, many-item, or c-style pointers
var addr = ra.init(slice.ptr);
// move up by one element
addr.add(1);
// move back by one element
addr.sub(1);
// get one-item pointer:
const ptr = addr.one();
// set value with one-item ptr:
addr.one().* = 42;
// get many-item pointer:
const mptr = addr.many();
// pointer comparisons:
addr1.lt(addr2); // less than
addr1.gt(addr2); // greater than
addr1.lte(addr2); // less than or equal to
addr1.gte(addr2); // greater than or equal to
addr1.eql(addr2); // equal to
// use with loops:
while (addr1.lt(addr2)) : (addr1.add(1)) {
// ...
}
```