-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #653 from upper/refactor-memory-and-speed-optimiza…
…tions Memory and speed optimizations
Showing
54 changed files
with
1,177 additions
and
2,123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package cache | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/segmentio/fasthash/fnv1a" | ||
) | ||
|
||
const ( | ||
hashTypeInt uint64 = 1 << iota | ||
hashTypeSignedInt | ||
hashTypeBool | ||
hashTypeString | ||
hashTypeHashable | ||
hashTypeNil | ||
) | ||
|
||
type hasher struct { | ||
t uint64 | ||
v interface{} | ||
} | ||
|
||
func (h *hasher) Hash() uint64 { | ||
return NewHash(h.t, h.v) | ||
} | ||
|
||
func NewHashable(t uint64, v interface{}) Hashable { | ||
return &hasher{t: t, v: v} | ||
} | ||
|
||
func InitHash(t uint64) uint64 { | ||
return fnv1a.AddUint64(fnv1a.Init64, t) | ||
} | ||
|
||
func NewHash(t uint64, in ...interface{}) uint64 { | ||
return AddToHash(InitHash(t), in...) | ||
} | ||
|
||
func AddToHash(h uint64, in ...interface{}) uint64 { | ||
for i := range in { | ||
if in[i] == nil { | ||
continue | ||
} | ||
h = addToHash(h, in[i]) | ||
} | ||
return h | ||
} | ||
|
||
func addToHash(h uint64, in interface{}) uint64 { | ||
switch v := in.(type) { | ||
case uint64: | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeInt), v) | ||
case uint32: | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeInt), uint64(v)) | ||
case uint16: | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeInt), uint64(v)) | ||
case uint8: | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeInt), uint64(v)) | ||
case uint: | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeInt), uint64(v)) | ||
case int64: | ||
if v < 0 { | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeSignedInt), uint64(-v)) | ||
} else { | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeInt), uint64(v)) | ||
} | ||
case int32: | ||
if v < 0 { | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeSignedInt), uint64(-v)) | ||
} else { | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeInt), uint64(v)) | ||
} | ||
case int16: | ||
if v < 0 { | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeSignedInt), uint64(-v)) | ||
} else { | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeInt), uint64(v)) | ||
} | ||
case int8: | ||
if v < 0 { | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeSignedInt), uint64(-v)) | ||
} else { | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeInt), uint64(v)) | ||
} | ||
case int: | ||
if v < 0 { | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeSignedInt), uint64(-v)) | ||
} else { | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeInt), uint64(v)) | ||
} | ||
case bool: | ||
if v { | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeBool), 1) | ||
} else { | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeBool), 2) | ||
} | ||
case string: | ||
return fnv1a.AddString64(fnv1a.AddUint64(h, hashTypeString), v) | ||
case Hashable: | ||
if in == nil { | ||
panic(fmt.Sprintf("could not hash nil element %T", in)) | ||
} | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeHashable), v.Hash()) | ||
case nil: | ||
return fnv1a.AddUint64(fnv1a.AddUint64(h, hashTypeNil), 0) | ||
default: | ||
panic(fmt.Sprintf("unsupported value type %T", in)) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package exql | ||
|
||
const ( | ||
errExpectingHashableFmt = "expecting hashable value, got %T" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package exql | ||
|
||
const ( | ||
FragmentType_None uint64 = iota + 713910251627 | ||
|
||
FragmentType_And | ||
FragmentType_Column | ||
FragmentType_ColumnValue | ||
FragmentType_ColumnValues | ||
FragmentType_Columns | ||
FragmentType_Database | ||
FragmentType_GroupBy | ||
FragmentType_Join | ||
FragmentType_Joins | ||
FragmentType_Nil | ||
FragmentType_Or | ||
FragmentType_Limit | ||
FragmentType_Offset | ||
FragmentType_OrderBy | ||
FragmentType_Order | ||
FragmentType_Raw | ||
FragmentType_Returning | ||
FragmentType_SortBy | ||
FragmentType_SortColumn | ||
FragmentType_SortColumns | ||
FragmentType_Statement | ||
FragmentType_StatementType | ||
FragmentType_Table | ||
FragmentType_Value | ||
FragmentType_On | ||
FragmentType_Using | ||
FragmentType_ValueGroups | ||
FragmentType_Values | ||
FragmentType_Where | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.