Current section

Files

Jump to
memory README.md
Raw

README.md

# memory
添加了LRU缓存淘汰。
rec模块为了缓存每次递归的结果牺牲了尾递归优化,所以移除了它。
[![Package Version](https://img.shields.io/hexpm/v/memory)](https://hex.pm/packages/memory)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://memory.hexdocs.pm/)
```sh
gleam add memory
```
```gleam
import memory
pub fn factorial(i: Int) -> Int {
factorial_loop(i, i)
}
fn factorial_loop(i: Int, acc: Int) -> Int {
case i {
0 | 1 -> acc
_ -> factorial_loop(i - 1, acc * { i - 1 })
}
}
pub fn main() -> Nil {
let assert Ok(factorial) = memory.new(factorial, 10)
}
```
## Development
```sh
gleam run # Run the project
gleam test # Run the tests
```