本文整理汇总了Golang中hash/adler32.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestDeepObjectPointer

func TestDeepObjectPointer(t *testing.T) {
    // Arrange
    wheel1 := wheel{radius: 17}
    wheel2 := wheel{radius: 22}
    wheel3 := wheel{radius: 17}

    myUni1 := unicycle{licencePlateID: "blah", primaryWheel: &wheel1, tags: map[string]string{"color": "blue", "name": "john"}}
    myUni2 := unicycle{licencePlateID: "blah", primaryWheel: &wheel2, tags: map[string]string{"color": "blue", "name": "john"}}
    myUni3 := unicycle{licencePlateID: "blah", primaryWheel: &wheel3, tags: map[string]string{"color": "blue", "name": "john"}}

    // Run it more than once to verify determinism of hasher.
    for i := 0; i < 100; i++ {
        hasher1 := adler32.New()
        hasher2 := adler32.New()
        hasher3 := adler32.New()
        // Act
        DeepHashObject(hasher1, myUni1)
        hash1 := hasher1.Sum32()
        DeepHashObject(hasher2, myUni2)
        hash2 := hasher2.Sum32()
        DeepHashObject(hasher3, myUni3)
        hash3 := hasher3.Sum32()

        // Assert
        if hash1 == hash2 {
            t.Errorf("hash1 (%d) and hash2(%d) must be different because they have different values for wheel size", hash1, hash2)
        }

        if hash1 != hash3 {
            t.Errorf("hash1 (%d) and hash3(%d) must be the same because although they point to different objects, they have the same values for wheel size", hash1, hash3)
        }
    }
}

开发者ID:brorhie,项目名称:panamax-kubernetes-adapter-go,代码行数:33,代码来源:hash_test.go

示例2: TestDeepObjectPointer

func TestDeepObjectPointer(t *testing.T) {
    // Arrange
    wheel1 := wheel{radius: 17}
    wheel2 := wheel{radius: 22}
    wheel3 := wheel{radius: 17}

    myUni1 := unicycle{licencePlateID: "blah", primaryWheel: &wheel1}
    myUni2 := unicycle{licencePlateID: "blah", primaryWheel: &wheel2}
    myUni3 := unicycle{licencePlateID: "blah", primaryWheel: &wheel3}

    hasher1 := adler32.New()
    hasher2 := adler32.New()
    hasher3 := adler32.New()

    // Act
    DeepHashObject(hasher1, myUni1)
    hash1 := hasher1.Sum32()
    DeepHashObject(hasher2, myUni2)
    hash2 := hasher2.Sum32()
    DeepHashObject(hasher3, myUni3)
    hash3 := hasher3.Sum32()

    // Assert
    if hash1 == hash2 {
        t.Errorf("hash1 (%d) and hash2(%d) must be different because they have different values for wheel size", hash1, hash2)
    }

    if hash1 != hash3 {
        t.Errorf("hash1 (%d) and hash3(%d) must be the same because although they point to different objects, they have the same values for wheel size", hash1, hash3)
    }
}

开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:31,代码来源:hash_test.go

示例3: syncPrinters

func (pm *PrinterManager) syncPrinters(ignorePrivet bool) error {
    glog.Info("Synchronizing printers, stand by")

    // Get current snapshot of CUPS printers.
    cupsPrinters, err := pm.cups.GetPrinters()
    if err != nil {
        return fmt.Errorf("Sync failed while calling GetPrinters(): %s", err)
    }
    if pm.ignoreRawPrinters {
        cupsPrinters, _ = lib.FilterRawPrinters(cupsPrinters)
    }

    // Augment CUPS printers with extra information from SNMP.
    if pm.snmp != nil {
        err = pm.snmp.AugmentPrinters(cupsPrinters)
        if err != nil {
            glog.Warningf("Failed to augment printers with SNMP data: %s", err)
        }
    }

    // Set CapsHash on all printers.
    for i := range cupsPrinters {
        h := adler32.New()
        lib.DeepHash(cupsPrinters[i].Tags, h)
        cupsPrinters[i].Tags["tagshash"] = fmt.Sprintf("%x", h.Sum(nil))

        h = adler32.New()
        lib.DeepHash(cupsPrinters[i].Description, h)
        cupsPrinters[i].CapsHash = fmt.Sprintf("%x", h.Sum(nil))
    }

    // Compare the snapshot to what we know currently.
    diffs := lib.DiffPrinters(cupsPrinters, pm.printers.GetAll())
    if diffs == nil {
        glog.Infof("Printers are already in sync; there are %d", len(cupsPrinters))
        return nil
    }

    // Update GCP.
    ch := make(chan lib.Printer, len(diffs))
    for i := range diffs {
        go pm.applyDiff(&diffs[i], ch, ignorePrivet)
    }
    currentPrinters := make([]lib.Printer, 0, len(diffs))
    for _ = range diffs {
        p := <-ch
        if p.Name != "" {
            currentPrinters = append(currentPrinters, p)
        }
    }

    // Update what we know.
    pm.printers.Refresh(currentPrinters)
    glog.Infof("Finished synchronizing %d printers", len(currentPrinters))

    return nil
}

开发者ID:TechEdge01,项目名称:cups-connector,代码行数:57,代码来源:printermanager.go

示例4: TestDeepHashObject

func TestDeepHashObject(t *testing.T) {
    successCases := []func() interface{}{
        func() interface{} { return 8675309 },
        func() interface{} { return "Jenny, I got your number" },
        func() interface{} { return []string{"eight", "six", "seven"} },
        func() interface{} { return [...]int{5, 3, 0, 9} },
        func() interface{} { return map[int]string{8: "8", 6: "6", 7: "7"} },
        func() interface{} { return map[string]int{"5": 5, "3": 3, "0": 0, "9": 9} },
        func() interface{} { return A{867, "5309"} },
        func() interface{} { return &A{867, "5309"} },
        func() interface{} {
            return B{[]int{8, 6, 7}, map[string]bool{"5": true, "3": true, "0": true, "9": true}}
        },
        func() interface{} { return map[A]bool{A{8675309, "Jenny"}: true, A{9765683, "!Jenny"}: false} },
        func() interface{} { return map[C]bool{C{8675309, "Jenny"}: true, C{9765683, "!Jenny"}: false} },
        func() interface{} { return map[*A]bool{&A{8675309, "Jenny"}: true, &A{9765683, "!Jenny"}: false} },
        func() interface{} { return map[*C]bool{&C{8675309, "Jenny"}: true, &C{9765683, "!Jenny"}: false} },
    }

    for _, tc := range successCases {
        hasher1 := adler32.New()
        DeepHashObject(hasher1, tc())
        hash1 := hasher1.Sum32()
        DeepHashObject(hasher1, tc())
        hash2 := hasher1.Sum32()
        if hash1 != hash2 {
            t.Fatalf("hash of the same object (%q) produced different results: %d vs %d", toString(tc()), hash1, hash2)
        }
        for i := 0; i < 100; i++ {
            hasher2 := adler32.New()

            DeepHashObject(hasher1, tc())
            hash1a := hasher1.Sum32()
            DeepHashObject(hasher2, tc())
            hash2a := hasher2.Sum32()

            if hash1a != hash1 {
                t.Errorf("repeated hash of the same object (%q) produced different results: %d vs %d", toString(tc()), hash1, hash1a)
            }
            if hash2a != hash2 {
                t.Errorf("repeated hash of the same object (%q) produced different results: %d vs %d", toString(tc()), hash2, hash2a)
            }
            if hash1a != hash2a {
                t.Errorf("hash of the same object produced (%q) different results: %d vs %d", toString(tc()), hash1a, hash2a)
            }
        }
    }
}

开发者ID:40a,项目名称:bootkube,代码行数:48,代码来源:hash_test.go

示例5: picHash

func picHash(picf io.Reader) string {
    hash := adler32.New()
    if _, err := io.Copy(hash, picf); err != nil {
        log.Panic(err)
    }
    return fmt.Sprintf("%x", hash.Sum32())
}

开发者ID:afajl,项目名称:am,代码行数:7,代码来源:pic.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng