2024-12-05 01:27:49 +00:00
|
|
|
package model
|
|
|
|
|
2024-12-17 23:57:29 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
2024-12-18 23:22:23 +00:00
|
|
|
"strconv"
|
2024-12-17 23:57:29 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/dchest/siphash"
|
|
|
|
)
|
|
|
|
|
2024-12-18 23:22:23 +00:00
|
|
|
// compute the hash of a source code string
|
2024-12-17 23:57:29 +00:00
|
|
|
func HashSource(source string) uint64{
|
|
|
|
return siphash.Hash(0, 0, []byte(source))
|
|
|
|
}
|
|
|
|
|
2024-12-18 23:22:23 +00:00
|
|
|
// format a hash value as a hexidecimal string
|
2024-12-17 23:57:29 +00:00
|
|
|
func HashFormat(hash uint64) string{
|
|
|
|
return fmt.Sprintf("%016x", hash)
|
|
|
|
}
|
2024-12-10 06:27:52 +00:00
|
|
|
|
2024-12-18 23:22:23 +00:00
|
|
|
// parse a hexidecimal hash string
|
|
|
|
func HashParse(hash string) (uint64, error){
|
|
|
|
return strconv.ParseUint(hash, 16, 64)
|
|
|
|
}
|
|
|
|
|
2024-12-05 01:27:49 +00:00
|
|
|
type Script struct {
|
2024-12-12 22:29:20 +00:00
|
|
|
ID int64 `gorm:"primaryKey"`
|
2024-12-14 20:31:31 +00:00
|
|
|
Name string
|
2024-12-12 22:29:20 +00:00
|
|
|
Hash uint64
|
|
|
|
Source string
|
|
|
|
SubmissionID int64 // which submission did this script first appear in
|
|
|
|
CreatedAt time.Time
|
|
|
|
UpdatedAt time.Time
|
2024-12-05 01:27:49 +00:00
|
|
|
}
|