mirror of
https://github.com/golang/go.git
synced 2025-05-10 18:13:12 +00:00
remove bytes.Copy
replace all calls with calls to copy use copy in regexp and bytes.Buffer R=rsc CC=golang-dev https://golang.org/cl/157073
This commit is contained in:
parent
093493c6a5
commit
e70cedfaec
@ -5,7 +5,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes";
|
|
||||||
"exec";
|
"exec";
|
||||||
"fmt";
|
"fmt";
|
||||||
"go/token";
|
"go/token";
|
||||||
@ -20,7 +19,7 @@ func (r ByteReaderAt) ReadAt(p []byte, off int64) (n int, err os.Error) {
|
|||||||
if off >= int64(len(r)) || off < 0 {
|
if off >= int64(len(r)) || off < 0 {
|
||||||
return 0, os.EOF
|
return 0, os.EOF
|
||||||
}
|
}
|
||||||
return bytes.Copy(p, r[off:len(r)]), nil;
|
return copy(p, r[off:len(r)]), nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
// run runs the command argv, feeding in stdin on standard input.
|
// run runs the command argv, feeding in stdin on standard input.
|
||||||
|
@ -8,7 +8,6 @@ package tar
|
|||||||
// - catch more errors (no first header, write after close, etc.)
|
// - catch more errors (no first header, write after close, etc.)
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes";
|
|
||||||
"io";
|
"io";
|
||||||
"os";
|
"os";
|
||||||
"strconv";
|
"strconv";
|
||||||
@ -124,25 +123,25 @@ func (tw *Writer) WriteHeader(hdr *Header) os.Error {
|
|||||||
s := slicer(header);
|
s := slicer(header);
|
||||||
|
|
||||||
// TODO(dsymonds): handle names longer than 100 chars
|
// TODO(dsymonds): handle names longer than 100 chars
|
||||||
bytes.Copy(s.next(100), strings.Bytes(hdr.Name));
|
copy(s.next(100), strings.Bytes(hdr.Name));
|
||||||
|
|
||||||
tw.octal(s.next(8), hdr.Mode); // 100:108
|
tw.octal(s.next(8), hdr.Mode); // 100:108
|
||||||
tw.numeric(s.next(8), hdr.Uid); // 108:116
|
tw.numeric(s.next(8), hdr.Uid); // 108:116
|
||||||
tw.numeric(s.next(8), hdr.Gid); // 116:124
|
tw.numeric(s.next(8), hdr.Gid); // 116:124
|
||||||
tw.numeric(s.next(12), hdr.Size); // 124:136
|
tw.numeric(s.next(12), hdr.Size); // 124:136
|
||||||
tw.numeric(s.next(12), hdr.Mtime); // 136:148
|
tw.numeric(s.next(12), hdr.Mtime); // 136:148
|
||||||
s.next(8); // chksum (148:156)
|
s.next(8); // chksum (148:156)
|
||||||
s.next(1)[0] = hdr.Typeflag; // 156:157
|
s.next(1)[0] = hdr.Typeflag; // 156:157
|
||||||
s.next(100); // linkname (157:257)
|
s.next(100); // linkname (157:257)
|
||||||
bytes.Copy(s.next(8), strings.Bytes("ustar\x0000")); // 257:265
|
copy(s.next(8), strings.Bytes("ustar\x0000")); // 257:265
|
||||||
tw.cString(s.next(32), hdr.Uname); // 265:297
|
tw.cString(s.next(32), hdr.Uname); // 265:297
|
||||||
tw.cString(s.next(32), hdr.Gname); // 297:329
|
tw.cString(s.next(32), hdr.Gname); // 297:329
|
||||||
tw.numeric(s.next(8), hdr.Devmajor); // 329:337
|
tw.numeric(s.next(8), hdr.Devmajor); // 329:337
|
||||||
tw.numeric(s.next(8), hdr.Devminor); // 337:345
|
tw.numeric(s.next(8), hdr.Devminor); // 337:345
|
||||||
|
|
||||||
// Use the GNU magic instead of POSIX magic if we used any GNU extensions.
|
// Use the GNU magic instead of POSIX magic if we used any GNU extensions.
|
||||||
if tw.usedBinary {
|
if tw.usedBinary {
|
||||||
bytes.Copy(header[257:265], strings.Bytes("ustar \x00"))
|
copy(header[257:265], strings.Bytes("ustar \x00"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// The chksum field is terminated by a NUL and a space.
|
// The chksum field is terminated by a NUL and a space.
|
||||||
|
@ -20,10 +20,11 @@ func copyString(dst []byte, doff int, str string) {
|
|||||||
|
|
||||||
// Copy from bytes to byte array at offset doff. Assume there's room.
|
// Copy from bytes to byte array at offset doff. Assume there's room.
|
||||||
func copyBytes(dst []byte, doff int, src []byte) {
|
func copyBytes(dst []byte, doff int, src []byte) {
|
||||||
for soff := 0; soff < len(src); soff++ {
|
if len(src) == 1 {
|
||||||
dst[doff] = src[soff];
|
dst[doff] = src[0];
|
||||||
doff++;
|
return;
|
||||||
}
|
}
|
||||||
|
copy(dst[doff:len(dst)], src);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Buffer is a variable-sized buffer of bytes
|
// A Buffer is a variable-sized buffer of bytes
|
||||||
|
@ -44,20 +44,6 @@ func Equal(a, b []byte) bool {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy copies bytes from src to dst,
|
|
||||||
// stopping when either all of src has been copied
|
|
||||||
// or all of dst has been filled.
|
|
||||||
// It returns the number of bytes copied.
|
|
||||||
func Copy(dst, src []byte) int {
|
|
||||||
if len(src) > len(dst) {
|
|
||||||
src = src[0:len(dst)]
|
|
||||||
}
|
|
||||||
for i, x := range src {
|
|
||||||
dst[i] = x
|
|
||||||
}
|
|
||||||
return len(src);
|
|
||||||
}
|
|
||||||
|
|
||||||
// explode splits s into an array of UTF-8 sequences, one per Unicode character (still arrays of bytes),
|
// explode splits s into an array of UTF-8 sequences, one per Unicode character (still arrays of bytes),
|
||||||
// up to a maximum of n byte arrays. Invalid UTF-8 sequences are chopped into individual bytes.
|
// up to a maximum of n byte arrays. Invalid UTF-8 sequences are chopped into individual bytes.
|
||||||
func explode(s []byte, n int) [][]byte {
|
func explode(s []byte, n int) [][]byte {
|
||||||
@ -315,10 +301,10 @@ func Add(s, t []byte) []byte {
|
|||||||
s = s[0 : lens+lent]
|
s = s[0 : lens+lent]
|
||||||
} else {
|
} else {
|
||||||
news := make([]byte, lens+lent, resize(lens+lent));
|
news := make([]byte, lens+lent, resize(lens+lent));
|
||||||
Copy(news, s);
|
copy(news, s);
|
||||||
s = news;
|
s = news;
|
||||||
}
|
}
|
||||||
Copy(s[lens:lens+lent], t);
|
copy(s[lens:lens+lent], t);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,7 +317,7 @@ func AddByte(s []byte, t byte) []byte {
|
|||||||
s = s[0 : lens+1]
|
s = s[0 : lens+1]
|
||||||
} else {
|
} else {
|
||||||
news := make([]byte, lens+1, resize(lens+1));
|
news := make([]byte, lens+1, resize(lens+1));
|
||||||
Copy(news, s);
|
copy(news, s);
|
||||||
s = news;
|
s = news;
|
||||||
}
|
}
|
||||||
s[lens] = t;
|
s[lens] = t;
|
||||||
|
@ -172,36 +172,6 @@ func TestSplitAfter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type CopyTest struct {
|
|
||||||
a string;
|
|
||||||
b string;
|
|
||||||
n int;
|
|
||||||
res string;
|
|
||||||
}
|
|
||||||
|
|
||||||
var copytests = []CopyTest{
|
|
||||||
CopyTest{"", "", 0, ""},
|
|
||||||
CopyTest{"a", "", 0, "a"},
|
|
||||||
CopyTest{"a", "a", 1, "a"},
|
|
||||||
CopyTest{"a", "b", 1, "b"},
|
|
||||||
CopyTest{"xyz", "abc", 3, "abc"},
|
|
||||||
CopyTest{"wxyz", "abc", 3, "abcz"},
|
|
||||||
CopyTest{"xyz", "abcd", 3, "abc"},
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCopy(t *testing.T) {
|
|
||||||
for i := 0; i < len(copytests); i++ {
|
|
||||||
tt := copytests[i];
|
|
||||||
dst := strings.Bytes(tt.a);
|
|
||||||
n := Copy(dst, strings.Bytes(tt.b));
|
|
||||||
result := string(dst);
|
|
||||||
if result != tt.res || n != tt.n {
|
|
||||||
t.Errorf(`Copy(%q, %q) = %d, %q; want %d, %q`, tt.a, tt.b, n, result, tt.n, tt.res);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test case for any function which accepts and returns a byte array.
|
// Test case for any function which accepts and returns a byte array.
|
||||||
// For ease of creation, we write the byte arrays as strings.
|
// For ease of creation, we write the byte arrays as strings.
|
||||||
type StringTest struct {
|
type StringTest struct {
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
package flate
|
package flate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes";
|
|
||||||
"io";
|
"io";
|
||||||
"math";
|
"math";
|
||||||
"os";
|
"os";
|
||||||
@ -128,7 +127,7 @@ func (d *deflater) fillWindow(index int) (int, os.Error) {
|
|||||||
wSize := d.windowMask + 1;
|
wSize := d.windowMask + 1;
|
||||||
if index >= wSize+wSize-(minMatchLength+maxMatchLength) {
|
if index >= wSize+wSize-(minMatchLength+maxMatchLength) {
|
||||||
// shift the window by wSize
|
// shift the window by wSize
|
||||||
bytes.Copy(d.window, d.window[wSize:2*wSize]);
|
copy(d.window, d.window[wSize:2*wSize]);
|
||||||
index -= wSize;
|
index -= wSize;
|
||||||
d.windowEnd -= wSize;
|
d.windowEnd -= wSize;
|
||||||
if d.blockStart >= wSize {
|
if d.blockStart >= wSize {
|
||||||
@ -355,7 +354,7 @@ func (d *deflater) doDeflate() (err os.Error) {
|
|||||||
// For matches this long, we don't bother inserting each individual
|
// For matches this long, we don't bother inserting each individual
|
||||||
// item into the table.
|
// item into the table.
|
||||||
index += length;
|
index += length;
|
||||||
hash = (int(d.window[index]) << hashShift + int(d.window[index+1]));
|
hash = (int(d.window[index])<<hashShift + int(d.window[index+1]));
|
||||||
}
|
}
|
||||||
if ti == maxFlateBlockTokens {
|
if ti == maxFlateBlockTokens {
|
||||||
// The block includes the current character
|
// The block includes the current character
|
||||||
|
@ -6,7 +6,6 @@ package rsa
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"big";
|
"big";
|
||||||
"bytes";
|
|
||||||
"crypto/subtle";
|
"crypto/subtle";
|
||||||
"io";
|
"io";
|
||||||
"os";
|
"os";
|
||||||
@ -34,7 +33,7 @@ func EncryptPKCS1v15(rand io.Reader, pub *PublicKey, msg []byte) (out []byte, er
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
em[len(em)-len(msg)-1] = 0;
|
em[len(em)-len(msg)-1] = 0;
|
||||||
bytes.Copy(mm, msg);
|
copy(mm, msg);
|
||||||
|
|
||||||
m := new(big.Int).SetBytes(em);
|
m := new(big.Int).SetBytes(em);
|
||||||
c := encrypt(new(big.Int), pub, m);
|
c := encrypt(new(big.Int), pub, m);
|
||||||
@ -191,8 +190,8 @@ func SignPKCS1v15(rand io.Reader, priv *PrivateKey, hash PKCS1v15Hash, hashed []
|
|||||||
for i := 2; i < k-tLen-1; i++ {
|
for i := 2; i < k-tLen-1; i++ {
|
||||||
em[i] = 0xff
|
em[i] = 0xff
|
||||||
}
|
}
|
||||||
bytes.Copy(em[k-tLen:k-hashLen], prefix);
|
copy(em[k-tLen:k-hashLen], prefix);
|
||||||
bytes.Copy(em[k-hashLen:k], hashed);
|
copy(em[k-hashLen:k], hashed);
|
||||||
|
|
||||||
m := new(big.Int).SetBytes(em);
|
m := new(big.Int).SetBytes(em);
|
||||||
c, err := decrypt(rand, priv, m);
|
c, err := decrypt(rand, priv, m);
|
||||||
|
@ -9,7 +9,6 @@ package rsa
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"big";
|
"big";
|
||||||
"bytes";
|
|
||||||
"crypto/subtle";
|
"crypto/subtle";
|
||||||
"hash";
|
"hash";
|
||||||
"io";
|
"io";
|
||||||
@ -263,9 +262,9 @@ func EncryptOAEP(hash hash.Hash, rand io.Reader, pub *PublicKey, msg []byte, lab
|
|||||||
seed := em[1 : 1+hash.Size()];
|
seed := em[1 : 1+hash.Size()];
|
||||||
db := em[1+hash.Size() : len(em)];
|
db := em[1+hash.Size() : len(em)];
|
||||||
|
|
||||||
bytes.Copy(db[0:hash.Size()], lHash);
|
copy(db[0:hash.Size()], lHash);
|
||||||
db[len(db)-len(msg)-1] = 1;
|
db[len(db)-len(msg)-1] = 1;
|
||||||
bytes.Copy(db[len(db)-len(msg):len(db)], msg);
|
copy(db[len(db)-len(msg):len(db)], msg);
|
||||||
|
|
||||||
_, err = io.ReadFull(rand, seed);
|
_, err = io.ReadFull(rand, seed);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -445,6 +444,6 @@ func leftPad(input []byte, size int) (out []byte) {
|
|||||||
n = size
|
n = size
|
||||||
}
|
}
|
||||||
out = make([]byte, size);
|
out = make([]byte, size);
|
||||||
bytes.Copy(out[len(out)-n:len(out)], input);
|
copy(out[len(out)-n:len(out)], input);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
package subtle
|
package subtle
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes";
|
|
||||||
"testing";
|
"testing";
|
||||||
"testing/quick";
|
"testing/quick";
|
||||||
)
|
)
|
||||||
@ -75,14 +74,14 @@ func TestConstantTimeEq(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func copy(v int, x, y []byte) []byte {
|
func makeCopy(v int, x, y []byte) []byte {
|
||||||
if len(x) > len(y) {
|
if len(x) > len(y) {
|
||||||
x = x[0:len(y)]
|
x = x[0:len(y)]
|
||||||
} else {
|
} else {
|
||||||
y = y[0:len(x)]
|
y = y[0:len(x)]
|
||||||
}
|
}
|
||||||
if v == 1 {
|
if v == 1 {
|
||||||
bytes.Copy(x, y)
|
copy(x, y)
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
@ -99,7 +98,7 @@ func constantTimeCopyWrapper(v int, x, y []byte) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestConstantTimeCopy(t *testing.T) {
|
func TestConstantTimeCopy(t *testing.T) {
|
||||||
err := quick.CheckEqual(constantTimeCopyWrapper, copy, nil);
|
err := quick.CheckEqual(constantTimeCopyWrapper, makeCopy, nil);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,6 @@
|
|||||||
|
|
||||||
package tls
|
package tls
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes";
|
|
||||||
)
|
|
||||||
|
|
||||||
type clientHelloMsg struct {
|
type clientHelloMsg struct {
|
||||||
raw []byte;
|
raw []byte;
|
||||||
major, minor uint8;
|
major, minor uint8;
|
||||||
@ -30,9 +26,9 @@ func (m *clientHelloMsg) marshal() []byte {
|
|||||||
x[3] = uint8(length);
|
x[3] = uint8(length);
|
||||||
x[4] = m.major;
|
x[4] = m.major;
|
||||||
x[5] = m.minor;
|
x[5] = m.minor;
|
||||||
bytes.Copy(x[6:38], m.random);
|
copy(x[6:38], m.random);
|
||||||
x[38] = uint8(len(m.sessionId));
|
x[38] = uint8(len(m.sessionId));
|
||||||
bytes.Copy(x[39:39+len(m.sessionId)], m.sessionId);
|
copy(x[39:39+len(m.sessionId)], m.sessionId);
|
||||||
y := x[39+len(m.sessionId) : len(x)];
|
y := x[39+len(m.sessionId) : len(x)];
|
||||||
y[0] = uint8(len(m.cipherSuites) >> 7);
|
y[0] = uint8(len(m.cipherSuites) >> 7);
|
||||||
y[1] = uint8(len(m.cipherSuites) << 1);
|
y[1] = uint8(len(m.cipherSuites) << 1);
|
||||||
@ -42,7 +38,7 @@ func (m *clientHelloMsg) marshal() []byte {
|
|||||||
}
|
}
|
||||||
z := y[2+len(m.cipherSuites)*2 : len(y)];
|
z := y[2+len(m.cipherSuites)*2 : len(y)];
|
||||||
z[0] = uint8(len(m.compressionMethods));
|
z[0] = uint8(len(m.compressionMethods));
|
||||||
bytes.Copy(z[1:len(z)], m.compressionMethods);
|
copy(z[1:len(z)], m.compressionMethods);
|
||||||
m.raw = x;
|
m.raw = x;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
@ -112,9 +108,9 @@ func (m *serverHelloMsg) marshal() []byte {
|
|||||||
x[3] = uint8(length);
|
x[3] = uint8(length);
|
||||||
x[4] = m.major;
|
x[4] = m.major;
|
||||||
x[5] = m.minor;
|
x[5] = m.minor;
|
||||||
bytes.Copy(x[6:38], m.random);
|
copy(x[6:38], m.random);
|
||||||
x[38] = uint8(len(m.sessionId));
|
x[38] = uint8(len(m.sessionId));
|
||||||
bytes.Copy(x[39:39+len(m.sessionId)], m.sessionId);
|
copy(x[39:39+len(m.sessionId)], m.sessionId);
|
||||||
z := x[39+len(m.sessionId) : len(x)];
|
z := x[39+len(m.sessionId) : len(x)];
|
||||||
z[0] = uint8(m.cipherSuite >> 8);
|
z[0] = uint8(m.cipherSuite >> 8);
|
||||||
z[1] = uint8(m.cipherSuite);
|
z[1] = uint8(m.cipherSuite);
|
||||||
@ -156,7 +152,7 @@ func (m *certificateMsg) marshal() (x []byte) {
|
|||||||
y[0] = uint8(len(slice) >> 16);
|
y[0] = uint8(len(slice) >> 16);
|
||||||
y[1] = uint8(len(slice) >> 8);
|
y[1] = uint8(len(slice) >> 8);
|
||||||
y[2] = uint8(len(slice));
|
y[2] = uint8(len(slice));
|
||||||
bytes.Copy(y[3:len(y)], slice);
|
copy(y[3:len(y)], slice);
|
||||||
y = y[3+len(slice) : len(y)];
|
y = y[3+len(slice) : len(y)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +185,7 @@ func (m *clientKeyExchangeMsg) marshal() []byte {
|
|||||||
x[3] = uint8(length);
|
x[3] = uint8(length);
|
||||||
x[4] = uint8(len(m.ciphertext) >> 8);
|
x[4] = uint8(len(m.ciphertext) >> 8);
|
||||||
x[5] = uint8(len(m.ciphertext));
|
x[5] = uint8(len(m.ciphertext));
|
||||||
bytes.Copy(x[6:len(x)], m.ciphertext);
|
copy(x[6:len(x)], m.ciphertext);
|
||||||
|
|
||||||
m.raw = x;
|
m.raw = x;
|
||||||
return x;
|
return x;
|
||||||
@ -221,7 +217,7 @@ func (m *finishedMsg) marshal() (x []byte) {
|
|||||||
x = make([]byte, 16);
|
x = make([]byte, 16);
|
||||||
x[0] = typeFinished;
|
x[0] = typeFinished;
|
||||||
x[3] = 12;
|
x[3] = 12;
|
||||||
bytes.Copy(x[4:len(x)], m.verifyData);
|
copy(x[4:len(x)], m.verifyData);
|
||||||
m.raw = x;
|
m.raw = x;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
package tls
|
package tls
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes";
|
|
||||||
"crypto/hmac";
|
"crypto/hmac";
|
||||||
"crypto/md5";
|
"crypto/md5";
|
||||||
"crypto/sha1";
|
"crypto/sha1";
|
||||||
@ -37,7 +36,7 @@ func pHash(result, secret, seed []byte, hash hash.Hash) {
|
|||||||
if j+todo > len(result) {
|
if j+todo > len(result) {
|
||||||
todo = len(result) - j
|
todo = len(result) - j
|
||||||
}
|
}
|
||||||
bytes.Copy(result[j:j+todo], b);
|
copy(result[j:j+todo], b);
|
||||||
j += todo;
|
j += todo;
|
||||||
|
|
||||||
h.Reset();
|
h.Reset();
|
||||||
@ -52,8 +51,8 @@ func pRF11(result, secret, label, seed []byte) {
|
|||||||
hashMD5 := md5.New();
|
hashMD5 := md5.New();
|
||||||
|
|
||||||
labelAndSeed := make([]byte, len(label)+len(seed));
|
labelAndSeed := make([]byte, len(label)+len(seed));
|
||||||
bytes.Copy(labelAndSeed, label);
|
copy(labelAndSeed, label);
|
||||||
bytes.Copy(labelAndSeed[len(label):len(labelAndSeed)], seed);
|
copy(labelAndSeed[len(label):len(labelAndSeed)], seed);
|
||||||
|
|
||||||
s1, s2 := splitPreMasterSecret(secret);
|
s1, s2 := splitPreMasterSecret(secret);
|
||||||
pHash(result, s1, labelAndSeed, hashMD5);
|
pHash(result, s1, labelAndSeed, hashMD5);
|
||||||
@ -81,13 +80,13 @@ var serverFinishedLabel = strings.Bytes("server finished")
|
|||||||
// 4346, section 6.3.
|
// 4346, section 6.3.
|
||||||
func keysFromPreMasterSecret11(preMasterSecret, clientRandom, serverRandom []byte, macLen, keyLen int) (masterSecret, clientMAC, serverMAC, clientKey, serverKey []byte) {
|
func keysFromPreMasterSecret11(preMasterSecret, clientRandom, serverRandom []byte, macLen, keyLen int) (masterSecret, clientMAC, serverMAC, clientKey, serverKey []byte) {
|
||||||
var seed [tlsRandomLength * 2]byte;
|
var seed [tlsRandomLength * 2]byte;
|
||||||
bytes.Copy(seed[0:len(clientRandom)], clientRandom);
|
copy(seed[0:len(clientRandom)], clientRandom);
|
||||||
bytes.Copy(seed[len(clientRandom):len(seed)], serverRandom);
|
copy(seed[len(clientRandom):len(seed)], serverRandom);
|
||||||
masterSecret = make([]byte, masterSecretLength);
|
masterSecret = make([]byte, masterSecretLength);
|
||||||
pRF11(masterSecret, preMasterSecret, masterSecretLabel, seed[0:len(seed)]);
|
pRF11(masterSecret, preMasterSecret, masterSecretLabel, seed[0:len(seed)]);
|
||||||
|
|
||||||
bytes.Copy(seed[0:len(clientRandom)], serverRandom);
|
copy(seed[0:len(clientRandom)], serverRandom);
|
||||||
bytes.Copy(seed[len(serverRandom):len(seed)], clientRandom);
|
copy(seed[len(serverRandom):len(seed)], clientRandom);
|
||||||
|
|
||||||
n := 2*macLen + 2*keyLen;
|
n := 2*macLen + 2*keyLen;
|
||||||
keyMaterial := make([]byte, n);
|
keyMaterial := make([]byte, n);
|
||||||
@ -124,8 +123,8 @@ func (h finishedHash) Write(msg []byte) (n int, err os.Error) {
|
|||||||
// message given the MD5 and SHA1 hashes of a set of handshake messages.
|
// message given the MD5 and SHA1 hashes of a set of handshake messages.
|
||||||
func finishedSum(md5, sha1, label, masterSecret []byte) []byte {
|
func finishedSum(md5, sha1, label, masterSecret []byte) []byte {
|
||||||
seed := make([]byte, len(md5)+len(sha1));
|
seed := make([]byte, len(md5)+len(sha1));
|
||||||
bytes.Copy(seed, md5);
|
copy(seed, md5);
|
||||||
bytes.Copy(seed[len(md5):len(seed)], sha1);
|
copy(seed[len(md5):len(seed)], sha1);
|
||||||
out := make([]byte, finishedVerifyLength);
|
out := make([]byte, finishedVerifyLength);
|
||||||
pRF11(out, masterSecret, label, seed);
|
pRF11(out, masterSecret, label, seed);
|
||||||
return out;
|
return out;
|
||||||
|
@ -10,7 +10,6 @@ package tls
|
|||||||
// state, or for a notification when the state changes.
|
// state, or for a notification when the state changes.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes";
|
|
||||||
"container/list";
|
"container/list";
|
||||||
"crypto/subtle";
|
"crypto/subtle";
|
||||||
"hash";
|
"hash";
|
||||||
@ -228,8 +227,8 @@ func (p *recordProcessor) processHandshakeRecord(data []byte) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
newBuf := make([]byte, len(p.handshakeBuf)+len(data));
|
newBuf := make([]byte, len(p.handshakeBuf)+len(data));
|
||||||
bytes.Copy(newBuf, p.handshakeBuf);
|
copy(newBuf, p.handshakeBuf);
|
||||||
bytes.Copy(newBuf[len(p.handshakeBuf):len(newBuf)], data);
|
copy(newBuf[len(p.handshakeBuf):len(newBuf)], data);
|
||||||
p.handshakeBuf = newBuf;
|
p.handshakeBuf = newBuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
package tls
|
package tls
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes";
|
|
||||||
"io";
|
"io";
|
||||||
"os";
|
"os";
|
||||||
"net";
|
"net";
|
||||||
@ -59,7 +58,7 @@ func (tls *Conn) Read(p []byte) (int, os.Error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
n := bytes.Copy(p, tls.readBuf);
|
n := copy(p, tls.readBuf);
|
||||||
tls.readBuf = tls.readBuf[n:len(tls.readBuf)];
|
tls.readBuf = tls.readBuf[n:len(tls.readBuf)];
|
||||||
return n, nil;
|
return n, nil;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
package ascii85
|
package ascii85
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes";
|
|
||||||
"io";
|
"io";
|
||||||
"os";
|
"os";
|
||||||
"strconv";
|
"strconv";
|
||||||
@ -268,7 +267,7 @@ func (d *decoder) Read(p []byte) (n int, err os.Error) {
|
|||||||
for {
|
for {
|
||||||
// Copy leftover output from last decode.
|
// Copy leftover output from last decode.
|
||||||
if len(d.out) > 0 {
|
if len(d.out) > 0 {
|
||||||
n = bytes.Copy(p, d.out);
|
n = copy(p, d.out);
|
||||||
d.out = d.out[n:len(d.out)];
|
d.out = d.out[n:len(d.out)];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -279,7 +278,7 @@ func (d *decoder) Read(p []byte) (n int, err os.Error) {
|
|||||||
ndst, nsrc, d.err = Decode(&d.outbuf, d.buf[0:d.nbuf], d.readErr != nil);
|
ndst, nsrc, d.err = Decode(&d.outbuf, d.buf[0:d.nbuf], d.readErr != nil);
|
||||||
if ndst > 0 {
|
if ndst > 0 {
|
||||||
d.out = d.outbuf[0:ndst];
|
d.out = d.outbuf[0:ndst];
|
||||||
d.nbuf = bytes.Copy(&d.buf, d.buf[nsrc:d.nbuf]);
|
d.nbuf = copy(&d.buf, d.buf[nsrc:d.nbuf]);
|
||||||
continue; // copy out and return
|
continue; // copy out and return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
package base64
|
package base64
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes";
|
|
||||||
"io";
|
"io";
|
||||||
"os";
|
"os";
|
||||||
"strconv";
|
"strconv";
|
||||||
@ -279,7 +278,7 @@ func (d *decoder) Read(p []byte) (n int, err os.Error) {
|
|||||||
|
|
||||||
// Use leftover decoded output from last read.
|
// Use leftover decoded output from last read.
|
||||||
if len(d.out) > 0 {
|
if len(d.out) > 0 {
|
||||||
n = bytes.Copy(p, d.out);
|
n = copy(p, d.out);
|
||||||
d.out = d.out[n:len(d.out)];
|
d.out = d.out[n:len(d.out)];
|
||||||
return n, nil;
|
return n, nil;
|
||||||
}
|
}
|
||||||
@ -304,7 +303,7 @@ func (d *decoder) Read(p []byte) (n int, err os.Error) {
|
|||||||
if nw > len(p) {
|
if nw > len(p) {
|
||||||
nw, d.end, d.err = d.enc.decode(&d.outbuf, d.buf[0:nr]);
|
nw, d.end, d.err = d.enc.decode(&d.outbuf, d.buf[0:nr]);
|
||||||
d.out = d.outbuf[0:nw];
|
d.out = d.outbuf[0:nw];
|
||||||
n = bytes.Copy(p, d.out);
|
n = copy(p, d.out);
|
||||||
d.out = d.out[n:len(d.out)];
|
d.out = d.out[n:len(d.out)];
|
||||||
} else {
|
} else {
|
||||||
n, d.end, d.err = d.enc.decode(p, d.buf[0:nr])
|
n, d.end, d.err = d.enc.decode(p, d.buf[0:nr])
|
||||||
|
@ -241,7 +241,7 @@ func (d *decoder) Read(p []byte) (n int, err os.Error) {
|
|||||||
for {
|
for {
|
||||||
// Copy leftover output from last decode.
|
// Copy leftover output from last decode.
|
||||||
if len(d.out) > 0 {
|
if len(d.out) > 0 {
|
||||||
n = bytes.Copy(p, d.out);
|
n = copy(p, d.out);
|
||||||
d.out = d.out[n:len(d.out)];
|
d.out = d.out[n:len(d.out)];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -270,7 +270,7 @@ func (d *decoder) Read(p []byte) (n int, err os.Error) {
|
|||||||
d.err = CorruptInputError(int64(e) + d.off)
|
d.err = CorruptInputError(int64(e) + d.off)
|
||||||
}
|
}
|
||||||
d.out = d.outbuf[0:nn];
|
d.out = d.outbuf[0:nn];
|
||||||
d.nbuf = bytes.Copy(&d.buf, d.buf[nl+1:d.nbuf]);
|
d.nbuf = copy(&d.buf, d.buf[nl+1:d.nbuf]);
|
||||||
d.off += int64(nl + 1);
|
d.off += int64(nl + 1);
|
||||||
}
|
}
|
||||||
panic("unreacahable");
|
panic("unreacahable");
|
||||||
|
@ -277,9 +277,8 @@ func newParser(re *Regexp) *parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func special(c int) bool {
|
func special(c int) bool {
|
||||||
s := `\.+*?()|[]^$`;
|
for _, r := range `\.+*?()|[]^$` {
|
||||||
for i := 0; i < len(s); i++ {
|
if c == r {
|
||||||
if c == int(s[i]) {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,9 +286,8 @@ func special(c int) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func specialcclass(c int) bool {
|
func specialcclass(c int) bool {
|
||||||
s := `\-[]`;
|
for _, r := range `\-[]` {
|
||||||
for i := 0; i < len(s); i++ {
|
if c == r {
|
||||||
if c == int(s[i]) {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -675,9 +673,7 @@ func (re *Regexp) addState(s []state, inst instr, match []int, pos, end int) []s
|
|||||||
}
|
}
|
||||||
if l == cap(s) {
|
if l == cap(s) {
|
||||||
s1 := make([]state, 2*l)[0:l];
|
s1 := make([]state, 2*l)[0:l];
|
||||||
for i := 0; i < l; i++ {
|
copy(s1, s);
|
||||||
s1[i] = s[i]
|
|
||||||
}
|
|
||||||
s = s1;
|
s = s1;
|
||||||
}
|
}
|
||||||
s = s[0 : l+1];
|
s = s[0 : l+1];
|
||||||
@ -685,15 +681,11 @@ func (re *Regexp) addState(s []state, inst instr, match []int, pos, end int) []s
|
|||||||
s[l].match = match;
|
s[l].match = match;
|
||||||
if inst.kind() == _ALT {
|
if inst.kind() == _ALT {
|
||||||
s1 := make([]int, 2*(re.nbra+1));
|
s1 := make([]int, 2*(re.nbra+1));
|
||||||
for i := 0; i < len(s1); i++ {
|
copy(s1, match);
|
||||||
s1[i] = match[i]
|
|
||||||
}
|
|
||||||
s = re.addState(s, inst.(*_Alt).left, s1, pos, end);
|
s = re.addState(s, inst.(*_Alt).left, s1, pos, end);
|
||||||
// give other branch a copy of this match vector
|
// give other branch a copy of this match vector
|
||||||
s1 = make([]int, 2*(re.nbra+1));
|
s1 = make([]int, 2*(re.nbra+1));
|
||||||
for i := 0; i < len(s1); i++ {
|
copy(s1, match);
|
||||||
s1[i] = match[i]
|
|
||||||
}
|
|
||||||
s = re.addState(s, inst.next(), s1, pos, end);
|
s = re.addState(s, inst.next(), s1, pos, end);
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
package strconv
|
package strconv
|
||||||
|
|
||||||
import "bytes"
|
|
||||||
|
|
||||||
type decimal struct {
|
type decimal struct {
|
||||||
// TODO(rsc): Can make d[] a bit smaller and add
|
// TODO(rsc): Can make d[] a bit smaller and add
|
||||||
// truncated bool;
|
// truncated bool;
|
||||||
@ -43,18 +41,18 @@ func (a *decimal) String() string {
|
|||||||
buf[w] = '.';
|
buf[w] = '.';
|
||||||
w++;
|
w++;
|
||||||
w += digitZero(buf[w : w+-a.dp]);
|
w += digitZero(buf[w : w+-a.dp]);
|
||||||
w += bytes.Copy(buf[w:w+a.nd], a.d[0:a.nd]);
|
w += copy(buf[w:w+a.nd], a.d[0:a.nd]);
|
||||||
|
|
||||||
case a.dp < a.nd:
|
case a.dp < a.nd:
|
||||||
// decimal point in middle of digits
|
// decimal point in middle of digits
|
||||||
w += bytes.Copy(buf[w:w+a.dp], a.d[0:a.dp]);
|
w += copy(buf[w:w+a.dp], a.d[0:a.dp]);
|
||||||
buf[w] = '.';
|
buf[w] = '.';
|
||||||
w++;
|
w++;
|
||||||
w += bytes.Copy(buf[w:w+a.nd-a.dp], a.d[a.dp:a.nd]);
|
w += copy(buf[w:w+a.nd-a.dp], a.d[a.dp:a.nd]);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// zeros fill space between digits and decimal point
|
// zeros fill space between digits and decimal point
|
||||||
w += bytes.Copy(buf[w:w+a.nd], a.d[0:a.nd]);
|
w += copy(buf[w:w+a.nd], a.d[0:a.nd]);
|
||||||
w += digitZero(buf[w : w+a.dp-a.nd]);
|
w += digitZero(buf[w : w+a.dp-a.nd]);
|
||||||
}
|
}
|
||||||
return string(buf[0:w]);
|
return string(buf[0:w]);
|
||||||
|
@ -9,7 +9,6 @@ package iotest
|
|||||||
import (
|
import (
|
||||||
"io";
|
"io";
|
||||||
"os";
|
"os";
|
||||||
"bytes";
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// OneByteReader returns a Reader that implements
|
// OneByteReader returns a Reader that implements
|
||||||
@ -63,7 +62,7 @@ func (r *dataErrReader) Read(p []byte) (n int, err os.Error) {
|
|||||||
if n > 0 {
|
if n > 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
n = bytes.Copy(p, r.unread);
|
n = copy(p, r.unread);
|
||||||
r.unread = r.unread[n:len(r.unread)];
|
r.unread = r.unread[n:len(r.unread)];
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -65,19 +65,19 @@ type EndElement struct {
|
|||||||
// the characters they represent.
|
// the characters they represent.
|
||||||
type CharData []byte
|
type CharData []byte
|
||||||
|
|
||||||
func copy(b []byte) []byte {
|
func makeCopy(b []byte) []byte {
|
||||||
b1 := make([]byte, len(b));
|
b1 := make([]byte, len(b));
|
||||||
bytes.Copy(b1, b);
|
copy(b1, b);
|
||||||
return b1;
|
return b1;
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c CharData) Copy() CharData { return CharData(copy(c)) }
|
func (c CharData) Copy() CharData { return CharData(makeCopy(c)) }
|
||||||
|
|
||||||
// A Comment represents an XML comment of the form <!--comment-->.
|
// A Comment represents an XML comment of the form <!--comment-->.
|
||||||
// The bytes do not include the <!-- and --> comment markers.
|
// The bytes do not include the <!-- and --> comment markers.
|
||||||
type Comment []byte
|
type Comment []byte
|
||||||
|
|
||||||
func (c Comment) Copy() Comment { return Comment(copy(c)) }
|
func (c Comment) Copy() Comment { return Comment(makeCopy(c)) }
|
||||||
|
|
||||||
// A ProcInst represents an XML processing instruction of the form <?target inst?>
|
// A ProcInst represents an XML processing instruction of the form <?target inst?>
|
||||||
type ProcInst struct {
|
type ProcInst struct {
|
||||||
@ -86,7 +86,7 @@ type ProcInst struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p ProcInst) Copy() ProcInst {
|
func (p ProcInst) Copy() ProcInst {
|
||||||
p.Inst = copy(p.Inst);
|
p.Inst = makeCopy(p.Inst);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ func (p ProcInst) Copy() ProcInst {
|
|||||||
// The bytes do not include the <! and > markers.
|
// The bytes do not include the <! and > markers.
|
||||||
type Directive []byte
|
type Directive []byte
|
||||||
|
|
||||||
func (d Directive) Copy() Directive { return Directive(copy(d)) }
|
func (d Directive) Copy() Directive { return Directive(makeCopy(d)) }
|
||||||
|
|
||||||
type readByter interface {
|
type readByter interface {
|
||||||
ReadByte() (b byte, err os.Error);
|
ReadByte() (b byte, err os.Error);
|
||||||
|
@ -39,7 +39,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio";
|
"bufio";
|
||||||
"bytes";
|
|
||||||
"flag";
|
"flag";
|
||||||
"os";
|
"os";
|
||||||
"strings";
|
"strings";
|
||||||
@ -55,7 +54,7 @@ func min(a, b int) int {
|
|||||||
if a < b {
|
if a < b {
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
return b
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
type AminoAcid struct {
|
type AminoAcid struct {
|
||||||
@ -63,23 +62,23 @@ type AminoAcid struct {
|
|||||||
c byte;
|
c byte;
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastrandom uint32 = 42
|
var lastrandom uint32 = 42
|
||||||
|
|
||||||
// Random number between 0.0 and 1.0
|
// Random number between 0.0 and 1.0
|
||||||
func myrandom() float {
|
func myrandom() float {
|
||||||
const (
|
const (
|
||||||
IM = 139968;
|
IM = 139968;
|
||||||
IA = 3877;
|
IA = 3877;
|
||||||
IC = 29573;
|
IC = 29573;
|
||||||
)
|
)
|
||||||
lastrandom = (lastrandom * IA + IC) % IM;
|
lastrandom = (lastrandom*IA + IC) % IM;
|
||||||
// Integer to float conversions are faster if the integer is signed.
|
// Integer to float conversions are faster if the integer is signed.
|
||||||
return float(int32(lastrandom)) / IM;
|
return float(int32(lastrandom)) / IM;
|
||||||
}
|
}
|
||||||
|
|
||||||
func AccumulateProbabilities(genelist []AminoAcid) {
|
func AccumulateProbabilities(genelist []AminoAcid) {
|
||||||
for i := 1; i < len(genelist); i++ {
|
for i := 1; i < len(genelist); i++ {
|
||||||
genelist[i].p += genelist[i-1].p;
|
genelist[i].p += genelist[i-1].p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,16 +89,16 @@ func AccumulateProbabilities(genelist []AminoAcid) {
|
|||||||
// It assumes that WIDTH <= len(s) + 1.
|
// It assumes that WIDTH <= len(s) + 1.
|
||||||
func RepeatFasta(s []byte, count int) {
|
func RepeatFasta(s []byte, count int) {
|
||||||
pos := 0;
|
pos := 0;
|
||||||
s2 := make([]byte, len(s) + WIDTH);
|
s2 := make([]byte, len(s)+WIDTH);
|
||||||
bytes.Copy(s2, s);
|
copy(s2, s);
|
||||||
bytes.Copy(s2[len(s):len(s2)], s);
|
copy(s2[len(s):len(s2)], s);
|
||||||
for count > 0 {
|
for count > 0 {
|
||||||
line := min(WIDTH, count);
|
line := min(WIDTH, count);
|
||||||
out.Write(s2[pos:pos+line]);
|
out.Write(s2[pos : pos+line]);
|
||||||
out.WriteByte('\n');
|
out.WriteByte('\n');
|
||||||
pos += line;
|
pos += line;
|
||||||
if pos >= len(s) {
|
if pos >= len(s) {
|
||||||
pos -= len(s);
|
pos -= len(s)
|
||||||
}
|
}
|
||||||
count -= line;
|
count -= line;
|
||||||
}
|
}
|
||||||
@ -114,7 +113,7 @@ func RepeatFasta(s []byte, count int) {
|
|||||||
// This sequence is repeated count times.
|
// This sequence is repeated count times.
|
||||||
// Between each WIDTH consecutive characters, the function prints a newline.
|
// Between each WIDTH consecutive characters, the function prints a newline.
|
||||||
func RandomFasta(genelist []AminoAcid, count int) {
|
func RandomFasta(genelist []AminoAcid, count int) {
|
||||||
buf := make([]byte, WIDTH + 1);
|
buf := make([]byte, WIDTH+1);
|
||||||
for count > 0 {
|
for count > 0 {
|
||||||
line := min(WIDTH, count);
|
line := min(WIDTH, count);
|
||||||
for pos := 0; pos < line; pos++ {
|
for pos := 0; pos < line; pos++ {
|
||||||
@ -125,7 +124,7 @@ func RandomFasta(genelist []AminoAcid, count int) {
|
|||||||
buf[pos] = genelist[i].c;
|
buf[pos] = genelist[i].c;
|
||||||
}
|
}
|
||||||
buf[line] = '\n';
|
buf[line] = '\n';
|
||||||
out.Write(buf[0:line + 1]);
|
out.Write(buf[0 : line+1]);
|
||||||
count -= line;
|
count -= line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,29 +135,29 @@ func main() {
|
|||||||
|
|
||||||
flag.Parse();
|
flag.Parse();
|
||||||
|
|
||||||
iub := []AminoAcid {
|
iub := []AminoAcid{
|
||||||
AminoAcid{ 0.27, 'a' },
|
AminoAcid{0.27, 'a'},
|
||||||
AminoAcid{ 0.12, 'c' },
|
AminoAcid{0.12, 'c'},
|
||||||
AminoAcid{ 0.12, 'g' },
|
AminoAcid{0.12, 'g'},
|
||||||
AminoAcid{ 0.27, 't' },
|
AminoAcid{0.27, 't'},
|
||||||
AminoAcid{ 0.02, 'B' },
|
AminoAcid{0.02, 'B'},
|
||||||
AminoAcid{ 0.02, 'D' },
|
AminoAcid{0.02, 'D'},
|
||||||
AminoAcid{ 0.02, 'H' },
|
AminoAcid{0.02, 'H'},
|
||||||
AminoAcid{ 0.02, 'K' },
|
AminoAcid{0.02, 'K'},
|
||||||
AminoAcid{ 0.02, 'M' },
|
AminoAcid{0.02, 'M'},
|
||||||
AminoAcid{ 0.02, 'N' },
|
AminoAcid{0.02, 'N'},
|
||||||
AminoAcid{ 0.02, 'R' },
|
AminoAcid{0.02, 'R'},
|
||||||
AminoAcid{ 0.02, 'S' },
|
AminoAcid{0.02, 'S'},
|
||||||
AminoAcid{ 0.02, 'V' },
|
AminoAcid{0.02, 'V'},
|
||||||
AminoAcid{ 0.02, 'W' },
|
AminoAcid{0.02, 'W'},
|
||||||
AminoAcid{ 0.02, 'Y' }
|
AminoAcid{0.02, 'Y'},
|
||||||
};
|
};
|
||||||
|
|
||||||
homosapiens := []AminoAcid {
|
homosapiens := []AminoAcid{
|
||||||
AminoAcid{ 0.3029549426680, 'a' },
|
AminoAcid{0.3029549426680, 'a'},
|
||||||
AminoAcid{ 0.1979883004921, 'c' },
|
AminoAcid{0.1979883004921, 'c'},
|
||||||
AminoAcid{ 0.1975473066391, 'g' },
|
AminoAcid{0.1975473066391, 'g'},
|
||||||
AminoAcid{ 0.3015094502008, 't' }
|
AminoAcid{0.3015094502008, 't'},
|
||||||
};
|
};
|
||||||
|
|
||||||
AccumulateProbabilities(iub);
|
AccumulateProbabilities(iub);
|
||||||
@ -166,17 +165,17 @@ func main() {
|
|||||||
|
|
||||||
alu := strings.Bytes(
|
alu := strings.Bytes(
|
||||||
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"
|
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"
|
||||||
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"
|
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"
|
||||||
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"
|
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"
|
||||||
"ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"
|
"ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA"
|
||||||
"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"
|
"GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG"
|
||||||
"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"
|
"AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC"
|
||||||
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA");
|
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA");
|
||||||
|
|
||||||
out.WriteString(">ONE Homo sapiens alu\n");
|
out.WriteString(">ONE Homo sapiens alu\n");
|
||||||
RepeatFasta(alu, 2 * *n);
|
RepeatFasta(alu, 2**n);
|
||||||
out.WriteString(">TWO IUB ambiguity codes\n");
|
out.WriteString(">TWO IUB ambiguity codes\n");
|
||||||
RandomFasta(iub, 3 * *n);
|
RandomFasta(iub, 3**n);
|
||||||
out.WriteString(">THREE Homo sapiens frequency\n");
|
out.WriteString(">THREE Homo sapiens frequency\n");
|
||||||
RandomFasta(homosapiens, 5 * *n);
|
RandomFasta(homosapiens, 5**n);
|
||||||
}
|
}
|
||||||
|
@ -37,39 +37,38 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio";
|
"bufio";
|
||||||
"bytes";
|
|
||||||
"os";
|
"os";
|
||||||
)
|
)
|
||||||
|
|
||||||
const lineSize = 60
|
const lineSize = 60
|
||||||
|
|
||||||
var complement = [256]uint8 {
|
var complement = [256]uint8{
|
||||||
'A': 'T', 'a': 'T',
|
'A': 'T', 'a': 'T',
|
||||||
'C': 'G', 'c': 'G',
|
'C': 'G', 'c': 'G',
|
||||||
'G': 'C', 'g': 'C',
|
'G': 'C', 'g': 'C',
|
||||||
'T': 'A', 't': 'A',
|
'T': 'A', 't': 'A',
|
||||||
'U': 'A', 'u': 'A',
|
'U': 'A', 'u': 'A',
|
||||||
'M': 'K', 'm': 'K',
|
'M': 'K', 'm': 'K',
|
||||||
'R': 'Y', 'r': 'Y',
|
'R': 'Y', 'r': 'Y',
|
||||||
'W': 'W', 'w': 'W',
|
'W': 'W', 'w': 'W',
|
||||||
'S': 'S', 's': 'S',
|
'S': 'S', 's': 'S',
|
||||||
'Y': 'R', 'y': 'R',
|
'Y': 'R', 'y': 'R',
|
||||||
'K': 'M', 'k': 'M',
|
'K': 'M', 'k': 'M',
|
||||||
'V': 'B', 'v': 'B',
|
'V': 'B', 'v': 'B',
|
||||||
'H': 'D', 'h': 'D',
|
'H': 'D', 'h': 'D',
|
||||||
'D': 'H', 'd': 'H',
|
'D': 'H', 'd': 'H',
|
||||||
'B': 'V', 'b': 'V',
|
'B': 'V', 'b': 'V',
|
||||||
'N': 'N', 'n': 'N',
|
'N': 'N', 'n': 'N',
|
||||||
}
|
}
|
||||||
|
|
||||||
var in *bufio.Reader
|
var in *bufio.Reader
|
||||||
|
|
||||||
func reverseComplement(in []byte) []byte {
|
func reverseComplement(in []byte) []byte {
|
||||||
outLen := len(in) + (len(in) + lineSize -1)/lineSize;
|
outLen := len(in) + (len(in)+lineSize-1)/lineSize;
|
||||||
out := make([]byte, outLen);
|
out := make([]byte, outLen);
|
||||||
j := 0;
|
j := 0;
|
||||||
k := 0;
|
k := 0;
|
||||||
for i := len(in)-1; i >= 0; i-- {
|
for i := len(in) - 1; i >= 0; i-- {
|
||||||
if k == lineSize {
|
if k == lineSize {
|
||||||
out[j] = '\n';
|
out[j] = '\n';
|
||||||
j++;
|
j++;
|
||||||
@ -106,15 +105,15 @@ func main() {
|
|||||||
top = 0;
|
top = 0;
|
||||||
}
|
}
|
||||||
os.Stdout.Write(line);
|
os.Stdout.Write(line);
|
||||||
continue
|
continue;
|
||||||
}
|
}
|
||||||
line = line[0:len(line)-1]; // drop newline
|
line = line[0 : len(line)-1]; // drop newline
|
||||||
if top+len(line) > len(buf) {
|
if top+len(line) > len(buf) {
|
||||||
nbuf := make([]byte, 2*len(buf) + 1024*(100+len(line)));
|
nbuf := make([]byte, 2*len(buf)+1024*(100+len(line)));
|
||||||
bytes.Copy(nbuf, buf[0:top]);
|
copy(nbuf, buf[0:top]);
|
||||||
buf = nbuf;
|
buf = nbuf;
|
||||||
}
|
}
|
||||||
bytes.Copy(buf[top:len(buf)], line);
|
copy(buf[top:len(buf)], line);
|
||||||
top += len(line);
|
top += len(line);
|
||||||
}
|
}
|
||||||
output(buf[0:top]);
|
output(buf[0:top]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user