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

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

示例1: parsePLTE

func (d *decoder) parsePLTE(r io.Reader, crc hash.Hash32, length uint32) os.Error {
    np := int(length / 3) // The number of palette entries.
    if length%3 != 0 || np <= 0 || np > 256 {
        return FormatError("bad PLTE length")
    }
    n, err := io.ReadFull(r, d.tmp[0:3*np])
    if err != nil {
        return err
    }
    crc.Write(d.tmp[0:n])
    switch d.colorType {
    case ctPaletted:
        palette := make([]image.Color, np)
        for i := 0; i < np; i++ {
            palette[i] = image.RGBAColor{d.tmp[3*i+0], d.tmp[3*i+1], d.tmp[3*i+2], 0xff}
        }
        d.image.(*image.Paletted).Palette = image.PalettedColorModel(palette)
    case ctTrueColor, ctTrueColorAlpha:
        // As per the PNG spec, a PLTE chunk is optional (and for practical purposes,
        // ignorable) for the ctTrueColor and ctTrueColorAlpha color types (section 4.1.2).
        return nil
    default:
        return FormatError("PLTE, color type mismatch")
    }
    return nil
}

开发者ID:rapgamer,项目名称:golang-china,代码行数:26,代码来源:reader.go

示例2: parsetRNS

func (d *decoder) parsetRNS(r io.Reader, crc hash.Hash32, length uint32) os.Error {
    if length > 256 {
        return FormatError("bad tRNS length")
    }
    n, err := io.ReadFull(r, d.tmp[0:length])
    if err != nil {
        return err
    }
    crc.Write(d.tmp[0:n])
    switch d.cb {
    case cbG8, cbG16:
        return UnsupportedError("grayscale transparency")
    case cbTC8, cbTC16:
        return UnsupportedError("truecolor transparency")
    case cbP8:
        if n > len(d.palette) {
            return FormatError("bad tRNS length")
        }
        for i := 0; i < n; i++ {
            rgba := d.palette[i].(image.RGBAColor)
            d.palette[i] = image.RGBAColor{rgba.R, rgba.G, rgba.B, d.tmp[i]}
        }
    case cbTCA8, cbTCA16:
        return FormatError("tRNS, color type mismatch")
    }
    return nil
}

开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:27,代码来源:reader.go

示例3: parsetRNS

func (d *decoder) parsetRNS(r io.Reader, crc hash.Hash32, length uint32) os.Error {
    if length > 256 {
        return FormatError("bad tRNS length")
    }
    n, err := io.ReadFull(r, d.tmp[0:length])
    if err != nil {
        return err
    }
    crc.Write(d.tmp[0:n])
    switch d.colorType {
    case ctTrueColor:
        return UnsupportedError("TrueColor transparency")
    case ctPaletted:
        p := d.image.(*image.Paletted).Palette
        if n > len(p) {
            return FormatError("bad tRNS length")
        }
        for i := 0; i < n; i++ {
            rgba := p[i].(image.RGBAColor)
            p[i] = image.RGBAColor{rgba.R, rgba.G, rgba.B, d.tmp[i]}
        }
    case ctTrueColorAlpha:
        return FormatError("tRNS, color type mismatch")
    }
    return nil
}

开发者ID:rapgamer,项目名称:golang-china,代码行数:26,代码来源:reader.go

示例4: TestRef

func TestRef(t *testing.T) {
    for _, elem := range data {

        var h32 hash.Hash32 = New32()
        h32.Write([]byte(elem.s))
        if v := h32.Sum32(); v != elem.h32 {
            t.Errorf("'%s': 0x%x (want 0x%x)", elem.s, v, elem.h32)
        }

        if v := Sum32([]byte(elem.s)); v != elem.h32 {
            t.Errorf("'%s': 0x%x (want 0x%x)", elem.s, v, elem.h32)
        }

        var h64 hash.Hash64 = New64()
        h64.Write([]byte(elem.s))
        if v := h64.Sum64(); v != elem.h64_1 {
            t.Errorf("'%s': 0x%x (want 0x%x)", elem.s, v, elem.h64_1)
        }

        var h128 Hash128 = New128()
        h128.Write([]byte(elem.s))
        if v1, v2 := h128.Sum128(); v1 != elem.h64_1 || v2 != elem.h64_2 {
            t.Errorf("'%s': 0x%x-0x%x (want 0x%x-0x%x)", elem.s, v1, v2, elem.h64_1, elem.h64_2)
        }

        if v1, v2 := Sum128([]byte(elem.s)); v1 != elem.h64_1 || v2 != elem.h64_2 {
            t.Errorf("'%s': 0x%x-0x%x (want 0x%x-0x%x)", elem.s, v1, v2, elem.h64_1, elem.h64_2)
        }
    }
}

开发者ID:venliong,项目名称:murmur3,代码行数:30,代码来源:murmur_test.go

示例5: copyUpwards1

/*
   Helper function for copyUpwards. Recursive.
*/
func (node *SpecializationPathNode) copyUpwards1(downNode *SpecializationPathNode, h hash.Hash32) *SpecializationPathNode {
    h.Write([]byte(node.Type.Name))
    copiedNode := &SpecializationPathNode{Up: nil, Down: downNode, Level: node.Level, Type: node.Type}
    if node.Up != nil {
        copiedUpNode := node.Up.copyUpwards1(copiedNode, h)
        copiedNode.Up = copiedUpNode
    }
    return copiedNode
}

开发者ID:eric-hawthorne,项目名称:relishpl-pre-code-cleanup,代码行数:12,代码来源:rtype.go

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