https://github.com/chippyash/logicgate
Builds on [Kelindar's Bitmap library](github.com/kelindar/bitmap) to provide: - functional equivalents to the bitmap declarative methods - additional functions for some 'missing' methods - some utility functions that wouldn't make it into the Bitmap library
https://github.com/chippyash/logicgate
Last synced: about 1 month ago
JSON representation
Builds on [Kelindar's Bitmap library](github.com/kelindar/bitmap) to provide: - functional equivalents to the bitmap declarative methods - additional functions for some 'missing' methods - some utility functions that wouldn't make it into the Bitmap library
- Host: GitHub
- URL: https://github.com/chippyash/logicgate
- Owner: chippyash
- License: mit
- Created: 2023-09-26T05:03:08.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-09-29T13:28:09.000Z (over 2 years ago)
- Last Synced: 2025-03-03T17:18:03.913Z (over 1 year ago)
- Language: Go
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Logic Gates
## github.com/chippyash/logicgate
## What
Builds on [Kelindar's Bitmap library](github.com/kelindar/bitmap) to provide:
- functional equivalents to the bitmap declarative methods
- additional functions for some 'missing' methods
- some utility functions that wouldn't make it into the Bitmap library
## Why
To provide the ability to write code functionally using bitmaps. Parameters
to the functions are not changed, maintaining immutability.
To show that it is reasonably possible to take someone else's code and provide a different experience without harming
the originator.
Kelindar's Bitmap library allows for very large bitmaps. His primary use case is categorisation, for which bit maps
are a good candidate, particularly if you are trying to slim down your data storage. My use case was slightly different,
but Kelindar's Bitmap serves the purpose as a highly efficient implementation.
The `bit` that was missing was the ability to compare bitmaps.
## How
- Go 1.18+ The base version is dictated by the Bitmap library. This may change in the future.
- `import "github.com/chippyash/logicgate"`
- Read the unit tests to see how functions are used
- Run the examples/main.go program for example usage
### Bitmap functional equivalents
- func And(a, b bitmap.Bitmap) bitmap.Bitmap
- func Or(a, b bitmap.Bitmap) bitmap.Bitmap
- func Xor(a, b bitmap.Bitmap) bitmap.Bitmap
### Additional functions
- func Imply(a, b bitmap.Bitmap) bitmap.Bitmap
- func Nimply(a, b bitmap.Bitmap) bitmap.Bitmap
- func Nand(a, b bitmap.Bitmap) bitmap.Bitmap
- func Not(a bitmap.Bitmap) bitmap.Bitmap
- func Xnor(a, b bitmap.Bitmap) bitmap.Bitmap
### Utility functions
- func Compare(a, b bitmap.Bitmap) int
- func RangeAll(src bitmap.Bitmap, fn func(k uint32, v bool))
- func Trim(a bitmap.Bitmap, bitLen uint32) bitmap.Bitmap
### An example of what you can do
My first use for Bitmap was to categorise team games by the players in the team, the objective being to ensure that I
hadn't gotten the same players playing together too often. That's where I hit a roadblock with Bitmap, it had no comparator.
In a sense, this library is a response to that. But once down the rabbit hole, off we must go!
`examples/full_adder/main.go` is a purely contrived attempt to produce a bitmap oriented electronic circuit as described in
https://en.wikipedia.org/wiki/Adder_(electronics) It has no functional reason to exist, as there are far better ways to do
these things. It exists only as a demonstration of the art of the possible.
## Contributing
Feel free to submit a pull request to make changes or add functionality. Please ensure that
changes are accompanied by relevant unit tests. I am particularly interested in efficiency improvements
if you can make them, or edge cases if you find them, and of course `the art of the possible` as examples that others may
learn from.
I cannot fix issues in the dependency chain. Please refer to the authors of a dependency.
### Developing
- clone the repo
- `go get -u ./...`
## References
[Logic Gates](https://en.wikipedia.org/wiki/Logic_gate)
## License
The library is licensed under the [MIT License](LICENSE)