Bitwise operations in expressions for flag checking
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
## Motivation
With machine generated geojson it's more space saving to store up to 32 flags in a single integer value.
## Design Alternatives
The only alternative is to store boolean properties for each flag, which creates unnecessary overhead and requires us to write a boolean check expression for each flag instead of checking for multiple flags only once with an _and_ operation.
```
"properties": {
"type1": true,
"type2": false,
"type3": true,
...
}
```
Right now for each flag I want to check inside an integer I have to create an expression, which shifts the bit to the right with a division by powers of 2 and _modulo 2_ to extract the bit for the _flag == 1_ check
`['==', ['%', ['floor', ['/', ["get", "location-type"], 1<
With bitwise operators we could do a check for multiple flags within a simple _and_ operation:
`['&', ["get", "location-type"], 0b10101]`
### Implementation
So for the flag checking use case it would be enough to have the & operator expression or labelled as 'hasFlags' expression.
But you could also just add all bitwise operators to the math expressions as
- `'&'` and
- `'xor'` because ^ is already in use
- `'not'` because ! is already in use
- `'|'` or
- `'<<'` left shift
- `'>>'` right shift
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue does not name implementation files, tests, or an entry point. Start by locating the expression implementation and existing math-expression tests, then determine whether the scope is a single flag-checking operator or the proposed set of bitwise operators; done should include the agreed operator behavior and coverage for it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100