repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
GoogleContainerTools/container-diff
differs/rpm_diff.go
Analyze
func (a RPMAnalyzer) Analyze(image pkgutil.Image) (util.Result, error) { analysis, err := singleVersionAnalysis(image, a) return analysis, err }
go
func (a RPMAnalyzer) Analyze(image pkgutil.Image) (util.Result, error) { analysis, err := singleVersionAnalysis(image, a) return analysis, err }
[ "func", "(", "a", "RPMAnalyzer", ")", "Analyze", "(", "image", "pkgutil", ".", "Image", ")", "(", "util", ".", "Result", ",", "error", ")", "{", "analysis", ",", "err", ":=", "singleVersionAnalysis", "(", "image", ",", "a", ")", "\n", "return", "analys...
// Analyze collects information of the installed rpm packages on image.
[ "Analyze", "collects", "information", "of", "the", "installed", "rpm", "packages", "on", "image", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/rpm_diff.go#L79-L82
train
GoogleContainerTools/container-diff
differs/rpm_diff.go
getPackages
func (a RPMAnalyzer) getPackages(image pkgutil.Image) (map[string]util.PackageInfo, error) { path := image.FSPath packages := make(map[string]util.PackageInfo) if _, err := os.Stat(path); err != nil { // invalid image directory path return packages, err } // try to find the rpm binary in bin/ or usr/bin/ rpm...
go
func (a RPMAnalyzer) getPackages(image pkgutil.Image) (map[string]util.PackageInfo, error) { path := image.FSPath packages := make(map[string]util.PackageInfo) if _, err := os.Stat(path); err != nil { // invalid image directory path return packages, err } // try to find the rpm binary in bin/ or usr/bin/ rpm...
[ "func", "(", "a", "RPMAnalyzer", ")", "getPackages", "(", "image", "pkgutil", ".", "Image", ")", "(", "map", "[", "string", "]", "util", ".", "PackageInfo", ",", "error", ")", "{", "path", ":=", "image", ".", "FSPath", "\n", "packages", ":=", "make", ...
// getPackages returns a map of installed rpm package on image.
[ "getPackages", "returns", "a", "map", "of", "installed", "rpm", "package", "on", "image", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/rpm_diff.go#L85-L109
train
GoogleContainerTools/container-diff
differs/rpm_diff.go
rpmDataFromImageFS
func rpmDataFromImageFS(image pkgutil.Image) (map[string]util.PackageInfo, error) { dbPath, err := rpmEnvCheck(image.FSPath) if err != nil { logrus.Warnf("Couldn't find RPM database: %s", err.Error()) return nil, err } return rpmDataFromFS(image.FSPath, dbPath) }
go
func rpmDataFromImageFS(image pkgutil.Image) (map[string]util.PackageInfo, error) { dbPath, err := rpmEnvCheck(image.FSPath) if err != nil { logrus.Warnf("Couldn't find RPM database: %s", err.Error()) return nil, err } return rpmDataFromFS(image.FSPath, dbPath) }
[ "func", "rpmDataFromImageFS", "(", "image", "pkgutil", ".", "Image", ")", "(", "map", "[", "string", "]", "util", ".", "PackageInfo", ",", "error", ")", "{", "dbPath", ",", "err", ":=", "rpmEnvCheck", "(", "image", ".", "FSPath", ")", "\n", "if", "err"...
// rpmDataFromImageFS runs a local rpm binary, if any, to query the image // rpmdb and returns a map of installed packages.
[ "rpmDataFromImageFS", "runs", "a", "local", "rpm", "binary", "if", "any", "to", "query", "the", "image", "rpmdb", "and", "returns", "a", "map", "of", "installed", "packages", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/rpm_diff.go#L113-L120
train
GoogleContainerTools/container-diff
differs/rpm_diff.go
rpmDataFromContainer
func rpmDataFromContainer(image v1.Image) (map[string]util.PackageInfo, error) { packages := make(map[string]util.PackageInfo) client, err := godocker.NewClientFromEnv() if err != nil { return packages, err } if err := lock(); err != nil { return packages, err } imageName, err := loadImageToDaemon(image) ...
go
func rpmDataFromContainer(image v1.Image) (map[string]util.PackageInfo, error) { packages := make(map[string]util.PackageInfo) client, err := godocker.NewClientFromEnv() if err != nil { return packages, err } if err := lock(); err != nil { return packages, err } imageName, err := loadImageToDaemon(image) ...
[ "func", "rpmDataFromContainer", "(", "image", "v1", ".", "Image", ")", "(", "map", "[", "string", "]", "util", ".", "PackageInfo", ",", "error", ")", "{", "packages", ":=", "make", "(", "map", "[", "string", "]", "util", ".", "PackageInfo", ")", "\n\n"...
// rpmDataFromContainer runs image in a container, queries the data of // installed rpm packages and returns a map of packages.
[ "rpmDataFromContainer", "runs", "image", "in", "a", "container", "queries", "the", "data", "of", "installed", "rpm", "packages", "and", "returns", "a", "map", "of", "packages", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/rpm_diff.go#L161-L233
train
GoogleContainerTools/container-diff
differs/rpm_diff.go
parsePackageData
func parsePackageData(rpmOutput []string) (map[string]util.PackageInfo, error) { packages := make(map[string]util.PackageInfo) for _, output := range rpmOutput { spl := strings.Split(output, "\t") if len(spl) != 3 { // ignore the empty (last) line if output != "" { logrus.Errorf("unexpected rpm-query o...
go
func parsePackageData(rpmOutput []string) (map[string]util.PackageInfo, error) { packages := make(map[string]util.PackageInfo) for _, output := range rpmOutput { spl := strings.Split(output, "\t") if len(spl) != 3 { // ignore the empty (last) line if output != "" { logrus.Errorf("unexpected rpm-query o...
[ "func", "parsePackageData", "(", "rpmOutput", "[", "]", "string", ")", "(", "map", "[", "string", "]", "util", ".", "PackageInfo", ",", "error", ")", "{", "packages", ":=", "make", "(", "map", "[", "string", "]", "util", ".", "PackageInfo", ")", "\n\n"...
// parsePackageData parses the package data of each line in rpmOutput and // returns a map of packages.
[ "parsePackageData", "parses", "the", "package", "data", "of", "each", "line", "in", "rpmOutput", "and", "returns", "a", "map", "of", "packages", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/rpm_diff.go#L237-L262
train
GoogleContainerTools/container-diff
differs/rpm_diff.go
loadImageToDaemon
func loadImageToDaemon(img v1.Image) (string, error) { tag := generateValidImageTag() resp, err := daemon.Write(tag, img) if err != nil { return "", err } logrus.Infof("daemon response: %s", resp) return tag.Name(), nil }
go
func loadImageToDaemon(img v1.Image) (string, error) { tag := generateValidImageTag() resp, err := daemon.Write(tag, img) if err != nil { return "", err } logrus.Infof("daemon response: %s", resp) return tag.Name(), nil }
[ "func", "loadImageToDaemon", "(", "img", "v1", ".", "Image", ")", "(", "string", ",", "error", ")", "{", "tag", ":=", "generateValidImageTag", "(", ")", "\n", "resp", ",", "err", ":=", "daemon", ".", "Write", "(", "tag", ",", "img", ")", "\n", "if", ...
// loadImageToDaemon loads the image specified to the docker daemon.
[ "loadImageToDaemon", "loads", "the", "image", "specified", "to", "the", "docker", "daemon", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/rpm_diff.go#L265-L273
train
GoogleContainerTools/container-diff
differs/rpm_diff.go
generateValidImageTag
func generateValidImageTag() name.Tag { var tag name.Tag var err error var i int b := make([]rune, 12) for { for i = 0; i < len(b); i++ { b[i] = letters[rand.Intn(len(letters))] } tag, err = name.NewTag("rpm_test_image:"+string(b), name.WeakValidation) if err != nil { logrus.Warn(err.Error()) cont...
go
func generateValidImageTag() name.Tag { var tag name.Tag var err error var i int b := make([]rune, 12) for { for i = 0; i < len(b); i++ { b[i] = letters[rand.Intn(len(letters))] } tag, err = name.NewTag("rpm_test_image:"+string(b), name.WeakValidation) if err != nil { logrus.Warn(err.Error()) cont...
[ "func", "generateValidImageTag", "(", ")", "name", ".", "Tag", "{", "var", "tag", "name", ".", "Tag", "\n", "var", "err", "error", "\n", "var", "i", "int", "\n", "b", ":=", "make", "(", "[", "]", "rune", ",", "12", ")", "\n", "for", "{", "for", ...
// generate random image name until we find one that isn't in use
[ "generate", "random", "image", "name", "until", "we", "find", "one", "that", "isn", "t", "in", "use" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/rpm_diff.go#L276-L296
train
GoogleContainerTools/container-diff
differs/rpm_diff.go
getLockfile
func getLockfile() (lockfile.Lockfile, error) { lockPath := filepath.Join(os.TempDir(), ".containerdiff.lock") lock, err := lockfile.New(lockPath) if err != nil { return lock, err } return lock, nil }
go
func getLockfile() (lockfile.Lockfile, error) { lockPath := filepath.Join(os.TempDir(), ".containerdiff.lock") lock, err := lockfile.New(lockPath) if err != nil { return lock, err } return lock, nil }
[ "func", "getLockfile", "(", ")", "(", "lockfile", ".", "Lockfile", ",", "error", ")", "{", "lockPath", ":=", "filepath", ".", "Join", "(", "os", ".", "TempDir", "(", ")", ",", "\"", "\"", ")", "\n", "lock", ",", "err", ":=", "lockfile", ".", "New",...
// unlock returns the containerdiff file-system lock. It is placed in the // system's temporary directory to make sure it's accessible for all users in // the system; no root required.
[ "unlock", "returns", "the", "containerdiff", "file", "-", "system", "lock", ".", "It", "is", "placed", "in", "the", "system", "s", "temporary", "directory", "to", "make", "sure", "it", "s", "accessible", "for", "all", "users", "in", "the", "system", ";", ...
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/rpm_diff.go#L301-L308
train
GoogleContainerTools/container-diff
differs/rpm_diff.go
lock
func lock() error { var err error var lock lockfile.Lockfile daemonMutex.Lock() lock, err = getLockfile() if err != nil { daemonMutex.Unlock() return fmt.Errorf("[lock] cannot init lockfile: %v", err) } // Try to acquire the lock and in case of a temporary error, sleep for // two seconds until the next re...
go
func lock() error { var err error var lock lockfile.Lockfile daemonMutex.Lock() lock, err = getLockfile() if err != nil { daemonMutex.Unlock() return fmt.Errorf("[lock] cannot init lockfile: %v", err) } // Try to acquire the lock and in case of a temporary error, sleep for // two seconds until the next re...
[ "func", "lock", "(", ")", "error", "{", "var", "err", "error", "\n", "var", "lock", "lockfile", ".", "Lockfile", "\n\n", "daemonMutex", ".", "Lock", "(", ")", "\n", "lock", ",", "err", "=", "getLockfile", "(", ")", "\n", "if", "err", "!=", "nil", "...
// lock acquires the containerdiff file-system lock.
[ "lock", "acquires", "the", "containerdiff", "file", "-", "system", "lock", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/rpm_diff.go#L311-L344
train
GoogleContainerTools/container-diff
differs/rpm_diff.go
unlock
func unlock() error { lock, err := getLockfile() if err != nil { return fmt.Errorf("[unlock] cannot init lockfile: %v", err) } err = lock.Unlock() if err != nil { return fmt.Errorf("[unlock] error releasing lock: %s", err) } logrus.Debugf("[unlock] lock released") daemonMutex.Unlock() return nil }
go
func unlock() error { lock, err := getLockfile() if err != nil { return fmt.Errorf("[unlock] cannot init lockfile: %v", err) } err = lock.Unlock() if err != nil { return fmt.Errorf("[unlock] error releasing lock: %s", err) } logrus.Debugf("[unlock] lock released") daemonMutex.Unlock() return nil }
[ "func", "unlock", "(", ")", "error", "{", "lock", ",", "err", ":=", "getLockfile", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "err", "=", "lock", ".", "Unloc...
// unlock releases the containerdiff file-system lock. Note that errors can be // ignored as there's no meaningful way to recover.
[ "unlock", "releases", "the", "containerdiff", "file", "-", "system", "lock", ".", "Note", "that", "errors", "can", "be", "ignored", "as", "there", "s", "no", "meaningful", "way", "to", "recover", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/rpm_diff.go#L348-L360
train
GoogleContainerTools/container-diff
differs/rpm_diff.go
getPackages
func (a RPMLayerAnalyzer) getPackages(image pkgutil.Image) ([]map[string]util.PackageInfo, error) { path := image.FSPath var packages []map[string]util.PackageInfo if _, err := os.Stat(path); err != nil { // invalid image directory path return packages, err } // try to find the rpm binary in bin/ or usr/bin/ ...
go
func (a RPMLayerAnalyzer) getPackages(image pkgutil.Image) ([]map[string]util.PackageInfo, error) { path := image.FSPath var packages []map[string]util.PackageInfo if _, err := os.Stat(path); err != nil { // invalid image directory path return packages, err } // try to find the rpm binary in bin/ or usr/bin/ ...
[ "func", "(", "a", "RPMLayerAnalyzer", ")", "getPackages", "(", "image", "pkgutil", ".", "Image", ")", "(", "[", "]", "map", "[", "string", "]", "util", ".", "PackageInfo", ",", "error", ")", "{", "path", ":=", "image", ".", "FSPath", "\n", "var", "pa...
// getPackages returns an array of maps of installed rpm packages on each layer
[ "getPackages", "returns", "an", "array", "of", "maps", "of", "installed", "rpm", "packages", "on", "each", "layer" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/rpm_diff.go#L383-L407
train
GoogleContainerTools/container-diff
differs/rpm_diff.go
rpmDataFromLayerFS
func rpmDataFromLayerFS(image pkgutil.Image) ([]map[string]util.PackageInfo, error) { var packages []map[string]util.PackageInfo dbPath, err := rpmEnvCheck(image.FSPath) if err != nil { logrus.Warnf("Couldn't find RPM database: %s", err.Error()) return packages, err } for _, layer := range image.Layers { lay...
go
func rpmDataFromLayerFS(image pkgutil.Image) ([]map[string]util.PackageInfo, error) { var packages []map[string]util.PackageInfo dbPath, err := rpmEnvCheck(image.FSPath) if err != nil { logrus.Warnf("Couldn't find RPM database: %s", err.Error()) return packages, err } for _, layer := range image.Layers { lay...
[ "func", "rpmDataFromLayerFS", "(", "image", "pkgutil", ".", "Image", ")", "(", "[", "]", "map", "[", "string", "]", "util", ".", "PackageInfo", ",", "error", ")", "{", "var", "packages", "[", "]", "map", "[", "string", "]", "util", ".", "PackageInfo", ...
// rpmDataFromLayerFS runs a local rpm binary, if any, to query the layer // rpmdb and returns an array of maps of installed packages.
[ "rpmDataFromLayerFS", "runs", "a", "local", "rpm", "binary", "if", "any", "to", "query", "the", "layer", "rpmdb", "and", "returns", "an", "array", "of", "maps", "of", "installed", "packages", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/rpm_diff.go#L411-L427
train
GoogleContainerTools/container-diff
differs/rpm_diff.go
rpmDataFromFS
func rpmDataFromFS(fsPath string, dbPath string) (map[string]util.PackageInfo, error) { packages := make(map[string]util.PackageInfo) if _, err := os.Stat(filepath.Join(fsPath, dbPath)); err == nil { cmdArgs := append([]string{"--root", fsPath, "--dbpath", dbPath}, rpmCmd[1:]...) out, err := exec.Command(rpmCmd[0...
go
func rpmDataFromFS(fsPath string, dbPath string) (map[string]util.PackageInfo, error) { packages := make(map[string]util.PackageInfo) if _, err := os.Stat(filepath.Join(fsPath, dbPath)); err == nil { cmdArgs := append([]string{"--root", fsPath, "--dbpath", dbPath}, rpmCmd[1:]...) out, err := exec.Command(rpmCmd[0...
[ "func", "rpmDataFromFS", "(", "fsPath", "string", ",", "dbPath", "string", ")", "(", "map", "[", "string", "]", "util", ".", "PackageInfo", ",", "error", ")", "{", "packages", ":=", "make", "(", "map", "[", "string", "]", "util", ".", "PackageInfo", ")...
// rpmDataFromFS runs a local rpm binary to query the image // rpmdb and returns a map of installed packages.
[ "rpmDataFromFS", "runs", "a", "local", "rpm", "binary", "to", "query", "the", "image", "rpmdb", "and", "returns", "a", "map", "of", "installed", "packages", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/rpm_diff.go#L431-L447
train
GoogleContainerTools/container-diff
differs/rpm_diff.go
rpmDataFromLayeredContainers
func rpmDataFromLayeredContainers(image v1.Image) ([]map[string]util.PackageInfo, error) { var packages []map[string]util.PackageInfo tmpImage, err := random.Image(0, 0) if err != nil { return packages, err } layers, err := image.Layers() if err != nil { return packages, err } // Append layers one by one to...
go
func rpmDataFromLayeredContainers(image v1.Image) ([]map[string]util.PackageInfo, error) { var packages []map[string]util.PackageInfo tmpImage, err := random.Image(0, 0) if err != nil { return packages, err } layers, err := image.Layers() if err != nil { return packages, err } // Append layers one by one to...
[ "func", "rpmDataFromLayeredContainers", "(", "image", "v1", ".", "Image", ")", "(", "[", "]", "map", "[", "string", "]", "util", ".", "PackageInfo", ",", "error", ")", "{", "var", "packages", "[", "]", "map", "[", "string", "]", "util", ".", "PackageIn...
// rpmDataFromLayeredContainers runs a tmp image in a container for each layer, // queries the data of installed rpm packages and returns an array of maps of // packages.
[ "rpmDataFromLayeredContainers", "runs", "a", "tmp", "image", "in", "a", "container", "for", "each", "layer", "queries", "the", "data", "of", "installed", "rpm", "packages", "and", "returns", "an", "array", "of", "maps", "of", "packages", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/rpm_diff.go#L452-L477
train
GoogleContainerTools/container-diff
cmd/util/output/output.go
PrintToStdErr
func PrintToStdErr(output string, vars ...interface{}) { if !quiet { fmt.Fprintf(os.Stderr, output, vars...) } }
go
func PrintToStdErr(output string, vars ...interface{}) { if !quiet { fmt.Fprintf(os.Stderr, output, vars...) } }
[ "func", "PrintToStdErr", "(", "output", "string", ",", "vars", "...", "interface", "{", "}", ")", "{", "if", "!", "quiet", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "output", ",", "vars", "...", ")", "\n", "}", "\n", "}" ]
// PrintToStdErr prints to stderr if quiet flag isn't enabled
[ "PrintToStdErr", "prints", "to", "stderr", "if", "quiet", "flag", "isn", "t", "enabled" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/cmd/util/output/output.go#L28-L32
train
GoogleContainerTools/container-diff
differs/pip_diff.go
Diff
func (a PipAnalyzer) Diff(image1, image2 pkgutil.Image) (util.Result, error) { diff, err := multiVersionDiff(image1, image2, a) return diff, err }
go
func (a PipAnalyzer) Diff(image1, image2 pkgutil.Image) (util.Result, error) { diff, err := multiVersionDiff(image1, image2, a) return diff, err }
[ "func", "(", "a", "PipAnalyzer", ")", "Diff", "(", "image1", ",", "image2", "pkgutil", ".", "Image", ")", "(", "util", ".", "Result", ",", "error", ")", "{", "diff", ",", "err", ":=", "multiVersionDiff", "(", "image1", ",", "image2", ",", "a", ")", ...
// PipDiff compares pip-installed Python packages between layers of two different images.
[ "PipDiff", "compares", "pip", "-", "installed", "Python", "packages", "between", "layers", "of", "two", "different", "images", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/pip_diff.go#L40-L43
train
GoogleContainerTools/container-diff
util/package_diff_utils.go
GetMapDiff
func GetMapDiff(map1, map2 map[string]PackageInfo) PackageDiff { diff := diffMaps(map1, map2) diffVal := reflect.ValueOf(diff) packDiff := diffVal.Interface().(PackageDiff) return packDiff }
go
func GetMapDiff(map1, map2 map[string]PackageInfo) PackageDiff { diff := diffMaps(map1, map2) diffVal := reflect.ValueOf(diff) packDiff := diffVal.Interface().(PackageDiff) return packDiff }
[ "func", "GetMapDiff", "(", "map1", ",", "map2", "map", "[", "string", "]", "PackageInfo", ")", "PackageDiff", "{", "diff", ":=", "diffMaps", "(", "map1", ",", "map2", ")", "\n", "diffVal", ":=", "reflect", ".", "ValueOf", "(", "diff", ")", "\n", "packD...
// GetMapDiff determines the differences between maps of package names to PackageInfo structs // This getter supports only single version packages.
[ "GetMapDiff", "determines", "the", "differences", "between", "maps", "of", "package", "names", "to", "PackageInfo", "structs", "This", "getter", "supports", "only", "single", "version", "packages", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/util/package_diff_utils.go#L118-L123
train
GoogleContainerTools/container-diff
util/package_diff_utils.go
GetMultiVersionMapDiff
func GetMultiVersionMapDiff(map1, map2 map[string]map[string]PackageInfo) MultiVersionPackageDiff { diff := diffMaps(map1, map2) diffVal := reflect.ValueOf(diff) packDiff := diffVal.Interface().(MultiVersionPackageDiff) return packDiff }
go
func GetMultiVersionMapDiff(map1, map2 map[string]map[string]PackageInfo) MultiVersionPackageDiff { diff := diffMaps(map1, map2) diffVal := reflect.ValueOf(diff) packDiff := diffVal.Interface().(MultiVersionPackageDiff) return packDiff }
[ "func", "GetMultiVersionMapDiff", "(", "map1", ",", "map2", "map", "[", "string", "]", "map", "[", "string", "]", "PackageInfo", ")", "MultiVersionPackageDiff", "{", "diff", ":=", "diffMaps", "(", "map1", ",", "map2", ")", "\n", "diffVal", ":=", "reflect", ...
// GetMultiVersionMapDiff determines the differences between two image package maps with multi-version packages // This getter supports multi version packages.
[ "GetMultiVersionMapDiff", "determines", "the", "differences", "between", "two", "image", "package", "maps", "with", "multi", "-", "version", "packages", "This", "getter", "supports", "multi", "version", "packages", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/util/package_diff_utils.go#L127-L132
train
GoogleContainerTools/container-diff
util/package_diff_utils.go
BuildLayerTargets
func BuildLayerTargets(path, target string) ([]string, error) { layerStems := []string{} layers, err := ioutil.ReadDir(path) if err != nil { return layerStems, err } for _, layer := range layers { if layer.IsDir() { layerStems = append(layerStems, filepath.Join(path, layer.Name(), target)) } } return la...
go
func BuildLayerTargets(path, target string) ([]string, error) { layerStems := []string{} layers, err := ioutil.ReadDir(path) if err != nil { return layerStems, err } for _, layer := range layers { if layer.IsDir() { layerStems = append(layerStems, filepath.Join(path, layer.Name(), target)) } } return la...
[ "func", "BuildLayerTargets", "(", "path", ",", "target", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "layerStems", ":=", "[", "]", "string", "{", "}", "\n", "layers", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "path", ")", ...
// BuildLayerTargets creates a string slice of the layers found at path with the target concatenated.
[ "BuildLayerTargets", "creates", "a", "string", "slice", "of", "the", "layers", "found", "at", "path", "with", "the", "target", "concatenated", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/util/package_diff_utils.go#L197-L209
train
GoogleContainerTools/container-diff
cmd/diff.go
processImage
func processImage(imageName string, errChan chan<- error) *pkgutil.Image { image, err := getImage(imageName) if err != nil { errChan <- fmt.Errorf("error retrieving image %s: %s", imageName, err) } return &image }
go
func processImage(imageName string, errChan chan<- error) *pkgutil.Image { image, err := getImage(imageName) if err != nil { errChan <- fmt.Errorf("error retrieving image %s: %s", imageName, err) } return &image }
[ "func", "processImage", "(", "imageName", "string", ",", "errChan", "chan", "<-", "error", ")", "*", "pkgutil", ".", "Image", "{", "image", ",", "err", ":=", "getImage", "(", "imageName", ")", "\n", "if", "err", "!=", "nil", "{", "errChan", "<-", "fmt"...
// processImage is a concurrency-friendly wrapper around getImageForName
[ "processImage", "is", "a", "concurrency", "-", "friendly", "wrapper", "around", "getImageForName" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/cmd/diff.go#L74-L80
train
GoogleContainerTools/container-diff
cmd/diff.go
readErrorsFromChannel
func readErrorsFromChannel(c chan error) error { errs := []string{} for { err, ok := <-c if !ok { break } errs = append(errs, err.Error()) } if len(errs) > 0 { return errors.New(strings.Join(errs, "\n")) } return nil }
go
func readErrorsFromChannel(c chan error) error { errs := []string{} for { err, ok := <-c if !ok { break } errs = append(errs, err.Error()) } if len(errs) > 0 { return errors.New(strings.Join(errs, "\n")) } return nil }
[ "func", "readErrorsFromChannel", "(", "c", "chan", "error", ")", "error", "{", "errs", ":=", "[", "]", "string", "{", "}", "\n", "for", "{", "err", ",", "ok", ":=", "<-", "c", "\n", "if", "!", "ok", "{", "break", "\n", "}", "\n", "errs", "=", "...
// collects errors from a channel and combines them // assumes channel has already been closed
[ "collects", "errors", "from", "a", "channel", "and", "combines", "them", "assumes", "channel", "has", "already", "been", "closed" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/cmd/diff.go#L84-L98
train
GoogleContainerTools/container-diff
differs/size_diff.go
Diff
func (a SizeAnalyzer) Diff(image1, image2 pkgutil.Image) (util.Result, error) { diff := []util.SizeDiff{} size1 := pkgutil.GetSize(image1.FSPath) size2 := pkgutil.GetSize(image2.FSPath) if size1 != size2 { diff = append(diff, util.SizeDiff{ Size1: size1, Size2: size2, }) } return &util.SizeDiffResult{...
go
func (a SizeAnalyzer) Diff(image1, image2 pkgutil.Image) (util.Result, error) { diff := []util.SizeDiff{} size1 := pkgutil.GetSize(image1.FSPath) size2 := pkgutil.GetSize(image2.FSPath) if size1 != size2 { diff = append(diff, util.SizeDiff{ Size1: size1, Size2: size2, }) } return &util.SizeDiffResult{...
[ "func", "(", "a", "SizeAnalyzer", ")", "Diff", "(", "image1", ",", "image2", "pkgutil", ".", "Image", ")", "(", "util", ".", "Result", ",", "error", ")", "{", "diff", ":=", "[", "]", "util", ".", "SizeDiff", "{", "}", "\n", "size1", ":=", "pkgutil"...
// SizeDiff diffs two images and compares their size
[ "SizeDiff", "diffs", "two", "images", "and", "compares", "their", "size" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/size_diff.go#L34-L52
train
GoogleContainerTools/container-diff
differs/size_diff.go
Diff
func (a SizeLayerAnalyzer) Diff(image1, image2 pkgutil.Image) (util.Result, error) { var layerDiffs []util.SizeDiff maxLayer := len(image1.Layers) if len(image2.Layers) > maxLayer { maxLayer = len(image2.Layers) } for index := 0; index < maxLayer; index++ { var size1, size2 int64 = -1, -1 if index < len(im...
go
func (a SizeLayerAnalyzer) Diff(image1, image2 pkgutil.Image) (util.Result, error) { var layerDiffs []util.SizeDiff maxLayer := len(image1.Layers) if len(image2.Layers) > maxLayer { maxLayer = len(image2.Layers) } for index := 0; index < maxLayer; index++ { var size1, size2 int64 = -1, -1 if index < len(im...
[ "func", "(", "a", "SizeLayerAnalyzer", ")", "Diff", "(", "image1", ",", "image2", "pkgutil", ".", "Image", ")", "(", "util", ".", "Result", ",", "error", ")", "{", "var", "layerDiffs", "[", "]", "util", ".", "SizeDiff", "\n\n", "maxLayer", ":=", "len",...
// SizeLayerDiff diffs the layers of two images and compares their size
[ "SizeLayerDiff", "diffs", "the", "layers", "of", "two", "images", "and", "compares", "their", "size" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/size_diff.go#L78-L111
train
GoogleContainerTools/container-diff
differs/package_differs.go
singleVersionLayerDiff
func singleVersionLayerDiff(image1, image2 pkgutil.Image, differ SingleVersionPackageLayerAnalyzer) (*util.SingleVersionPackageLayerDiffResult, error) { logrus.Warning("'diff' command for packages on layers is not supported, consider using 'analyze' on each image instead") return &util.SingleVersionPackageLayerDiffRe...
go
func singleVersionLayerDiff(image1, image2 pkgutil.Image, differ SingleVersionPackageLayerAnalyzer) (*util.SingleVersionPackageLayerDiffResult, error) { logrus.Warning("'diff' command for packages on layers is not supported, consider using 'analyze' on each image instead") return &util.SingleVersionPackageLayerDiffRe...
[ "func", "singleVersionLayerDiff", "(", "image1", ",", "image2", "pkgutil", ".", "Image", ",", "differ", "SingleVersionPackageLayerAnalyzer", ")", "(", "*", "util", ".", "SingleVersionPackageLayerDiffResult", ",", "error", ")", "{", "logrus", ".", "Warning", "(", "...
// singleVersionLayerDiff returns an error as this diff is not supported as // it is far from obvious to define it in meaningful way
[ "singleVersionLayerDiff", "returns", "an", "error", "as", "this", "diff", "is", "not", "supported", "as", "it", "is", "far", "from", "obvious", "to", "define", "it", "in", "meaningful", "way" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/package_differs.go#L83-L86
train
GoogleContainerTools/container-diff
differs/package_differs.go
singleVersionLayerAnalysis
func singleVersionLayerAnalysis(image pkgutil.Image, analyzer SingleVersionPackageLayerAnalyzer) (*util.SingleVersionPackageLayerAnalyzeResult, error) { pack, err := analyzer.getPackages(image) if err != nil { return &util.SingleVersionPackageLayerAnalyzeResult{}, err } var pkgDiffs []util.PackageDiff // Each l...
go
func singleVersionLayerAnalysis(image pkgutil.Image, analyzer SingleVersionPackageLayerAnalyzer) (*util.SingleVersionPackageLayerAnalyzeResult, error) { pack, err := analyzer.getPackages(image) if err != nil { return &util.SingleVersionPackageLayerAnalyzeResult{}, err } var pkgDiffs []util.PackageDiff // Each l...
[ "func", "singleVersionLayerAnalysis", "(", "image", "pkgutil", ".", "Image", ",", "analyzer", "SingleVersionPackageLayerAnalyzer", ")", "(", "*", "util", ".", "SingleVersionPackageLayerAnalyzeResult", ",", "error", ")", "{", "pack", ",", "err", ":=", "analyzer", "."...
// singleVersionLayerAnalysis returns the packages included, deleted or // updated in each layer
[ "singleVersionLayerAnalysis", "returns", "the", "packages", "included", "deleted", "or", "updated", "in", "each", "layer" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/differs/package_differs.go#L118-L150
train
GoogleContainerTools/container-diff
pkg/util/image_utils.go
GetFileSystemForLayer
func GetFileSystemForLayer(layer v1.Layer, root string, whitelist []string) error { empty, err := DirIsEmpty(root) if err != nil { return err } if !empty { logrus.Infof("using cached filesystem in %s", root) return nil } contents, err := layer.Uncompressed() if err != nil { return err } return unpackTa...
go
func GetFileSystemForLayer(layer v1.Layer, root string, whitelist []string) error { empty, err := DirIsEmpty(root) if err != nil { return err } if !empty { logrus.Infof("using cached filesystem in %s", root) return nil } contents, err := layer.Uncompressed() if err != nil { return err } return unpackTa...
[ "func", "GetFileSystemForLayer", "(", "layer", "v1", ".", "Layer", ",", "root", "string", ",", "whitelist", "[", "]", "string", ")", "error", "{", "empty", ",", "err", ":=", "DirIsEmpty", "(", "root", ")", "\n", "if", "err", "!=", "nil", "{", "return",...
// GetFileSystemForLayer unpacks a layer to local disk
[ "GetFileSystemForLayer", "unpacks", "a", "layer", "to", "local", "disk" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/pkg/util/image_utils.go#L244-L258
train
GoogleContainerTools/container-diff
pkg/util/image_utils.go
GetFileSystemForImage
func GetFileSystemForImage(image v1.Image, root string, whitelist []string) error { empty, err := DirIsEmpty(root) if err != nil { return err } if !empty { logrus.Infof("using cached filesystem in %s", root) return nil } if err := unpackTar(tar.NewReader(mutate.Extract(image)), root, whitelist); err != nil ...
go
func GetFileSystemForImage(image v1.Image, root string, whitelist []string) error { empty, err := DirIsEmpty(root) if err != nil { return err } if !empty { logrus.Infof("using cached filesystem in %s", root) return nil } if err := unpackTar(tar.NewReader(mutate.Extract(image)), root, whitelist); err != nil ...
[ "func", "GetFileSystemForImage", "(", "image", "v1", ".", "Image", ",", "root", "string", ",", "whitelist", "[", "]", "string", ")", "error", "{", "empty", ",", "err", ":=", "DirIsEmpty", "(", "root", ")", "\n", "if", "err", "!=", "nil", "{", "return",...
// unpack image filesystem to local disk // if provided directory is not empty, do nothing
[ "unpack", "image", "filesystem", "to", "local", "disk", "if", "provided", "directory", "is", "not", "empty", "do", "nothing" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/pkg/util/image_utils.go#L262-L275
train
GoogleContainerTools/container-diff
pkg/util/image_utils.go
HasTag
func HasTag(image string) bool { tagRegex := regexp.MustCompile(tagRegexStr) return tagRegex.MatchString(image) }
go
func HasTag(image string) bool { tagRegex := regexp.MustCompile(tagRegexStr) return tagRegex.MatchString(image) }
[ "func", "HasTag", "(", "image", "string", ")", "bool", "{", "tagRegex", ":=", "regexp", ".", "MustCompile", "(", "tagRegexStr", ")", "\n", "return", "tagRegex", ".", "MatchString", "(", "image", ")", "\n", "}" ]
// checks to see if an image string contains a tag.
[ "checks", "to", "see", "if", "an", "image", "string", "contains", "a", "tag", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/pkg/util/image_utils.go#L320-L323
train
GoogleContainerTools/container-diff
pkg/util/image_utils.go
RemoveTag
func RemoveTag(image string) string { if !HasTag(image) { return image } tagRegex := regexp.MustCompile(tagRegexStr) parts := tagRegex.FindStringSubmatch(image) tag := parts[len(parts)-1] return image[0 : len(image)-len(tag)-1] }
go
func RemoveTag(image string) string { if !HasTag(image) { return image } tagRegex := regexp.MustCompile(tagRegexStr) parts := tagRegex.FindStringSubmatch(image) tag := parts[len(parts)-1] return image[0 : len(image)-len(tag)-1] }
[ "func", "RemoveTag", "(", "image", "string", ")", "string", "{", "if", "!", "HasTag", "(", "image", ")", "{", "return", "image", "\n", "}", "\n", "tagRegex", ":=", "regexp", ".", "MustCompile", "(", "tagRegexStr", ")", "\n", "parts", ":=", "tagRegex", ...
// returns a raw image name with the tag removed
[ "returns", "a", "raw", "image", "name", "with", "the", "tag", "removed" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/pkg/util/image_utils.go#L326-L334
train
GoogleContainerTools/container-diff
util/diff_utils.go
GetAdditions
func GetAdditions(a, b []string) []string { matcher := difflib.NewMatcher(a, b) differences := matcher.GetGroupedOpCodes(0) adds := []string{} for _, group := range differences { for _, opCode := range group { j1, j2 := opCode.J1, opCode.J2 if opCode.Tag == 'r' || opCode.Tag == 'i' { for _, line := ran...
go
func GetAdditions(a, b []string) []string { matcher := difflib.NewMatcher(a, b) differences := matcher.GetGroupedOpCodes(0) adds := []string{} for _, group := range differences { for _, opCode := range group { j1, j2 := opCode.J1, opCode.J2 if opCode.Tag == 'r' || opCode.Tag == 'i' { for _, line := ran...
[ "func", "GetAdditions", "(", "a", ",", "b", "[", "]", "string", ")", "[", "]", "string", "{", "matcher", ":=", "difflib", ".", "NewMatcher", "(", "a", ",", "b", ")", "\n", "differences", ":=", "matcher", ".", "GetGroupedOpCodes", "(", "0", ")", "\n\n...
// Modification of difflib's unified differ
[ "Modification", "of", "difflib", "s", "unified", "differ" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/util/diff_utils.go#L54-L70
train
GoogleContainerTools/container-diff
util/diff_utils.go
DiffDirectory
func DiffDirectory(d1, d2 pkgutil.Directory) (DirDiff, bool) { adds := GetAddedEntries(d1, d2) sort.Strings(adds) addedEntries := pkgutil.CreateDirectoryEntries(d2.Root, adds) dels := GetDeletedEntries(d1, d2) sort.Strings(dels) deletedEntries := pkgutil.CreateDirectoryEntries(d1.Root, dels) mods := GetModifie...
go
func DiffDirectory(d1, d2 pkgutil.Directory) (DirDiff, bool) { adds := GetAddedEntries(d1, d2) sort.Strings(adds) addedEntries := pkgutil.CreateDirectoryEntries(d2.Root, adds) dels := GetDeletedEntries(d1, d2) sort.Strings(dels) deletedEntries := pkgutil.CreateDirectoryEntries(d1.Root, dels) mods := GetModifie...
[ "func", "DiffDirectory", "(", "d1", ",", "d2", "pkgutil", ".", "Directory", ")", "(", "DirDiff", ",", "bool", ")", "{", "adds", ":=", "GetAddedEntries", "(", "d1", ",", "d2", ")", "\n", "sort", ".", "Strings", "(", "adds", ")", "\n", "addedEntries", ...
// DiffDirectory takes the diff of two directories, assuming both are completely unpacked
[ "DiffDirectory", "takes", "the", "diff", "of", "two", "directories", "assuming", "both", "are", "completely", "unpacked" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/util/diff_utils.go#L108-L129
train
GoogleContainerTools/container-diff
util/diff_utils.go
GetModifiedEntries
func GetModifiedEntries(d1, d2 pkgutil.Directory) []string { d1files := d1.Content d2files := d2.Content filematches := GetMatches(d1files, d2files) modified := []string{} for _, f := range filematches { f1path := fmt.Sprintf("%s%s", d1.Root, f) f2path := fmt.Sprintf("%s%s", d2.Root, f) f1stat, err := os....
go
func GetModifiedEntries(d1, d2 pkgutil.Directory) []string { d1files := d1.Content d2files := d2.Content filematches := GetMatches(d1files, d2files) modified := []string{} for _, f := range filematches { f1path := fmt.Sprintf("%s%s", d1.Root, f) f2path := fmt.Sprintf("%s%s", d2.Root, f) f1stat, err := os....
[ "func", "GetModifiedEntries", "(", "d1", ",", "d2", "pkgutil", ".", "Directory", ")", "[", "]", "string", "{", "d1files", ":=", "d1", ".", "Content", "\n", "d2files", ":=", "d2", ".", "Content", "\n\n", "filematches", ":=", "GetMatches", "(", "d1files", ...
// Checks for content differences between files of the same name from different directories
[ "Checks", "for", "content", "differences", "between", "files", "of", "the", "same", "name", "from", "different", "directories" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/util/diff_utils.go#L190-L247
train
GoogleContainerTools/container-diff
pkg/util/fs_utils.go
GetFileContents
func GetFileContents(path string) (*string, error) { if _, err := os.Stat(path); os.IsNotExist(err) { return nil, err } contents, err := ioutil.ReadFile(path) if err != nil { return nil, err } strContents := string(contents) //If file is empty, return nil if strContents == "" { return nil, nil } retur...
go
func GetFileContents(path string) (*string, error) { if _, err := os.Stat(path); os.IsNotExist(err) { return nil, err } contents, err := ioutil.ReadFile(path) if err != nil { return nil, err } strContents := string(contents) //If file is empty, return nil if strContents == "" { return nil, nil } retur...
[ "func", "GetFileContents", "(", "path", "string", ")", "(", "*", "string", ",", "error", ")", "{", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "path", ")", ";", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "nil", ",", "err", ...
//GetFileContents returns the contents of a file at the specified path
[ "GetFileContents", "returns", "the", "contents", "of", "a", "file", "at", "the", "specified", "path" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/pkg/util/fs_utils.go#L58-L74
train
GoogleContainerTools/container-diff
pkg/util/fs_utils.go
GetDirectory
func GetDirectory(path string, deep bool) (Directory, error) { var directory Directory directory.Root = path var err error if deep { walkFn := func(currPath string, info os.FileInfo, err error) error { newContent := strings.TrimPrefix(currPath, directory.Root) if newContent != "" { directory.Content = a...
go
func GetDirectory(path string, deep bool) (Directory, error) { var directory Directory directory.Root = path var err error if deep { walkFn := func(currPath string, info os.FileInfo, err error) error { newContent := strings.TrimPrefix(currPath, directory.Root) if newContent != "" { directory.Content = a...
[ "func", "GetDirectory", "(", "path", "string", ",", "deep", "bool", ")", "(", "Directory", ",", "error", ")", "{", "var", "directory", "Directory", "\n", "directory", ".", "Root", "=", "path", "\n", "var", "err", "error", "\n", "if", "deep", "{", "walk...
// GetDirectoryContents converts the directory starting at the provided path into a Directory struct.
[ "GetDirectoryContents", "converts", "the", "directory", "starting", "at", "the", "provided", "path", "into", "a", "Directory", "struct", "." ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/pkg/util/fs_utils.go#L88-L114
train
GoogleContainerTools/container-diff
pkg/util/fs_utils.go
HasFilepathPrefix
func HasFilepathPrefix(path, prefix string) bool { path = filepath.Clean(path) prefix = filepath.Clean(prefix) pathArray := strings.Split(path, "/") prefixArray := strings.Split(prefix, "/") if len(pathArray) < len(prefixArray) { return false } for index := range prefixArray { if prefixArray[index] == pathA...
go
func HasFilepathPrefix(path, prefix string) bool { path = filepath.Clean(path) prefix = filepath.Clean(prefix) pathArray := strings.Split(path, "/") prefixArray := strings.Split(prefix, "/") if len(pathArray) < len(prefixArray) { return false } for index := range prefixArray { if prefixArray[index] == pathA...
[ "func", "HasFilepathPrefix", "(", "path", ",", "prefix", "string", ")", "bool", "{", "path", "=", "filepath", ".", "Clean", "(", "path", ")", "\n", "prefix", "=", "filepath", ".", "Clean", "(", "prefix", ")", "\n", "pathArray", ":=", "strings", ".", "S...
// HasFilepathPrefix checks if the given file path begins with prefix
[ "HasFilepathPrefix", "checks", "if", "the", "given", "file", "path", "begins", "with", "prefix" ]
a62c5163a8a12073631fddd972570e5559476e24
https://github.com/GoogleContainerTools/container-diff/blob/a62c5163a8a12073631fddd972570e5559476e24/pkg/util/fs_utils.go#L178-L194
train
Unknwon/com
path.go
GetSrcPath
func GetSrcPath(importPath string) (appPath string, err error) { paths := GetGOPATHs() for _, p := range paths { if IsExist(p + "/src/" + importPath + "/") { appPath = p + "/src/" + importPath + "/" break } } if len(appPath) == 0 { return "", errors.New("Unable to locate source folder path") } appPa...
go
func GetSrcPath(importPath string) (appPath string, err error) { paths := GetGOPATHs() for _, p := range paths { if IsExist(p + "/src/" + importPath + "/") { appPath = p + "/src/" + importPath + "/" break } } if len(appPath) == 0 { return "", errors.New("Unable to locate source folder path") } appPa...
[ "func", "GetSrcPath", "(", "importPath", "string", ")", "(", "appPath", "string", ",", "err", "error", ")", "{", "paths", ":=", "GetGOPATHs", "(", ")", "\n", "for", "_", ",", "p", ":=", "range", "paths", "{", "if", "IsExist", "(", "p", "+", "\"", "...
// GetSrcPath returns app. source code path. // It only works when you have src. folder in GOPATH, // it returns error not able to locate source folder path.
[ "GetSrcPath", "returns", "app", ".", "source", "code", "path", ".", "It", "only", "works", "when", "you", "have", "src", ".", "folder", "in", "GOPATH", "it", "returns", "error", "not", "able", "to", "locate", "source", "folder", "path", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/path.go#L41-L61
train
Unknwon/com
cmd.go
getColorLevel
func getColorLevel(level string) string { level = strings.ToUpper(level) switch level { case "TRAC": return fmt.Sprintf("\033[%dm%s\033[0m", Blue, level) case "ERRO": return fmt.Sprintf("\033[%dm%s\033[0m", Red, level) case "WARN": return fmt.Sprintf("\033[%dm%s\033[0m", Magenta, level) case "SUCC": retur...
go
func getColorLevel(level string) string { level = strings.ToUpper(level) switch level { case "TRAC": return fmt.Sprintf("\033[%dm%s\033[0m", Blue, level) case "ERRO": return fmt.Sprintf("\033[%dm%s\033[0m", Red, level) case "WARN": return fmt.Sprintf("\033[%dm%s\033[0m", Magenta, level) case "SUCC": retur...
[ "func", "getColorLevel", "(", "level", "string", ")", "string", "{", "level", "=", "strings", ".", "ToUpper", "(", "level", ")", "\n", "switch", "level", "{", "case", "\"", "\"", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\\033", "\\033", "\"", ...
// getColorLevel returns colored level string by given level.
[ "getColorLevel", "returns", "colored", "level", "string", "by", "given", "level", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/cmd.go#L82-L96
train
Unknwon/com
string.go
AESGCMEncrypt
func AESGCMEncrypt(key, plaintext []byte) ([]byte, error) { block, err := aes.NewCipher(key) if err != nil { return nil, err } gcm, err := cipher.NewGCM(block) if err != nil { return nil, err } nonce := make([]byte, gcm.NonceSize()) if _, err := rand.Read(nonce); err != nil { return nil, err } cipher...
go
func AESGCMEncrypt(key, plaintext []byte) ([]byte, error) { block, err := aes.NewCipher(key) if err != nil { return nil, err } gcm, err := cipher.NewGCM(block) if err != nil { return nil, err } nonce := make([]byte, gcm.NonceSize()) if _, err := rand.Read(nonce); err != nil { return nil, err } cipher...
[ "func", "AESGCMEncrypt", "(", "key", ",", "plaintext", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "block", ",", "err", ":=", "aes", ".", "NewCipher", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil"...
// AESGCMEncrypt encrypts plaintext with the given key using AES in GCM mode.
[ "AESGCMEncrypt", "encrypts", "plaintext", "with", "the", "given", "key", "using", "AES", "in", "GCM", "mode", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/string.go#L32-L50
train
Unknwon/com
string.go
AESGCMDecrypt
func AESGCMDecrypt(key, ciphertext []byte) ([]byte, error) { block, err := aes.NewCipher(key) if err != nil { return nil, err } gcm, err := cipher.NewGCM(block) if err != nil { return nil, err } size := gcm.NonceSize() if len(ciphertext)-size <= 0 { return nil, errors.New("Ciphertext is empty") } non...
go
func AESGCMDecrypt(key, ciphertext []byte) ([]byte, error) { block, err := aes.NewCipher(key) if err != nil { return nil, err } gcm, err := cipher.NewGCM(block) if err != nil { return nil, err } size := gcm.NonceSize() if len(ciphertext)-size <= 0 { return nil, errors.New("Ciphertext is empty") } non...
[ "func", "AESGCMDecrypt", "(", "key", ",", "ciphertext", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "block", ",", "err", ":=", "aes", ".", "NewCipher", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil...
// AESGCMDecrypt decrypts ciphertext with the given key using AES in GCM mode.
[ "AESGCMDecrypt", "decrypts", "ciphertext", "with", "the", "given", "key", "using", "AES", "in", "GCM", "mode", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/string.go#L53-L78
train
Unknwon/com
string.go
IsLetter
func IsLetter(l uint8) bool { n := (l | 0x20) - 'a' if n >= 0 && n < 26 { return true } return false }
go
func IsLetter(l uint8) bool { n := (l | 0x20) - 'a' if n >= 0 && n < 26 { return true } return false }
[ "func", "IsLetter", "(", "l", "uint8", ")", "bool", "{", "n", ":=", "(", "l", "|", "0x20", ")", "-", "'a'", "\n", "if", "n", ">=", "0", "&&", "n", "<", "26", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsLetter returns true if the 'l' is an English letter.
[ "IsLetter", "returns", "true", "if", "the", "l", "is", "an", "English", "letter", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/string.go#L81-L87
train
Unknwon/com
string.go
Reverse
func Reverse(s string) string { n := len(s) runes := make([]rune, n) for _, rune := range s { n-- runes[n] = rune } return string(runes[n:]) }
go
func Reverse(s string) string { n := len(s) runes := make([]rune, n) for _, rune := range s { n-- runes[n] = rune } return string(runes[n:]) }
[ "func", "Reverse", "(", "s", "string", ")", "string", "{", "n", ":=", "len", "(", "s", ")", "\n", "runes", ":=", "make", "(", "[", "]", "rune", ",", "n", ")", "\n", "for", "_", ",", "rune", ":=", "range", "s", "{", "n", "--", "\n", "runes", ...
// Reverse s string, support unicode
[ "Reverse", "s", "string", "support", "unicode" ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/string.go#L118-L126
train
Unknwon/com
time.go
Date
func Date(ti int64, format string) string { t := time.Unix(int64(ti), 0) return DateT(t, format) }
go
func Date(ti int64, format string) string { t := time.Unix(int64(ti), 0) return DateT(t, format) }
[ "func", "Date", "(", "ti", "int64", ",", "format", "string", ")", "string", "{", "t", ":=", "time", ".", "Unix", "(", "int64", "(", "ti", ")", ",", "0", ")", "\n", "return", "DateT", "(", "t", ",", "format", ")", "\n", "}" ]
// Format unix time int64 to string
[ "Format", "unix", "time", "int64", "to", "string" ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/time.go#L25-L28
train
Unknwon/com
time.go
DateS
func DateS(ts string, format string) string { i, _ := strconv.ParseInt(ts, 10, 64) return Date(i, format) }
go
func DateS(ts string, format string) string { i, _ := strconv.ParseInt(ts, 10, 64) return Date(i, format) }
[ "func", "DateS", "(", "ts", "string", ",", "format", "string", ")", "string", "{", "i", ",", "_", ":=", "strconv", ".", "ParseInt", "(", "ts", ",", "10", ",", "64", ")", "\n", "return", "Date", "(", "i", ",", "format", ")", "\n", "}" ]
// Format unix time string to string
[ "Format", "unix", "time", "string", "to", "string" ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/time.go#L31-L34
train
Unknwon/com
time.go
DateT
func DateT(t time.Time, format string) string { res := strings.Replace(format, "MM", t.Format("01"), -1) res = strings.Replace(res, "M", t.Format("1"), -1) res = strings.Replace(res, "DD", t.Format("02"), -1) res = strings.Replace(res, "D", t.Format("2"), -1) res = strings.Replace(res, "YYYY", t.Format("2006"), -1...
go
func DateT(t time.Time, format string) string { res := strings.Replace(format, "MM", t.Format("01"), -1) res = strings.Replace(res, "M", t.Format("1"), -1) res = strings.Replace(res, "DD", t.Format("02"), -1) res = strings.Replace(res, "D", t.Format("2"), -1) res = strings.Replace(res, "YYYY", t.Format("2006"), -1...
[ "func", "DateT", "(", "t", "time", ".", "Time", ",", "format", "string", ")", "string", "{", "res", ":=", "strings", ".", "Replace", "(", "format", ",", "\"", "\"", ",", "t", ".", "Format", "(", "\"", "\"", ")", ",", "-", "1", ")", "\n", "res",...
// Format time.Time struct to string // MM - month - 01 // M - month - 1, single bit // DD - day - 02 // D - day 2 // YYYY - year - 2006 // YY - year - 06 // HH - 24 hours - 03 // H - 24 hours - 3 // hh - 12 hours - 03 // h - 12 hours - 3 // mm - minute - 04 // m - minute - 4 // ss - second - 05 // s - second = 5
[ "Format", "time", ".", "Time", "struct", "to", "string", "MM", "-", "month", "-", "01", "M", "-", "month", "-", "1", "single", "bit", "DD", "-", "day", "-", "02", "D", "-", "day", "2", "YYYY", "-", "year", "-", "2006", "YY", "-", "year", "-", ...
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/time.go#L51-L67
train
Unknwon/com
time.go
DateParse
func DateParse(dateString, format string) (time.Time, error) { replacer := strings.NewReplacer(datePatterns...) format = replacer.Replace(format) return time.ParseInLocation(format, dateString, time.Local) }
go
func DateParse(dateString, format string) (time.Time, error) { replacer := strings.NewReplacer(datePatterns...) format = replacer.Replace(format) return time.ParseInLocation(format, dateString, time.Local) }
[ "func", "DateParse", "(", "dateString", ",", "format", "string", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "replacer", ":=", "strings", ".", "NewReplacer", "(", "datePatterns", "...", ")", "\n", "format", "=", "replacer", ".", "Replace", "("...
// Parse Date use PHP time format.
[ "Parse", "Date", "use", "PHP", "time", "format", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/time.go#L111-L115
train
Unknwon/com
dir.go
GetAllSubDirs
func GetAllSubDirs(rootPath string) ([]string, error) { if !IsDir(rootPath) { return nil, errors.New("not a directory or does not exist: " + rootPath) } return statDir(rootPath, "", true, true, false) }
go
func GetAllSubDirs(rootPath string) ([]string, error) { if !IsDir(rootPath) { return nil, errors.New("not a directory or does not exist: " + rootPath) } return statDir(rootPath, "", true, true, false) }
[ "func", "GetAllSubDirs", "(", "rootPath", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "!", "IsDir", "(", "rootPath", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", "+", "rootPath", ")", "\n", "}", ...
// GetAllSubDirs returns all subdirectories of given root path. // Slice does not include given path itself.
[ "GetAllSubDirs", "returns", "all", "subdirectories", "of", "given", "root", "path", ".", "Slice", "does", "not", "include", "given", "path", "itself", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/dir.go#L127-L132
train
Unknwon/com
dir.go
GetFileListBySuffix
func GetFileListBySuffix(dirPath, suffix string) ([]string, error) { if !IsExist(dirPath) { return nil, fmt.Errorf("given path does not exist: %s", dirPath) } else if IsFile(dirPath) { return []string{dirPath}, nil } // Given path is a directory. dir, err := os.Open(dirPath) if err != nil { return nil, err...
go
func GetFileListBySuffix(dirPath, suffix string) ([]string, error) { if !IsExist(dirPath) { return nil, fmt.Errorf("given path does not exist: %s", dirPath) } else if IsFile(dirPath) { return []string{dirPath}, nil } // Given path is a directory. dir, err := os.Open(dirPath) if err != nil { return nil, err...
[ "func", "GetFileListBySuffix", "(", "dirPath", ",", "suffix", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "!", "IsExist", "(", "dirPath", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "dirPath",...
// GetFileListBySuffix returns an ordered list of file paths. // It recognize if given path is a file, and don't do recursive find.
[ "GetFileListBySuffix", "returns", "an", "ordered", "list", "of", "file", "paths", ".", "It", "recognize", "if", "given", "path", "is", "a", "file", "and", "don", "t", "do", "recursive", "find", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/dir.go#L146-L172
train
Unknwon/com
slice.go
AppendStr
func AppendStr(strs []string, str string) []string { for _, s := range strs { if s == str { return strs } } return append(strs, str) }
go
func AppendStr(strs []string, str string) []string { for _, s := range strs { if s == str { return strs } } return append(strs, str) }
[ "func", "AppendStr", "(", "strs", "[", "]", "string", ",", "str", "string", ")", "[", "]", "string", "{", "for", "_", ",", "s", ":=", "range", "strs", "{", "if", "s", "==", "str", "{", "return", "strs", "\n", "}", "\n", "}", "\n", "return", "ap...
// AppendStr appends string to slice with no duplicates.
[ "AppendStr", "appends", "string", "to", "slice", "with", "no", "duplicates", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/slice.go#L22-L29
train
Unknwon/com
slice.go
CompareSliceStrU
func CompareSliceStrU(s1, s2 []string) bool { if len(s1) != len(s2) { return false } for i := range s1 { for j := len(s2) - 1; j >= 0; j-- { if s1[i] == s2[j] { s2 = append(s2[:j], s2[j+1:]...) break } } } if len(s2) > 0 { return false } return true }
go
func CompareSliceStrU(s1, s2 []string) bool { if len(s1) != len(s2) { return false } for i := range s1 { for j := len(s2) - 1; j >= 0; j-- { if s1[i] == s2[j] { s2 = append(s2[:j], s2[j+1:]...) break } } } if len(s2) > 0 { return false } return true }
[ "func", "CompareSliceStrU", "(", "s1", ",", "s2", "[", "]", "string", ")", "bool", "{", "if", "len", "(", "s1", ")", "!=", "len", "(", "s2", ")", "{", "return", "false", "\n", "}", "\n\n", "for", "i", ":=", "range", "s1", "{", "for", "j", ":=",...
// CompareSliceStrU compares two 'string' type slices. // It returns true if elements are the same, and ignores the order.
[ "CompareSliceStrU", "compares", "two", "string", "type", "slices", ".", "It", "returns", "true", "if", "elements", "are", "the", "same", "and", "ignores", "the", "order", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/slice.go#L49-L66
train
Unknwon/com
slice.go
IsSliceContainsInt64
func IsSliceContainsInt64(sl []int64, i int64) bool { for _, s := range sl { if s == i { return true } } return false }
go
func IsSliceContainsInt64(sl []int64, i int64) bool { for _, s := range sl { if s == i { return true } } return false }
[ "func", "IsSliceContainsInt64", "(", "sl", "[", "]", "int64", ",", "i", "int64", ")", "bool", "{", "for", "_", ",", "s", ":=", "range", "sl", "{", "if", "s", "==", "i", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", ...
// IsSliceContainsInt64 returns true if the int64 exists in given slice.
[ "IsSliceContainsInt64", "returns", "true", "if", "the", "int64", "exists", "in", "given", "slice", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/slice.go#L80-L87
train
Unknwon/com
file.go
FileMTime
func FileMTime(file string) (int64, error) { f, err := os.Stat(file) if err != nil { return 0, err } return f.ModTime().Unix(), nil }
go
func FileMTime(file string) (int64, error) { f, err := os.Stat(file) if err != nil { return 0, err } return f.ModTime().Unix(), nil }
[ "func", "FileMTime", "(", "file", "string", ")", "(", "int64", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Stat", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "f", ...
// FileMTime returns file modified time and possible error.
[ "FileMTime", "returns", "file", "modified", "time", "and", "possible", "error", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/file.go#L63-L69
train
Unknwon/com
file.go
FileSize
func FileSize(file string) (int64, error) { f, err := os.Stat(file) if err != nil { return 0, err } return f.Size(), nil }
go
func FileSize(file string) (int64, error) { f, err := os.Stat(file) if err != nil { return 0, err } return f.Size(), nil }
[ "func", "FileSize", "(", "file", "string", ")", "(", "int64", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Stat", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "f", ...
// FileSize returns file size in bytes and possible error.
[ "FileSize", "returns", "file", "size", "in", "bytes", "and", "possible", "error", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/file.go#L72-L78
train
Unknwon/com
file.go
WriteFile
func WriteFile(filename string, data []byte) error { os.MkdirAll(path.Dir(filename), os.ModePerm) return ioutil.WriteFile(filename, data, 0655) }
go
func WriteFile(filename string, data []byte) error { os.MkdirAll(path.Dir(filename), os.ModePerm) return ioutil.WriteFile(filename, data, 0655) }
[ "func", "WriteFile", "(", "filename", "string", ",", "data", "[", "]", "byte", ")", "error", "{", "os", ".", "MkdirAll", "(", "path", ".", "Dir", "(", "filename", ")", ",", "os", ".", "ModePerm", ")", "\n", "return", "ioutil", ".", "WriteFile", "(", ...
// WriteFile writes data to a file named by filename. // If the file does not exist, WriteFile creates it // and its upper level paths.
[ "WriteFile", "writes", "data", "to", "a", "file", "named", "by", "filename", ".", "If", "the", "file", "does", "not", "exist", "WriteFile", "creates", "it", "and", "its", "upper", "level", "paths", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/file.go#L125-L128
train
Unknwon/com
http.go
HttpPost
func HttpPost(client *http.Client, url string, header http.Header, body []byte) (io.ReadCloser, error) { return HttpCall(client, "POST", url, header, bytes.NewBuffer(body)) }
go
func HttpPost(client *http.Client, url string, header http.Header, body []byte) (io.ReadCloser, error) { return HttpCall(client, "POST", url, header, bytes.NewBuffer(body)) }
[ "func", "HttpPost", "(", "client", "*", "http", ".", "Client", ",", "url", "string", ",", "header", "http", ".", "Header", ",", "body", "[", "]", "byte", ")", "(", "io", ".", "ReadCloser", ",", "error", ")", "{", "return", "HttpCall", "(", "client", ...
// HttpPost posts the specified resource. // ErrNotFound is returned if the server responds with status 404.
[ "HttpPost", "posts", "the", "specified", "resource", ".", "ErrNotFound", "is", "returned", "if", "the", "server", "responds", "with", "status", "404", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/http.go#L81-L83
train
Unknwon/com
http.go
HttpGetToFile
func HttpGetToFile(client *http.Client, url string, header http.Header, fileName string) error { rc, err := HttpGet(client, url, header) if err != nil { return err } defer rc.Close() os.MkdirAll(path.Dir(fileName), os.ModePerm) f, err := os.Create(fileName) if err != nil { return err } defer f.Close() _,...
go
func HttpGetToFile(client *http.Client, url string, header http.Header, fileName string) error { rc, err := HttpGet(client, url, header) if err != nil { return err } defer rc.Close() os.MkdirAll(path.Dir(fileName), os.ModePerm) f, err := os.Create(fileName) if err != nil { return err } defer f.Close() _,...
[ "func", "HttpGetToFile", "(", "client", "*", "http", ".", "Client", ",", "url", "string", ",", "header", "http", ".", "Header", ",", "fileName", "string", ")", "error", "{", "rc", ",", "err", ":=", "HttpGet", "(", "client", ",", "url", ",", "header", ...
// HttpGetToFile gets the specified resource and writes to file. // ErrNotFound is returned if the server responds with status 404.
[ "HttpGetToFile", "gets", "the", "specified", "resource", "and", "writes", "to", "file", ".", "ErrNotFound", "is", "returned", "if", "the", "server", "responds", "with", "status", "404", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/http.go#L87-L102
train
Unknwon/com
http.go
HttpPostJSON
func HttpPostJSON(client *http.Client, url string, body, v interface{}) error { data, err := json.Marshal(body) if err != nil { return err } rc, err := HttpPost(client, url, http.Header{"content-type": []string{"application/json"}}, data) if err != nil { return err } defer rc.Close() err = json.NewDecoder(r...
go
func HttpPostJSON(client *http.Client, url string, body, v interface{}) error { data, err := json.Marshal(body) if err != nil { return err } rc, err := HttpPost(client, url, http.Header{"content-type": []string{"application/json"}}, data) if err != nil { return err } defer rc.Close() err = json.NewDecoder(r...
[ "func", "HttpPostJSON", "(", "client", "*", "http", ".", "Client", ",", "url", "string", ",", "body", ",", "v", "interface", "{", "}", ")", "error", "{", "data", ",", "err", ":=", "json", ".", "Marshal", "(", "body", ")", "\n", "if", "err", "!=", ...
// HttpPostJSON posts the specified resource with struct values, // and maps results to struct. // ErrNotFound is returned if the server responds with status 404.
[ "HttpPostJSON", "posts", "the", "specified", "resource", "with", "struct", "values", "and", "maps", "results", "to", "struct", ".", "ErrNotFound", "is", "returned", "if", "the", "server", "responds", "with", "status", "404", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/http.go#L133-L148
train
Unknwon/com
http.go
FetchFiles
func FetchFiles(client *http.Client, files []RawFile, header http.Header) error { ch := make(chan error, len(files)) for i := range files { go func(i int) { p, err := HttpGetBytes(client, files[i].RawUrl(), nil) if err != nil { ch <- err return } files[i].SetData(p) ch <- nil }(i) } for _...
go
func FetchFiles(client *http.Client, files []RawFile, header http.Header) error { ch := make(chan error, len(files)) for i := range files { go func(i int) { p, err := HttpGetBytes(client, files[i].RawUrl(), nil) if err != nil { ch <- err return } files[i].SetData(p) ch <- nil }(i) } for _...
[ "func", "FetchFiles", "(", "client", "*", "http", ".", "Client", ",", "files", "[", "]", "RawFile", ",", "header", "http", ".", "Header", ")", "error", "{", "ch", ":=", "make", "(", "chan", "error", ",", "len", "(", "files", ")", ")", "\n", "for", ...
// FetchFiles fetches files specified by the rawURL field in parallel.
[ "FetchFiles", "fetches", "files", "specified", "by", "the", "rawURL", "field", "in", "parallel", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/http.go#L159-L178
train
Unknwon/com
convert.go
HexStr2int
func HexStr2int(hexStr string) (int, error) { num := 0 length := len(hexStr) for i := 0; i < length; i++ { char := hexStr[length-i-1] factor := -1 switch { case char >= '0' && char <= '9': factor = int(char) - '0' case char >= 'a' && char <= 'f': factor = int(char) - 'a' + 10 default: return -1...
go
func HexStr2int(hexStr string) (int, error) { num := 0 length := len(hexStr) for i := 0; i < length; i++ { char := hexStr[length-i-1] factor := -1 switch { case char >= '0' && char <= '9': factor = int(char) - '0' case char >= 'a' && char <= 'f': factor = int(char) - 'a' + 10 default: return -1...
[ "func", "HexStr2int", "(", "hexStr", "string", ")", "(", "int", ",", "error", ")", "{", "num", ":=", "0", "\n", "length", ":=", "len", "(", "hexStr", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "length", ";", "i", "++", "{", "char", ":=", ...
// HexStr2int converts hex format string to decimal number.
[ "HexStr2int", "converts", "hex", "format", "string", "to", "decimal", "number", "." ]
0fed4efef7553eed2cd04624befccacda78bb8e2
https://github.com/Unknwon/com/blob/0fed4efef7553eed2cd04624befccacda78bb8e2/convert.go#L127-L146
train
HouzuoGuo/tiedot
data/partition.go
OpenPartition
func (conf *Config) OpenPartition(colPath, lookupPath string) (part *Partition, err error) { part = conf.newPartition() part.CalculateConfigConstants() if part.col, err = conf.OpenCollection(colPath); err != nil { return } else if part.lookup, err = conf.OpenHashTable(lookupPath); err != nil { return } return...
go
func (conf *Config) OpenPartition(colPath, lookupPath string) (part *Partition, err error) { part = conf.newPartition() part.CalculateConfigConstants() if part.col, err = conf.OpenCollection(colPath); err != nil { return } else if part.lookup, err = conf.OpenHashTable(lookupPath); err != nil { return } return...
[ "func", "(", "conf", "*", "Config", ")", "OpenPartition", "(", "colPath", ",", "lookupPath", "string", ")", "(", "part", "*", "Partition", ",", "err", "error", ")", "{", "part", "=", "conf", ".", "newPartition", "(", ")", "\n", "part", ".", "CalculateC...
// Open a collection partition.
[ "Open", "a", "collection", "partition", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/partition.go#L37-L46
train
HouzuoGuo/tiedot
data/partition.go
LockUpdate
func (part *Partition) LockUpdate(id int) { for { part.exclUpdateLock.Lock() ch, ok := part.exclUpdate[id] if !ok { part.exclUpdate[id] = make(chan struct{}) } part.exclUpdateLock.Unlock() if ok { <-ch } else { break } } }
go
func (part *Partition) LockUpdate(id int) { for { part.exclUpdateLock.Lock() ch, ok := part.exclUpdate[id] if !ok { part.exclUpdate[id] = make(chan struct{}) } part.exclUpdateLock.Unlock() if ok { <-ch } else { break } } }
[ "func", "(", "part", "*", "Partition", ")", "LockUpdate", "(", "id", "int", ")", "{", "for", "{", "part", ".", "exclUpdateLock", ".", "Lock", "(", ")", "\n", "ch", ",", "ok", ":=", "part", ".", "exclUpdate", "[", "id", "]", "\n", "if", "!", "ok",...
// Lock a document for exclusive update.
[ "Lock", "a", "document", "for", "exclusive", "update", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/partition.go#L93-L107
train
HouzuoGuo/tiedot
data/partition.go
UnlockUpdate
func (part *Partition) UnlockUpdate(id int) { part.exclUpdateLock.Lock() ch := part.exclUpdate[id] delete(part.exclUpdate, id) part.exclUpdateLock.Unlock() close(ch) }
go
func (part *Partition) UnlockUpdate(id int) { part.exclUpdateLock.Lock() ch := part.exclUpdate[id] delete(part.exclUpdate, id) part.exclUpdateLock.Unlock() close(ch) }
[ "func", "(", "part", "*", "Partition", ")", "UnlockUpdate", "(", "id", "int", ")", "{", "part", ".", "exclUpdateLock", ".", "Lock", "(", ")", "\n", "ch", ":=", "part", ".", "exclUpdate", "[", "id", "]", "\n", "delete", "(", "part", ".", "exclUpdate",...
// Unlock a document to make it ready for the next update.
[ "Unlock", "a", "document", "to", "make", "it", "ready", "for", "the", "next", "update", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/partition.go#L110-L116
train
HouzuoGuo/tiedot
data/partition.go
ForEachDoc
func (part *Partition) ForEachDoc(partNum, totalPart int, fun func(id int, doc []byte) bool) (moveOn bool) { ids, physIDs := part.lookup.GetPartition(partNum, totalPart) for i, id := range ids { data := part.col.Read(physIDs[i]) if data != nil { if !fun(id, data) { return false } } } return true }
go
func (part *Partition) ForEachDoc(partNum, totalPart int, fun func(id int, doc []byte) bool) (moveOn bool) { ids, physIDs := part.lookup.GetPartition(partNum, totalPart) for i, id := range ids { data := part.col.Read(physIDs[i]) if data != nil { if !fun(id, data) { return false } } } return true }
[ "func", "(", "part", "*", "Partition", ")", "ForEachDoc", "(", "partNum", ",", "totalPart", "int", ",", "fun", "func", "(", "id", "int", ",", "doc", "[", "]", "byte", ")", "bool", ")", "(", "moveOn", "bool", ")", "{", "ids", ",", "physIDs", ":=", ...
// Partition documents into roughly equally sized portions, and run the function on every document in the portion.
[ "Partition", "documents", "into", "roughly", "equally", "sized", "portions", "and", "run", "the", "function", "on", "every", "document", "in", "the", "portion", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/partition.go#L130-L141
train
HouzuoGuo/tiedot
data/partition.go
ApproxDocCount
func (part *Partition) ApproxDocCount() int { totalPart := 24 // not magic; a larger number makes estimation less accurate, but improves performance for { keys, _ := part.lookup.GetPartition(0, totalPart) if len(keys) == 0 { if totalPart < 8 { return 0 // the hash table is really really empty } // Tr...
go
func (part *Partition) ApproxDocCount() int { totalPart := 24 // not magic; a larger number makes estimation less accurate, but improves performance for { keys, _ := part.lookup.GetPartition(0, totalPart) if len(keys) == 0 { if totalPart < 8 { return 0 // the hash table is really really empty } // Tr...
[ "func", "(", "part", "*", "Partition", ")", "ApproxDocCount", "(", ")", "int", "{", "totalPart", ":=", "24", "// not magic; a larger number makes estimation less accurate, but improves performance", "\n", "for", "{", "keys", ",", "_", ":=", "part", ".", "lookup", "....
// Return approximate number of documents in the partition.
[ "Return", "approximate", "number", "of", "documents", "in", "the", "partition", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/partition.go#L144-L158
train
HouzuoGuo/tiedot
data/partition.go
Close
func (part *Partition) Close() error { var err error if e := part.col.Close(); e != nil { tdlog.CritNoRepeat("Failed to close %s: %v", part.col.Path, e) err = dberr.New(dberr.ErrorIO) } if e := part.lookup.Close(); e != nil { tdlog.CritNoRepeat("Failed to close %s: %v", part.lookup.Path, e) err = dberr.Ne...
go
func (part *Partition) Close() error { var err error if e := part.col.Close(); e != nil { tdlog.CritNoRepeat("Failed to close %s: %v", part.col.Path, e) err = dberr.New(dberr.ErrorIO) } if e := part.lookup.Close(); e != nil { tdlog.CritNoRepeat("Failed to close %s: %v", part.lookup.Path, e) err = dberr.Ne...
[ "func", "(", "part", "*", "Partition", ")", "Close", "(", ")", "error", "{", "var", "err", "error", "\n\n", "if", "e", ":=", "part", ".", "col", ".", "Close", "(", ")", ";", "e", "!=", "nil", "{", "tdlog", ".", "CritNoRepeat", "(", "\"", "\"", ...
// Close all file handles.
[ "Close", "all", "file", "handles", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/partition.go#L181-L194
train
HouzuoGuo/tiedot
gommap/mmap.go
Map
func Map(f *os.File) (MMap, error) { fd := uintptr(f.Fd()) fi, err := f.Stat() if err != nil { return nil, err } length := int(fi.Size()) if int64(length) != fi.Size() { return nil, errors.New("memory map file length overflow") } return mmap(length, fd) }
go
func Map(f *os.File) (MMap, error) { fd := uintptr(f.Fd()) fi, err := f.Stat() if err != nil { return nil, err } length := int(fi.Size()) if int64(length) != fi.Size() { return nil, errors.New("memory map file length overflow") } return mmap(length, fd) }
[ "func", "Map", "(", "f", "*", "os", ".", "File", ")", "(", "MMap", ",", "error", ")", "{", "fd", ":=", "uintptr", "(", "f", ".", "Fd", "(", ")", ")", "\n", "fi", ",", "err", ":=", "f", ".", "Stat", "(", ")", "\n", "if", "err", "!=", "nil"...
// Map maps an entire file into memory. // Note that because of runtime limitations, no file larger than about 2GB can // be completely mapped into memory.
[ "Map", "maps", "an", "entire", "file", "into", "memory", ".", "Note", "that", "because", "of", "runtime", "limitations", "no", "file", "larger", "than", "about", "2GB", "can", "be", "completely", "mapped", "into", "memory", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/gommap/mmap.go#L30-L41
train
HouzuoGuo/tiedot
httpapi/query.go
Query
func Query(w http.ResponseWriter, r *http.Request) { w.Header().Set("Cache-Control", "must-revalidate") w.Header().Set("Content-Type", "application/json") w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS") var col, q string if !Require(w, r...
go
func Query(w http.ResponseWriter, r *http.Request) { w.Header().Set("Cache-Control", "must-revalidate") w.Header().Set("Content-Type", "application/json") w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS") var col, q string if !Require(w, r...
[ "func", "Query", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "w", ".", "Header", "(", ")", ".", "Set", "(", ...
// Execute a query and return documents from the result.
[ "Execute", "a", "query", "and", "return", "documents", "from", "the", "result", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/query.go#L15-L60
train
HouzuoGuo/tiedot
httpapi/query.go
Count
func Count(w http.ResponseWriter, r *http.Request) { w.Header().Set("Cache-Control", "must-revalidate") w.Header().Set("Content-Type", "text/plain") w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS") var col, q string if !Require(w, r, "col...
go
func Count(w http.ResponseWriter, r *http.Request) { w.Header().Set("Cache-Control", "must-revalidate") w.Header().Set("Content-Type", "text/plain") w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS") var col, q string if !Require(w, r, "col...
[ "func", "Count", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "w", ".", "Header", "(", ")", ".", "Set", "(", ...
// Execute a query and return number of documents from the result.
[ "Execute", "a", "query", "and", "return", "number", "of", "documents", "from", "the", "result", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/query.go#L63-L91
train
HouzuoGuo/tiedot
db/col.go
OpenCol
func OpenCol(db *DB, name string) (*Col, error) { col := &Col{db: db, name: name} return col, col.load() }
go
func OpenCol(db *DB, name string) (*Col, error) { col := &Col{db: db, name: name} return col, col.load() }
[ "func", "OpenCol", "(", "db", "*", "DB", ",", "name", "string", ")", "(", "*", "Col", ",", "error", ")", "{", "col", ":=", "&", "Col", "{", "db", ":", "db", ",", "name", ":", "name", "}", "\n", "return", "col", ",", "col", ".", "load", "(", ...
// Open a collection and load all indexes.
[ "Open", "a", "collection", "and", "load", "all", "indexes", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/col.go#L33-L36
train
HouzuoGuo/tiedot
db/col.go
load
func (col *Col) load() error { if err := os.MkdirAll(path.Join(col.db.path, col.name), 0700); err != nil { return err } col.parts = make([]*data.Partition, col.db.numParts) col.hts = make([]map[string]*data.HashTable, col.db.numParts) for i := 0; i < col.db.numParts; i++ { col.hts[i] = make(map[string]*data.Ha...
go
func (col *Col) load() error { if err := os.MkdirAll(path.Join(col.db.path, col.name), 0700); err != nil { return err } col.parts = make([]*data.Partition, col.db.numParts) col.hts = make([]map[string]*data.HashTable, col.db.numParts) for i := 0; i < col.db.numParts; i++ { col.hts[i] = make(map[string]*data.Ha...
[ "func", "(", "col", "*", "Col", ")", "load", "(", ")", "error", "{", "if", "err", ":=", "os", ".", "MkdirAll", "(", "path", ".", "Join", "(", "col", ".", "db", ".", "path", ",", "col", ".", "name", ")", ",", "0700", ")", ";", "err", "!=", "...
// Load collection schema including index schema.
[ "Load", "collection", "schema", "including", "index", "schema", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/col.go#L39-L79
train
HouzuoGuo/tiedot
db/col.go
close
func (col *Col) close() error { errs := make([]error, 0, 0) for i := 0; i < col.db.numParts; i++ { col.parts[i].DataLock.Lock() if err := col.parts[i].Close(); err != nil { errs = append(errs, err) } for _, ht := range col.hts[i] { if err := ht.Close(); err != nil { errs = append(errs, err) } }...
go
func (col *Col) close() error { errs := make([]error, 0, 0) for i := 0; i < col.db.numParts; i++ { col.parts[i].DataLock.Lock() if err := col.parts[i].Close(); err != nil { errs = append(errs, err) } for _, ht := range col.hts[i] { if err := ht.Close(); err != nil { errs = append(errs, err) } }...
[ "func", "(", "col", "*", "Col", ")", "close", "(", ")", "error", "{", "errs", ":=", "make", "(", "[", "]", "error", ",", "0", ",", "0", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "col", ".", "db", ".", "numParts", ";", "i", "++", "{...
// Close all collection files. Do not use the collection afterwards!
[ "Close", "all", "collection", "files", ".", "Do", "not", "use", "the", "collection", "afterwards!" ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/col.go#L82-L100
train
HouzuoGuo/tiedot
db/col.go
ForEachDoc
func (col *Col) ForEachDoc(fun func(id int, doc []byte) (moveOn bool)) { col.forEachDoc(fun, true) }
go
func (col *Col) ForEachDoc(fun func(id int, doc []byte) (moveOn bool)) { col.forEachDoc(fun, true) }
[ "func", "(", "col", "*", "Col", ")", "ForEachDoc", "(", "fun", "func", "(", "id", "int", ",", "doc", "[", "]", "byte", ")", "(", "moveOn", "bool", ")", ")", "{", "col", ".", "forEachDoc", "(", "fun", ",", "true", ")", "\n", "}" ]
// Do fun for all documents in the collection.
[ "Do", "fun", "for", "all", "documents", "in", "the", "collection", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/col.go#L126-L128
train
HouzuoGuo/tiedot
db/col.go
Index
func (col *Col) Index(idxPath []string) (err error) { col.db.schemaLock.Lock() defer col.db.schemaLock.Unlock() idxName := strings.Join(idxPath, INDEX_PATH_SEP) if _, exists := col.indexPaths[idxName]; exists { return fmt.Errorf("Path %v is already indexed", idxPath) } col.indexPaths[idxName] = idxPath idxDir ...
go
func (col *Col) Index(idxPath []string) (err error) { col.db.schemaLock.Lock() defer col.db.schemaLock.Unlock() idxName := strings.Join(idxPath, INDEX_PATH_SEP) if _, exists := col.indexPaths[idxName]; exists { return fmt.Errorf("Path %v is already indexed", idxPath) } col.indexPaths[idxName] = idxPath idxDir ...
[ "func", "(", "col", "*", "Col", ")", "Index", "(", "idxPath", "[", "]", "string", ")", "(", "err", "error", ")", "{", "col", ".", "db", ".", "schemaLock", ".", "Lock", "(", ")", "\n", "defer", "col", ".", "db", ".", "schemaLock", ".", "Unlock", ...
// Create an index on the path.
[ "Create", "an", "index", "on", "the", "path", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/col.go#L131-L164
train
HouzuoGuo/tiedot
db/col.go
Unindex
func (col *Col) Unindex(idxPath []string) error { col.db.schemaLock.Lock() defer col.db.schemaLock.Unlock() idxName := strings.Join(idxPath, INDEX_PATH_SEP) if _, exists := col.indexPaths[idxName]; !exists { return fmt.Errorf("Path %v is not indexed", idxPath) } delete(col.indexPaths, idxName) for i := 0; i < ...
go
func (col *Col) Unindex(idxPath []string) error { col.db.schemaLock.Lock() defer col.db.schemaLock.Unlock() idxName := strings.Join(idxPath, INDEX_PATH_SEP) if _, exists := col.indexPaths[idxName]; !exists { return fmt.Errorf("Path %v is not indexed", idxPath) } delete(col.indexPaths, idxName) for i := 0; i < ...
[ "func", "(", "col", "*", "Col", ")", "Unindex", "(", "idxPath", "[", "]", "string", ")", "error", "{", "col", ".", "db", ".", "schemaLock", ".", "Lock", "(", ")", "\n", "defer", "col", ".", "db", ".", "schemaLock", ".", "Unlock", "(", ")", "\n", ...
// Remove an index.
[ "Remove", "an", "index", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/col.go#L182-L198
train
HouzuoGuo/tiedot
db/col.go
ForEachDocInPage
func (col *Col) ForEachDocInPage(page, total int, fun func(id int, doc []byte) bool) { col.db.schemaLock.RLock() defer col.db.schemaLock.RUnlock() for iteratePart := 0; iteratePart < col.db.numParts; iteratePart++ { part := col.parts[iteratePart] part.DataLock.RLock() if !part.ForEachDoc(page, total, fun) { ...
go
func (col *Col) ForEachDocInPage(page, total int, fun func(id int, doc []byte) bool) { col.db.schemaLock.RLock() defer col.db.schemaLock.RUnlock() for iteratePart := 0; iteratePart < col.db.numParts; iteratePart++ { part := col.parts[iteratePart] part.DataLock.RLock() if !part.ForEachDoc(page, total, fun) { ...
[ "func", "(", "col", "*", "Col", ")", "ForEachDocInPage", "(", "page", ",", "total", "int", ",", "fun", "func", "(", "id", "int", ",", "doc", "[", "]", "byte", ")", "bool", ")", "{", "col", ".", "db", ".", "schemaLock", ".", "RLock", "(", ")", "...
// Divide the collection into roughly equally sized pages, and do fun on all documents in the specified page.
[ "Divide", "the", "collection", "into", "roughly", "equally", "sized", "pages", "and", "do", "fun", "on", "all", "documents", "in", "the", "specified", "page", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/col.go#L220-L232
train
HouzuoGuo/tiedot
db/doc.go
StrHash
func StrHash(str string) int { var hash int for _, c := range str { hash = int(c) + (hash << 6) + (hash << 16) - hash } if hash < 0 { return -hash } return hash }
go
func StrHash(str string) int { var hash int for _, c := range str { hash = int(c) + (hash << 6) + (hash << 16) - hash } if hash < 0 { return -hash } return hash }
[ "func", "StrHash", "(", "str", "string", ")", "int", "{", "var", "hash", "int", "\n", "for", "_", ",", "c", ":=", "range", "str", "{", "hash", "=", "int", "(", "c", ")", "+", "(", "hash", "<<", "6", ")", "+", "(", "hash", "<<", "16", ")", "...
// Hash a string using sdbm algorithm.
[ "Hash", "a", "string", "using", "sdbm", "algorithm", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/doc.go#L42-L51
train
HouzuoGuo/tiedot
db/doc.go
indexDoc
func (col *Col) indexDoc(id int, doc map[string]interface{}) { for idxName, idxPath := range col.indexPaths { for _, idxVal := range GetIn(doc, idxPath) { if idxVal != nil { hashKey := StrHash(fmt.Sprint(idxVal)) partNum := hashKey % col.db.numParts ht := col.hts[partNum][idxName] ht.Lock.Lock() ...
go
func (col *Col) indexDoc(id int, doc map[string]interface{}) { for idxName, idxPath := range col.indexPaths { for _, idxVal := range GetIn(doc, idxPath) { if idxVal != nil { hashKey := StrHash(fmt.Sprint(idxVal)) partNum := hashKey % col.db.numParts ht := col.hts[partNum][idxName] ht.Lock.Lock() ...
[ "func", "(", "col", "*", "Col", ")", "indexDoc", "(", "id", "int", ",", "doc", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "for", "idxName", ",", "idxPath", ":=", "range", "col", ".", "indexPaths", "{", "for", "_", ",", "idxVal", ...
// Put a document on all user-created indexes.
[ "Put", "a", "document", "on", "all", "user", "-", "created", "indexes", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/doc.go#L54-L67
train
HouzuoGuo/tiedot
db/doc.go
Insert
func (col *Col) Insert(doc map[string]interface{}) (id int, err error) { docJS, err := json.Marshal(doc) if err != nil { return } id = rand.Int() partNum := id % col.db.numParts col.db.schemaLock.RLock() part := col.parts[partNum] // Put document data into collection part.DataLock.Lock() _, err = part.Inse...
go
func (col *Col) Insert(doc map[string]interface{}) (id int, err error) { docJS, err := json.Marshal(doc) if err != nil { return } id = rand.Int() partNum := id % col.db.numParts col.db.schemaLock.RLock() part := col.parts[partNum] // Put document data into collection part.DataLock.Lock() _, err = part.Inse...
[ "func", "(", "col", "*", "Col", ")", "Insert", "(", "doc", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "id", "int", ",", "err", "error", ")", "{", "docJS", ",", "err", ":=", "json", ".", "Marshal", "(", "doc", ")", "\n", "if", ...
// Insert a document into the collection.
[ "Insert", "a", "document", "into", "the", "collection", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/doc.go#L103-L129
train
HouzuoGuo/tiedot
tdlog/tdlog.go
CritNoRepeat
func CritNoRepeat(template string, params ...interface{}) { msg := fmt.Sprintf(template, params...) critLock.Lock() if _, exists := critHistory[msg]; !exists { log.Print(msg) critHistory[msg] = struct{}{} } if len(critHistory) > limitCritHistory { critHistory = make(map[string]struct{}) } critLock.Unlock()...
go
func CritNoRepeat(template string, params ...interface{}) { msg := fmt.Sprintf(template, params...) critLock.Lock() if _, exists := critHistory[msg]; !exists { log.Print(msg) critHistory[msg] = struct{}{} } if len(critHistory) > limitCritHistory { critHistory = make(map[string]struct{}) } critLock.Unlock()...
[ "func", "CritNoRepeat", "(", "template", "string", ",", "params", "...", "interface", "{", "}", ")", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", "template", ",", "params", "...", ")", "\n", "critLock", ".", "Lock", "(", ")", "\n", "if", "_", ",", ...
// LVL 2 - will not repeat a message twice over the past 100 distinct crit messages
[ "LVL", "2", "-", "will", "not", "repeat", "a", "message", "twice", "over", "the", "past", "100", "distinct", "crit", "messages" ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/tdlog/tdlog.go#L41-L52
train
HouzuoGuo/tiedot
db/query.go
EvalUnion
func EvalUnion(exprs []interface{}, src *Col, result *map[int]struct{}) (err error) { for _, subExpr := range exprs { if err = evalQuery(subExpr, src, result, false); err != nil { return } } return }
go
func EvalUnion(exprs []interface{}, src *Col, result *map[int]struct{}) (err error) { for _, subExpr := range exprs { if err = evalQuery(subExpr, src, result, false); err != nil { return } } return }
[ "func", "EvalUnion", "(", "exprs", "[", "]", "interface", "{", "}", ",", "src", "*", "Col", ",", "result", "*", "map", "[", "int", "]", "struct", "{", "}", ")", "(", "err", "error", ")", "{", "for", "_", ",", "subExpr", ":=", "range", "exprs", ...
// Calculate union of sub-query results.
[ "Calculate", "union", "of", "sub", "-", "query", "results", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/query.go#L16-L23
train
HouzuoGuo/tiedot
db/query.go
EvalAllIDs
func EvalAllIDs(src *Col, result *map[int]struct{}) (err error) { src.forEachDoc(func(id int, _ []byte) bool { (*result)[id] = struct{}{} return true }, false) return }
go
func EvalAllIDs(src *Col, result *map[int]struct{}) (err error) { src.forEachDoc(func(id int, _ []byte) bool { (*result)[id] = struct{}{} return true }, false) return }
[ "func", "EvalAllIDs", "(", "src", "*", "Col", ",", "result", "*", "map", "[", "int", "]", "struct", "{", "}", ")", "(", "err", "error", ")", "{", "src", ".", "forEachDoc", "(", "func", "(", "id", "int", ",", "_", "[", "]", "byte", ")", "bool", ...
// Put all document IDs into result.
[ "Put", "all", "document", "IDs", "into", "result", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/query.go#L26-L32
train
HouzuoGuo/tiedot
db/query.go
Intersect
func Intersect(subExprs interface{}, src *Col, result *map[int]struct{}) (err error) { myResult := make(map[int]struct{}) if subExprVecs, ok := subExprs.([]interface{}); ok { first := true for _, subExpr := range subExprVecs { subResult := make(map[int]struct{}) intersection := make(map[int]struct{}) if ...
go
func Intersect(subExprs interface{}, src *Col, result *map[int]struct{}) (err error) { myResult := make(map[int]struct{}) if subExprVecs, ok := subExprs.([]interface{}); ok { first := true for _, subExpr := range subExprVecs { subResult := make(map[int]struct{}) intersection := make(map[int]struct{}) if ...
[ "func", "Intersect", "(", "subExprs", "interface", "{", "}", ",", "src", "*", "Col", ",", "result", "*", "map", "[", "int", "]", "struct", "{", "}", ")", "(", "err", "error", ")", "{", "myResult", ":=", "make", "(", "map", "[", "int", "]", "struc...
// Calculate intersection of sub-query results.
[ "Calculate", "intersection", "of", "sub", "-", "query", "results", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/query.go#L135-L164
train
HouzuoGuo/tiedot
db/query.go
Complement
func Complement(subExprs interface{}, src *Col, result *map[int]struct{}) (err error) { myResult := make(map[int]struct{}) if subExprVecs, ok := subExprs.([]interface{}); ok { for _, subExpr := range subExprVecs { subResult := make(map[int]struct{}) complement := make(map[int]struct{}) if err = evalQuery(s...
go
func Complement(subExprs interface{}, src *Col, result *map[int]struct{}) (err error) { myResult := make(map[int]struct{}) if subExprVecs, ok := subExprs.([]interface{}); ok { for _, subExpr := range subExprVecs { subResult := make(map[int]struct{}) complement := make(map[int]struct{}) if err = evalQuery(s...
[ "func", "Complement", "(", "subExprs", "interface", "{", "}", ",", "src", "*", "Col", ",", "result", "*", "map", "[", "int", "]", "struct", "{", "}", ")", "(", "err", "error", ")", "{", "myResult", ":=", "make", "(", "map", "[", "int", "]", "stru...
// Calculate complement of sub-query results.
[ "Calculate", "complement", "of", "sub", "-", "query", "results", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/db/query.go#L167-L195
train
HouzuoGuo/tiedot
data/file.go
LooksEmpty
func LooksEmpty(buf gommap.MMap) bool { upTo := 1024 if upTo >= len(buf) { upTo = len(buf) - 1 } for i := 0; i < upTo; i++ { if buf[i] != 0 { return false } } return true }
go
func LooksEmpty(buf gommap.MMap) bool { upTo := 1024 if upTo >= len(buf) { upTo = len(buf) - 1 } for i := 0; i < upTo; i++ { if buf[i] != 0 { return false } } return true }
[ "func", "LooksEmpty", "(", "buf", "gommap", ".", "MMap", ")", "bool", "{", "upTo", ":=", "1024", "\n", "if", "upTo", ">=", "len", "(", "buf", ")", "{", "upTo", "=", "len", "(", "buf", ")", "-", "1", "\n", "}", "\n", "for", "i", ":=", "0", ";"...
// Return true if the buffer begins with 64 consecutive zero bytes.
[ "Return", "true", "if", "the", "buffer", "begins", "with", "64", "consecutive", "zero", "bytes", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/file.go#L21-L32
train
HouzuoGuo/tiedot
data/file.go
OpenDataFile
func OpenDataFile(path string, growth int) (file *DataFile, err error) { file = &DataFile{Path: path, Growth: growth} if file.Fh, err = os.OpenFile(file.Path, os.O_CREATE|os.O_RDWR, 0600); err != nil { return } var size int64 if size, err = file.Fh.Seek(0, os.SEEK_END); err != nil { return } // Ensure the fi...
go
func OpenDataFile(path string, growth int) (file *DataFile, err error) { file = &DataFile{Path: path, Growth: growth} if file.Fh, err = os.OpenFile(file.Path, os.O_CREATE|os.O_RDWR, 0600); err != nil { return } var size int64 if size, err = file.Fh.Seek(0, os.SEEK_END); err != nil { return } // Ensure the fi...
[ "func", "OpenDataFile", "(", "path", "string", ",", "growth", "int", ")", "(", "file", "*", "DataFile", ",", "err", "error", ")", "{", "file", "=", "&", "DataFile", "{", "Path", ":", "path", ",", "Growth", ":", "growth", "}", "\n", "if", "file", "....
// Open a data file that grows by the specified size.
[ "Open", "a", "data", "file", "that", "grows", "by", "the", "specified", "size", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/file.go#L35-L77
train
HouzuoGuo/tiedot
data/file.go
overwriteWithZero
func (file *DataFile) overwriteWithZero(from int, size int) (err error) { if _, err = file.Fh.Seek(int64(from), os.SEEK_SET); err != nil { return } zeroSize := 1048576 * 8 // Fill 8 MB at a time zero := make([]byte, zeroSize) for i := 0; i < size; i += zeroSize { var zeroSlice []byte if i+zeroSize > size { ...
go
func (file *DataFile) overwriteWithZero(from int, size int) (err error) { if _, err = file.Fh.Seek(int64(from), os.SEEK_SET); err != nil { return } zeroSize := 1048576 * 8 // Fill 8 MB at a time zero := make([]byte, zeroSize) for i := 0; i < size; i += zeroSize { var zeroSlice []byte if i+zeroSize > size { ...
[ "func", "(", "file", "*", "DataFile", ")", "overwriteWithZero", "(", "from", "int", ",", "size", "int", ")", "(", "err", "error", ")", "{", "if", "_", ",", "err", "=", "file", ".", "Fh", ".", "Seek", "(", "int64", "(", "from", ")", ",", "os", "...
// Fill up portion of a file with 0s.
[ "Fill", "up", "portion", "of", "a", "file", "with", "0s", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/file.go#L80-L98
train
HouzuoGuo/tiedot
data/file.go
EnsureSize
func (file *DataFile) EnsureSize(more int) (err error) { if file.Used+more <= file.Size { return } else if file.Buf != nil { if err = file.Buf.Unmap(); err != nil { return } } if err = file.overwriteWithZero(file.Size, file.Growth); err != nil { return } else if file.Buf, err = gommap.Map(file.Fh); err ...
go
func (file *DataFile) EnsureSize(more int) (err error) { if file.Used+more <= file.Size { return } else if file.Buf != nil { if err = file.Buf.Unmap(); err != nil { return } } if err = file.overwriteWithZero(file.Size, file.Growth); err != nil { return } else if file.Buf, err = gommap.Map(file.Fh); err ...
[ "func", "(", "file", "*", "DataFile", ")", "EnsureSize", "(", "more", "int", ")", "(", "err", "error", ")", "{", "if", "file", ".", "Used", "+", "more", "<=", "file", ".", "Size", "{", "return", "\n", "}", "else", "if", "file", ".", "Buf", "!=", ...
// Ensure there is enough room for that many bytes of data.
[ "Ensure", "there", "is", "enough", "room", "for", "that", "many", "bytes", "of", "data", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/file.go#L101-L117
train
HouzuoGuo/tiedot
data/file.go
Close
func (file *DataFile) Close() (err error) { if err = file.Buf.Unmap(); err != nil { return } return file.Fh.Close() }
go
func (file *DataFile) Close() (err error) { if err = file.Buf.Unmap(); err != nil { return } return file.Fh.Close() }
[ "func", "(", "file", "*", "DataFile", ")", "Close", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "file", ".", "Buf", ".", "Unmap", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "return", "file", ".", "Fh", "...
// Un-map the file buffer and close the file handle.
[ "Un", "-", "map", "the", "file", "buffer", "and", "close", "the", "file", "handle", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/file.go#L120-L125
train
HouzuoGuo/tiedot
data/file.go
Clear
func (file *DataFile) Clear() (err error) { if err = file.Close(); err != nil { return } else if err = os.Truncate(file.Path, 0); err != nil { return } else if file.Fh, err = os.OpenFile(file.Path, os.O_CREATE|os.O_RDWR, 0600); err != nil { return } else if err = file.overwriteWithZero(0, file.Growth); err !=...
go
func (file *DataFile) Clear() (err error) { if err = file.Close(); err != nil { return } else if err = os.Truncate(file.Path, 0); err != nil { return } else if file.Fh, err = os.OpenFile(file.Path, os.O_CREATE|os.O_RDWR, 0600); err != nil { return } else if err = file.overwriteWithZero(0, file.Growth); err !=...
[ "func", "(", "file", "*", "DataFile", ")", "Clear", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "file", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "else", "if", "err", "=", "os", ".", "Truncate", ...
// Clear the entire file and resize it to initial size.
[ "Clear", "the", "entire", "file", "and", "resize", "it", "to", "initial", "size", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/file.go#L128-L143
train
HouzuoGuo/tiedot
data/collection.go
OpenCollection
func (conf *Config) OpenCollection(path string) (col *Collection, err error) { col = new(Collection) col.DataFile, err = OpenDataFile(path, conf.ColFileGrowth) col.Config = conf col.Config.CalculateConfigConstants() return }
go
func (conf *Config) OpenCollection(path string) (col *Collection, err error) { col = new(Collection) col.DataFile, err = OpenDataFile(path, conf.ColFileGrowth) col.Config = conf col.Config.CalculateConfigConstants() return }
[ "func", "(", "conf", "*", "Config", ")", "OpenCollection", "(", "path", "string", ")", "(", "col", "*", "Collection", ",", "err", "error", ")", "{", "col", "=", "new", "(", "Collection", ")", "\n", "col", ".", "DataFile", ",", "err", "=", "OpenDataFi...
// Open a collection file.
[ "Open", "a", "collection", "file", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/collection.go#L30-L36
train
HouzuoGuo/tiedot
data/collection.go
Insert
func (col *Collection) Insert(data []byte) (id int, err error) { room := len(data) << 1 if room > col.DocMaxRoom { return 0, dberr.New(dberr.ErrorDocTooLarge, col.DocMaxRoom, room) } id = col.Used docSize := DocHeader + room if err = col.EnsureSize(docSize); err != nil { return } col.Used += docSize // Wri...
go
func (col *Collection) Insert(data []byte) (id int, err error) { room := len(data) << 1 if room > col.DocMaxRoom { return 0, dberr.New(dberr.ErrorDocTooLarge, col.DocMaxRoom, room) } id = col.Used docSize := DocHeader + room if err = col.EnsureSize(docSize); err != nil { return } col.Used += docSize // Wri...
[ "func", "(", "col", "*", "Collection", ")", "Insert", "(", "data", "[", "]", "byte", ")", "(", "id", "int", ",", "err", "error", ")", "{", "room", ":=", "len", "(", "data", ")", "<<", "1", "\n", "if", "room", ">", "col", ".", "DocMaxRoom", "{",...
// Insert a new document, return the new document ID.
[ "Insert", "a", "new", "document", "return", "the", "new", "document", "ID", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/collection.go#L54-L77
train
HouzuoGuo/tiedot
data/collection.go
Update
func (col *Collection) Update(id int, data []byte) (newID int, err error) { dataLen := len(data) if dataLen > col.DocMaxRoom { return 0, dberr.New(dberr.ErrorDocTooLarge, col.DocMaxRoom, dataLen) } if id < 0 || id >= col.Used-DocHeader || col.Buf[id] != 1 { return 0, dberr.New(dberr.ErrorNoDoc, id) } currentD...
go
func (col *Collection) Update(id int, data []byte) (newID int, err error) { dataLen := len(data) if dataLen > col.DocMaxRoom { return 0, dberr.New(dberr.ErrorDocTooLarge, col.DocMaxRoom, dataLen) } if id < 0 || id >= col.Used-DocHeader || col.Buf[id] != 1 { return 0, dberr.New(dberr.ErrorNoDoc, id) } currentD...
[ "func", "(", "col", "*", "Collection", ")", "Update", "(", "id", "int", ",", "data", "[", "]", "byte", ")", "(", "newID", "int", ",", "err", "error", ")", "{", "dataLen", ":=", "len", "(", "data", ")", "\n", "if", "dataLen", ">", "col", ".", "D...
// Overwrite or re-insert a document, return the new document ID if re-inserted.
[ "Overwrite", "or", "re", "-", "insert", "a", "document", "return", "the", "new", "document", "ID", "if", "re", "-", "inserted", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/collection.go#L80-L113
train
HouzuoGuo/tiedot
data/collection.go
Delete
func (col *Collection) Delete(id int) error { if id < 0 || id > col.Used-DocHeader || col.Buf[id] != 1 { return dberr.New(dberr.ErrorNoDoc, id) } if col.Buf[id] == 1 { col.Buf[id] = 0 } return nil }
go
func (col *Collection) Delete(id int) error { if id < 0 || id > col.Used-DocHeader || col.Buf[id] != 1 { return dberr.New(dberr.ErrorNoDoc, id) } if col.Buf[id] == 1 { col.Buf[id] = 0 } return nil }
[ "func", "(", "col", "*", "Collection", ")", "Delete", "(", "id", "int", ")", "error", "{", "if", "id", "<", "0", "||", "id", ">", "col", ".", "Used", "-", "DocHeader", "||", "col", ".", "Buf", "[", "id", "]", "!=", "1", "{", "return", "dberr", ...
// Delete a document by ID.
[ "Delete", "a", "document", "by", "ID", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/collection.go#L116-L127
train
HouzuoGuo/tiedot
data/collection.go
ForEachDoc
func (col *Collection) ForEachDoc(fun func(id int, doc []byte) bool) { for id := 0; id < col.Used-DocHeader && id >= 0; { validity := col.Buf[id] room, _ := binary.Varint(col.Buf[id+1 : id+11]) docEnd := id + DocHeader + int(room) if (validity == 0 || validity == 1) && room <= int64(col.DocMaxRoom) && docEnd >...
go
func (col *Collection) ForEachDoc(fun func(id int, doc []byte) bool) { for id := 0; id < col.Used-DocHeader && id >= 0; { validity := col.Buf[id] room, _ := binary.Varint(col.Buf[id+1 : id+11]) docEnd := id + DocHeader + int(room) if (validity == 0 || validity == 1) && room <= int64(col.DocMaxRoom) && docEnd >...
[ "func", "(", "col", "*", "Collection", ")", "ForEachDoc", "(", "fun", "func", "(", "id", "int", ",", "doc", "[", "]", "byte", ")", "bool", ")", "{", "for", "id", ":=", "0", ";", "id", "<", "col", ".", "Used", "-", "DocHeader", "&&", "id", ">=",...
// Run the function on every document; stop when the function returns false.
[ "Run", "the", "function", "on", "every", "document", ";", "stop", "when", "the", "function", "returns", "false", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/collection.go#L130-L145
train
HouzuoGuo/tiedot
httpapi/index.go
Index
func Index(w http.ResponseWriter, r *http.Request) { w.Header().Set("Cache-Control", "must-revalidate") w.Header().Set("Content-Type", "text/plain") w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS") var col, path string if !Require(w, r, "...
go
func Index(w http.ResponseWriter, r *http.Request) { w.Header().Set("Cache-Control", "must-revalidate") w.Header().Set("Content-Type", "text/plain") w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS") var col, path string if !Require(w, r, "...
[ "func", "Index", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "w", ".", "Header", "(", ")", ".", "Set", "(", ...
// Put an index on a document path.
[ "Put", "an", "index", "on", "a", "document", "path", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/httpapi/index.go#L13-L35
train
HouzuoGuo/tiedot
data/hashtable.go
OpenHashTable
func (conf *Config) OpenHashTable(path string) (ht *HashTable, err error) { ht = &HashTable{Config: conf, Lock: new(sync.RWMutex)} if ht.DataFile, err = OpenDataFile(path, ht.HTFileGrowth); err != nil { return } conf.CalculateConfigConstants() ht.calculateNumBuckets() return }
go
func (conf *Config) OpenHashTable(path string) (ht *HashTable, err error) { ht = &HashTable{Config: conf, Lock: new(sync.RWMutex)} if ht.DataFile, err = OpenDataFile(path, ht.HTFileGrowth); err != nil { return } conf.CalculateConfigConstants() ht.calculateNumBuckets() return }
[ "func", "(", "conf", "*", "Config", ")", "OpenHashTable", "(", "path", "string", ")", "(", "ht", "*", "HashTable", ",", "err", "error", ")", "{", "ht", "=", "&", "HashTable", "{", "Config", ":", "conf", ",", "Lock", ":", "new", "(", "sync", ".", ...
// Open a hash table file.
[ "Open", "a", "hash", "table", "file", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/hashtable.go#L30-L38
train
HouzuoGuo/tiedot
data/hashtable.go
calculateNumBuckets
func (ht *HashTable) calculateNumBuckets() { ht.numBuckets = ht.Size / ht.BucketSize largestBucketNum := ht.InitialBuckets - 1 for i := 0; i < ht.InitialBuckets; i++ { lastBucket := ht.lastBucket(i) if lastBucket > largestBucketNum && lastBucket < ht.numBuckets { largestBucketNum = lastBucket } } ht.numBu...
go
func (ht *HashTable) calculateNumBuckets() { ht.numBuckets = ht.Size / ht.BucketSize largestBucketNum := ht.InitialBuckets - 1 for i := 0; i < ht.InitialBuckets; i++ { lastBucket := ht.lastBucket(i) if lastBucket > largestBucketNum && lastBucket < ht.numBuckets { largestBucketNum = lastBucket } } ht.numBu...
[ "func", "(", "ht", "*", "HashTable", ")", "calculateNumBuckets", "(", ")", "{", "ht", ".", "numBuckets", "=", "ht", ".", "Size", "/", "ht", ".", "BucketSize", "\n", "largestBucketNum", ":=", "ht", ".", "InitialBuckets", "-", "1", "\n", "for", "i", ":="...
// Follow the longest bucket chain to calculate total number of buckets, hence the "used size" of hash table file.
[ "Follow", "the", "longest", "bucket", "chain", "to", "calculate", "total", "number", "of", "buckets", "hence", "the", "used", "size", "of", "hash", "table", "file", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/hashtable.go#L41-L58
train
HouzuoGuo/tiedot
data/hashtable.go
nextBucket
func (ht *HashTable) nextBucket(bucket int) int { if bucket >= ht.numBuckets { return 0 } bucketAddr := bucket * ht.BucketSize nextUint, err := binary.Varint(ht.Buf[bucketAddr : bucketAddr+10]) next := int(nextUint) if next == 0 { return 0 } else if err < 0 || next <= bucket || next >= ht.numBuckets || next ...
go
func (ht *HashTable) nextBucket(bucket int) int { if bucket >= ht.numBuckets { return 0 } bucketAddr := bucket * ht.BucketSize nextUint, err := binary.Varint(ht.Buf[bucketAddr : bucketAddr+10]) next := int(nextUint) if next == 0 { return 0 } else if err < 0 || next <= bucket || next >= ht.numBuckets || next ...
[ "func", "(", "ht", "*", "HashTable", ")", "nextBucket", "(", "bucket", "int", ")", "int", "{", "if", "bucket", ">=", "ht", ".", "numBuckets", "{", "return", "0", "\n", "}", "\n", "bucketAddr", ":=", "bucket", "*", "ht", ".", "BucketSize", "\n", "next...
// Return number of the next chained bucket.
[ "Return", "number", "of", "the", "next", "chained", "bucket", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/hashtable.go#L61-L76
train
HouzuoGuo/tiedot
data/hashtable.go
lastBucket
func (ht *HashTable) lastBucket(bucket int) int { for curr := bucket; ; { next := ht.nextBucket(curr) if next == 0 { return curr } curr = next } }
go
func (ht *HashTable) lastBucket(bucket int) int { for curr := bucket; ; { next := ht.nextBucket(curr) if next == 0 { return curr } curr = next } }
[ "func", "(", "ht", "*", "HashTable", ")", "lastBucket", "(", "bucket", "int", ")", "int", "{", "for", "curr", ":=", "bucket", ";", ";", "{", "next", ":=", "ht", ".", "nextBucket", "(", "curr", ")", "\n", "if", "next", "==", "0", "{", "return", "c...
// Return number of the last bucket in chain.
[ "Return", "number", "of", "the", "last", "bucket", "in", "chain", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/hashtable.go#L79-L87
train
HouzuoGuo/tiedot
data/hashtable.go
growBucket
func (ht *HashTable) growBucket(bucket int) { ht.EnsureSize(ht.BucketSize) lastBucketAddr := ht.lastBucket(bucket) * ht.BucketSize binary.PutVarint(ht.Buf[lastBucketAddr:lastBucketAddr+10], int64(ht.numBuckets)) ht.Used += ht.BucketSize ht.numBuckets++ }
go
func (ht *HashTable) growBucket(bucket int) { ht.EnsureSize(ht.BucketSize) lastBucketAddr := ht.lastBucket(bucket) * ht.BucketSize binary.PutVarint(ht.Buf[lastBucketAddr:lastBucketAddr+10], int64(ht.numBuckets)) ht.Used += ht.BucketSize ht.numBuckets++ }
[ "func", "(", "ht", "*", "HashTable", ")", "growBucket", "(", "bucket", "int", ")", "{", "ht", ".", "EnsureSize", "(", "ht", ".", "BucketSize", ")", "\n", "lastBucketAddr", ":=", "ht", ".", "lastBucket", "(", "bucket", ")", "*", "ht", ".", "BucketSize",...
// Create and chain a new bucket.
[ "Create", "and", "chain", "a", "new", "bucket", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/hashtable.go#L90-L96
train
HouzuoGuo/tiedot
data/hashtable.go
Clear
func (ht *HashTable) Clear() (err error) { if err = ht.DataFile.Clear(); err != nil { return } ht.calculateNumBuckets() return }
go
func (ht *HashTable) Clear() (err error) { if err = ht.DataFile.Clear(); err != nil { return } ht.calculateNumBuckets() return }
[ "func", "(", "ht", "*", "HashTable", ")", "Clear", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "ht", ".", "DataFile", ".", "Clear", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "ht", ".", "calculateNumBuckets"...
// Clear the entire hash table.
[ "Clear", "the", "entire", "hash", "table", "." ]
be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39
https://github.com/HouzuoGuo/tiedot/blob/be8ab1f1598ed275ad3857e5d5f23ddc1f8b8b39/data/hashtable.go#L99-L105
train