Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimize stringmap and add faststringmap #11

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ type Variant struct {
StructSuffix string
ExtraFileds string

// For fast string only.
// These fields are empty for other types.
FSHashResult string // hash := strhash(key)
FSHashResultS string // hash = strhash(key)
FSHashField string // hash uint64
FSHashFieldAssign string // hash : 0,
FSHashParameter string // hash uint64,
FSHashArgument string // hash,

// Basic key and value type.
KeyType string
ValueType string
Expand Down Expand Up @@ -178,6 +187,50 @@ func main() {
generate(baseType)
generate(baseTypeDesc)
}

// For NewStringFast.
fv := &Variant{
Package: "skipmap",
Name: "stringfast",
Path: "gen_stringfast.go",
Imports: "\"sync\"\n\"sync/atomic\"\n\"unsafe\"\n",
KeyType: "string",
ValueType: "valueT",
TypeArgument: "[valueT]",
TypeParam: "[valueT any]",
StructPrefix: "String",
StructPrefixLow: "string",
StructSuffix: "Fast",

FSHashResult: "hash := strhash(key)",
FSHashResultS: "hash = strhash(key)",
FSHashField: "hash uint64",
FSHashFieldAssign: "hash : hash,",
FSHashParameter: "hash uint64,",
FSHashArgument: "hash,",

Funcs: template.FuncMap{
"Less": func(i, j string) string {
// succ.key < key
// =>
// succ.hash < hash
i = strings.ReplaceAll(i, "key", "hash")
j = strings.ReplaceAll(j, "key", "hash")
return fmt.Sprintf("(%s < %s)", i, j)
},
"Equal": func(i, j string) string {
// succ.key == key
// =>
// succ.hash == hash && succ.key == key
cond2 := fmt.Sprintf("%s == %s", i, j)
i = strings.ReplaceAll(i, "key", "hash")
j = strings.ReplaceAll(j, "key", "hash")
cond1 := fmt.Sprintf("%s == %s", i, j)
return fmt.Sprintf("%s && %s", cond1, cond2)
},
},
}
generate(fv)
}

// generate generates the code for variant `v` into a file named by `v.Path`.
Expand Down
10 changes: 7 additions & 3 deletions gen_func.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions gen_int.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions gen_int32.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions gen_int32desc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions gen_int64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions gen_int64desc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions gen_intdesc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading