1 Star 0 Fork 0

广州捷仓科技有限公司/gopdf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
map_of_character_To_glyph_index.go 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
package gopdf
//MapOfCharacterToGlyphIndex map of CharacterToGlyphIndex
type MapOfCharacterToGlyphIndex struct {
keyIndexs map[rune]int //for search index in keys
Keys []rune
Vals []uint
}
//NewMapOfCharacterToGlyphIndex new CharacterToGlyphIndex
func NewMapOfCharacterToGlyphIndex() *MapOfCharacterToGlyphIndex {
var m MapOfCharacterToGlyphIndex
m.keyIndexs = make(map[rune]int)
return &m
}
//KeyExists key is exists?
func (m *MapOfCharacterToGlyphIndex) KeyExists(k rune) bool {
/*for _, key := range m.Keys {
if k == key {
return true
}
}*/
if _, ok := m.keyIndexs[k]; ok {
return true
}
return false
}
//Set set key and value to map
func (m *MapOfCharacterToGlyphIndex) Set(k rune, v uint) {
m.keyIndexs[k] = len(m.Keys)
m.Keys = append(m.Keys, k)
m.Vals = append(m.Vals, v)
}
//Index get index by key
func (m *MapOfCharacterToGlyphIndex) Index(k rune) (int, bool) {
/*for i, key := range m.Keys {
if k == key {
return i, true
}
}*/
if index, ok := m.keyIndexs[k]; ok {
return index, true
}
return -1, false
}
//Val get value by Key
func (m *MapOfCharacterToGlyphIndex) Val(k rune) (uint, bool) {
i, ok := m.Index(k)
if !ok {
return 0, false
}
return m.Vals[i], true
}
//AllKeys get keys
func (m *MapOfCharacterToGlyphIndex) AllKeys() []rune {
return m.Keys
}
//AllVals get all values
func (m *MapOfCharacterToGlyphIndex) AllVals() []uint {
return m.Vals
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jiecang-tech/gopdf.git
git@gitee.com:jiecang-tech/gopdf.git
jiecang-tech
gopdf
gopdf
v0.8.0

搜索帮助