doc(structure): add doc
This commit is contained in:
parent
d42b01ff77
commit
f022ae9cbe
|
@ -0,0 +1,60 @@
|
||||||
|
### 结构体开发文档
|
||||||
|
|
||||||
|
#### 基础结构体开发
|
||||||
|
|
||||||
|
- 基础结构体放到 /pkg/structure。
|
||||||
|
|
||||||
|
- 每个结构 类型都以 x 结尾,如 listx, stringx。
|
||||||
|
|
||||||
|
- 在 pkg/structure/define.go 文件中添加对应结构体的接口,主要为 了保证项目可以扩展线程安全结构体, 以及结构体接口的实现, 目前 lru 采用 single 模式, 可以只开发 single 的结构体,如 stringxSingle。
|
||||||
|
|
||||||
|
- 请在结构体包中 补充单元测试。
|
||||||
|
|
||||||
|
#### 目前实现结构体接口说明
|
||||||
|
|
||||||
|
> ps: 所有的详细用法都可以查看单元测试文件。
|
||||||
|
|
||||||
|
```go
|
||||||
|
// stringx
|
||||||
|
type StringXInterface interface {
|
||||||
|
KeyBaseInterface
|
||||||
|
// 重新设置一个 值
|
||||||
|
Set(string) (string, UpdateLength)
|
||||||
|
// 获取值的 string 形式
|
||||||
|
Get() string
|
||||||
|
// 值自动增加 一个值,只对 float 和 string 有效
|
||||||
|
Add(int32) (string, error)
|
||||||
|
// 值自动增加 减少值,只对 float 和 string 有效
|
||||||
|
Reduce(int32) (string, error)
|
||||||
|
// 使用位图类型
|
||||||
|
Setbit(int32, bool) UpdateLength
|
||||||
|
Getbit(int32) (bool, error)
|
||||||
|
// 获取字符串的切片
|
||||||
|
Getrange(start, end int32) (string, error)
|
||||||
|
GetLength() int
|
||||||
|
}
|
||||||
|
|
||||||
|
// listx
|
||||||
|
type ListXInterface interface {
|
||||||
|
KeyBaseInterface
|
||||||
|
LPush(...string) UpdateLength
|
||||||
|
RPush(...string) UpdateLength
|
||||||
|
LPop(int) ([]string, UpdateLength)
|
||||||
|
RPop(int) ([]string, UpdateLength)
|
||||||
|
Index(int) (string, error)
|
||||||
|
// 插入一组数据, bool 类型表示是否右插(尾插),false 时采用左插(头插)
|
||||||
|
Insert(int, bool, ...string) (UpdateLength, error)
|
||||||
|
Length() int
|
||||||
|
// 切片, O(n)复杂度
|
||||||
|
Slice(start, end int) (UpdateLength, error)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### structure.Value 类型
|
||||||
|
- 结构体的数据区域全部使用 structure.Value 类型存储。
|
||||||
|
- structure.Value 主要实现了 sting, int64, float64 的存储接口。
|
||||||
|
- structure.Value 非常容易计算内存占用。
|
||||||
|
- structure.UpdateLength 指的是在进行某一个操作以后,内存大小的变化。
|
||||||
|
- 为了保证 lru 的存储效率,lru 不会去遍历全部的 key 来重新计算大小,而是根据 UpdateLength 来动态更新 lru 的大小,具体实现在 dao 中。
|
||||||
|
- structure.Value 类型的使用方法可以在 pkg/structure/value_test.go 中获取。
|
Loading…
Reference in New Issue