The Go Programming Language

Source file src/pkg/compress/flate/util.go

     1	// Copyright 2009 The Go Authors. All rights reserved.
     2	// Use of this source code is governed by a BSD-style
     3	// license that can be found in the LICENSE file.
     4	
     5	package flate
     6	
     7	func min(left int, right int) int {
     8		if left < right {
     9			return left
    10		}
    11		return right
    12	}
    13	
    14	func minInt32(left int32, right int32) int32 {
    15		if left < right {
    16			return left
    17		}
    18		return right
    19	}
    20	
    21	func max(left int, right int) int {
    22		if left > right {
    23			return left
    24		}
    25		return right
    26	}
    27	
    28	func fillInts(a []int, value int) {
    29		for i := range a {
    30			a[i] = value
    31		}
    32	}
    33	
    34	func fillInt32s(a []int32, value int32) {
    35		for i := range a {
    36			a[i] = value
    37		}
    38	}
    39	
    40	func fillBytes(a []byte, value byte) {
    41		for i := range a {
    42			a[i] = value
    43		}
    44	}
    45	
    46	func fillInt8s(a []int8, value int8) {
    47		for i := range a {
    48			a[i] = value
    49		}
    50	}
    51	
    52	func fillUint8s(a []uint8, value uint8) {
    53		for i := range a {
    54			a[i] = value
    55		}
    56	}
    57	
    58	func copyInt8s(dst []int8, src []int8) int {
    59		cnt := min(len(dst), len(src))
    60		for i := 0; i < cnt; i++ {
    61			dst[i] = src[i]
    62		}
    63		return cnt
    64	}
    65	
    66	func copyUint8s(dst []uint8, src []uint8) int {
    67		cnt := min(len(dst), len(src))
    68		for i := 0; i < cnt; i++ {
    69			dst[i] = src[i]
    70		}
    71		return cnt
    72	}

release.r60.3. Except as noted, this content is licensed under a Creative Commons Attribution 3.0 License.