id
int32 0
167k
| 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
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
150,500 | mattn/go-oci8 | cHelpers.go | freeBuffer | func freeBuffer(buffer unsafe.Pointer, dataType C.ub2) {
switch dataType {
case C.SQLT_CLOB, C.SQLT_BLOB:
C.OCIDescriptorFree(*(*unsafe.Pointer)(buffer), C.OCI_DTYPE_LOB)
case C.SQLT_TIMESTAMP:
C.OCIDescriptorFree(*(*unsafe.Pointer)(buffer), C.OCI_DTYPE_TIMESTAMP)
case C.SQLT_TIMESTAMP_TZ:
C.OCIDescriptorFree(*(*unsafe.Pointer)(buffer), C.OCI_DTYPE_TIMESTAMP_TZ)
case C.SQLT_TIMESTAMP_LTZ:
C.OCIDescriptorFree(*(*unsafe.Pointer)(buffer), C.OCI_DTYPE_TIMESTAMP_LTZ)
case C.SQLT_INTERVAL_DS:
C.OCIDescriptorFree(*(*unsafe.Pointer)(buffer), C.OCI_DTYPE_INTERVAL_DS)
case C.SQLT_INTERVAL_YM:
C.OCIDescriptorFree(*(*unsafe.Pointer)(buffer), C.OCI_DTYPE_INTERVAL_YM)
default:
C.free(buffer)
}
} | go | func freeBuffer(buffer unsafe.Pointer, dataType C.ub2) {
switch dataType {
case C.SQLT_CLOB, C.SQLT_BLOB:
C.OCIDescriptorFree(*(*unsafe.Pointer)(buffer), C.OCI_DTYPE_LOB)
case C.SQLT_TIMESTAMP:
C.OCIDescriptorFree(*(*unsafe.Pointer)(buffer), C.OCI_DTYPE_TIMESTAMP)
case C.SQLT_TIMESTAMP_TZ:
C.OCIDescriptorFree(*(*unsafe.Pointer)(buffer), C.OCI_DTYPE_TIMESTAMP_TZ)
case C.SQLT_TIMESTAMP_LTZ:
C.OCIDescriptorFree(*(*unsafe.Pointer)(buffer), C.OCI_DTYPE_TIMESTAMP_LTZ)
case C.SQLT_INTERVAL_DS:
C.OCIDescriptorFree(*(*unsafe.Pointer)(buffer), C.OCI_DTYPE_INTERVAL_DS)
case C.SQLT_INTERVAL_YM:
C.OCIDescriptorFree(*(*unsafe.Pointer)(buffer), C.OCI_DTYPE_INTERVAL_YM)
default:
C.free(buffer)
}
} | [
"func",
"freeBuffer",
"(",
"buffer",
"unsafe",
".",
"Pointer",
",",
"dataType",
"C",
".",
"ub2",
")",
"{",
"switch",
"dataType",
"{",
"case",
"C",
".",
"SQLT_CLOB",
",",
"C",
".",
"SQLT_BLOB",
":",
"C",
".",
"OCIDescriptorFree",
"(",
"*",
"(",
"*",
"unsafe",
".",
"Pointer",
")",
"(",
"buffer",
")",
",",
"C",
".",
"OCI_DTYPE_LOB",
")",
"\n",
"case",
"C",
".",
"SQLT_TIMESTAMP",
":",
"C",
".",
"OCIDescriptorFree",
"(",
"*",
"(",
"*",
"unsafe",
".",
"Pointer",
")",
"(",
"buffer",
")",
",",
"C",
".",
"OCI_DTYPE_TIMESTAMP",
")",
"\n",
"case",
"C",
".",
"SQLT_TIMESTAMP_TZ",
":",
"C",
".",
"OCIDescriptorFree",
"(",
"*",
"(",
"*",
"unsafe",
".",
"Pointer",
")",
"(",
"buffer",
")",
",",
"C",
".",
"OCI_DTYPE_TIMESTAMP_TZ",
")",
"\n",
"case",
"C",
".",
"SQLT_TIMESTAMP_LTZ",
":",
"C",
".",
"OCIDescriptorFree",
"(",
"*",
"(",
"*",
"unsafe",
".",
"Pointer",
")",
"(",
"buffer",
")",
",",
"C",
".",
"OCI_DTYPE_TIMESTAMP_LTZ",
")",
"\n",
"case",
"C",
".",
"SQLT_INTERVAL_DS",
":",
"C",
".",
"OCIDescriptorFree",
"(",
"*",
"(",
"*",
"unsafe",
".",
"Pointer",
")",
"(",
"buffer",
")",
",",
"C",
".",
"OCI_DTYPE_INTERVAL_DS",
")",
"\n",
"case",
"C",
".",
"SQLT_INTERVAL_YM",
":",
"C",
".",
"OCIDescriptorFree",
"(",
"*",
"(",
"*",
"unsafe",
".",
"Pointer",
")",
"(",
"buffer",
")",
",",
"C",
".",
"OCI_DTYPE_INTERVAL_YM",
")",
"\n",
"default",
":",
"C",
".",
"free",
"(",
"buffer",
")",
"\n",
"}",
"\n",
"}"
] | // freeBuffer calles OCIDescriptorFree to free double pointer to buffer
// or calles C free to free pointer to buffer | [
"freeBuffer",
"calles",
"OCIDescriptorFree",
"to",
"free",
"double",
"pointer",
"to",
"buffer",
"or",
"calles",
"C",
"free",
"to",
"free",
"pointer",
"to",
"buffer"
] | b4ff95311f59786a15c0688c8beff047414c098f | https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/cHelpers.go#L113-L130 |
150,501 | mattn/go-oci8 | rows.go | Close | func (rows *OCI8Rows) Close() error {
if rows.closed {
return nil
}
rows.closed = true
close(rows.done)
if rows.cls {
rows.stmt.Close()
}
freeDefines(rows.defines)
return nil
} | go | func (rows *OCI8Rows) Close() error {
if rows.closed {
return nil
}
rows.closed = true
close(rows.done)
if rows.cls {
rows.stmt.Close()
}
freeDefines(rows.defines)
return nil
} | [
"func",
"(",
"rows",
"*",
"OCI8Rows",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"rows",
".",
"closed",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"rows",
".",
"closed",
"=",
"true",
"\n",
"close",
"(",
"rows",
".",
"done",
")",
"\n\n",
"if",
"rows",
".",
"cls",
"{",
"rows",
".",
"stmt",
".",
"Close",
"(",
")",
"\n",
"}",
"\n\n",
"freeDefines",
"(",
"rows",
".",
"defines",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Close closes rows | [
"Close",
"closes",
"rows"
] | b4ff95311f59786a15c0688c8beff047414c098f | https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/rows.go#L18-L33 |
150,502 | mattn/go-oci8 | rows.go | Columns | func (rows *OCI8Rows) Columns() []string {
names := make([]string, len(rows.defines))
for i, define := range rows.defines {
names[i] = define.name
}
return names
} | go | func (rows *OCI8Rows) Columns() []string {
names := make([]string, len(rows.defines))
for i, define := range rows.defines {
names[i] = define.name
}
return names
} | [
"func",
"(",
"rows",
"*",
"OCI8Rows",
")",
"Columns",
"(",
")",
"[",
"]",
"string",
"{",
"names",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"rows",
".",
"defines",
")",
")",
"\n",
"for",
"i",
",",
"define",
":=",
"range",
"rows",
".",
"defines",
"{",
"names",
"[",
"i",
"]",
"=",
"define",
".",
"name",
"\n",
"}",
"\n",
"return",
"names",
"\n",
"}"
] | // Columns returns column names | [
"Columns",
"returns",
"column",
"names"
] | b4ff95311f59786a15c0688c8beff047414c098f | https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/rows.go#L36-L42 |
150,503 | mattn/go-oci8 | rows.go | ColumnTypeLength | func (rows *OCI8Rows) ColumnTypeLength(i int) (length int64, ok bool) {
param, err := rows.stmt.ociParamGet(C.ub4(i + 1))
if err != nil {
return 0, false
}
defer C.OCIDescriptorFree(unsafe.Pointer(param), C.OCI_DTYPE_PARAM)
var dataSize C.ub4 // Maximum size in bytes of the external data for the column. This can affect conversion buffer sizes.
_, err = rows.stmt.conn.ociAttrGet(param, unsafe.Pointer(&dataSize), C.OCI_ATTR_DATA_SIZE)
if err != nil {
return 0, false
}
return int64(dataSize), true
} | go | func (rows *OCI8Rows) ColumnTypeLength(i int) (length int64, ok bool) {
param, err := rows.stmt.ociParamGet(C.ub4(i + 1))
if err != nil {
return 0, false
}
defer C.OCIDescriptorFree(unsafe.Pointer(param), C.OCI_DTYPE_PARAM)
var dataSize C.ub4 // Maximum size in bytes of the external data for the column. This can affect conversion buffer sizes.
_, err = rows.stmt.conn.ociAttrGet(param, unsafe.Pointer(&dataSize), C.OCI_ATTR_DATA_SIZE)
if err != nil {
return 0, false
}
return int64(dataSize), true
} | [
"func",
"(",
"rows",
"*",
"OCI8Rows",
")",
"ColumnTypeLength",
"(",
"i",
"int",
")",
"(",
"length",
"int64",
",",
"ok",
"bool",
")",
"{",
"param",
",",
"err",
":=",
"rows",
".",
"stmt",
".",
"ociParamGet",
"(",
"C",
".",
"ub4",
"(",
"i",
"+",
"1",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"defer",
"C",
".",
"OCIDescriptorFree",
"(",
"unsafe",
".",
"Pointer",
"(",
"param",
")",
",",
"C",
".",
"OCI_DTYPE_PARAM",
")",
"\n\n",
"var",
"dataSize",
"C",
".",
"ub4",
"// Maximum size in bytes of the external data for the column. This can affect conversion buffer sizes.",
"\n",
"_",
",",
"err",
"=",
"rows",
".",
"stmt",
".",
"conn",
".",
"ociAttrGet",
"(",
"param",
",",
"unsafe",
".",
"Pointer",
"(",
"&",
"dataSize",
")",
",",
"C",
".",
"OCI_ATTR_DATA_SIZE",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n\n",
"return",
"int64",
"(",
"dataSize",
")",
",",
"true",
"\n",
"}"
] | // ColumnTypeLength returns column length | [
"ColumnTypeLength",
"returns",
"column",
"length"
] | b4ff95311f59786a15c0688c8beff047414c098f | https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/rows.go#L350-L364 |
150,504 | mattn/go-oci8 | dsn.go | ParseQuery | func ParseQuery(query string) (m Values, err error) {
m = make(Values)
err = parseQuery(m, query)
return
} | go | func ParseQuery(query string) (m Values, err error) {
m = make(Values)
err = parseQuery(m, query)
return
} | [
"func",
"ParseQuery",
"(",
"query",
"string",
")",
"(",
"m",
"Values",
",",
"err",
"error",
")",
"{",
"m",
"=",
"make",
"(",
"Values",
")",
"\n",
"err",
"=",
"parseQuery",
"(",
"m",
",",
"query",
")",
"\n",
"return",
"\n",
"}"
] | // ParseQuery parses the URL-encoded query string and returns
// a map listing the values specified for each key.
// ParseQuery always returns a non-nil map containing all the
// valid query parameters found; err describes the first decoding error
// encountered, if any. | [
"ParseQuery",
"parses",
"the",
"URL",
"-",
"encoded",
"query",
"string",
"and",
"returns",
"a",
"map",
"listing",
"the",
"values",
"specified",
"for",
"each",
"key",
".",
"ParseQuery",
"always",
"returns",
"a",
"non",
"-",
"nil",
"map",
"containing",
"all",
"the",
"valid",
"query",
"parameters",
"found",
";",
"err",
"describes",
"the",
"first",
"decoding",
"error",
"encountered",
"if",
"any",
"."
] | b4ff95311f59786a15c0688c8beff047414c098f | https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/dsn.go#L296-L300 |
150,505 | gin-contrib/sessions | redis/redis.go | SetKeyPrefix | func SetKeyPrefix(s Store, prefix string) error {
err, rediStore := GetRedisStore(s)
if err != nil {
return err
}
rediStore.SetKeyPrefix(prefix)
return nil
} | go | func SetKeyPrefix(s Store, prefix string) error {
err, rediStore := GetRedisStore(s)
if err != nil {
return err
}
rediStore.SetKeyPrefix(prefix)
return nil
} | [
"func",
"SetKeyPrefix",
"(",
"s",
"Store",
",",
"prefix",
"string",
")",
"error",
"{",
"err",
",",
"rediStore",
":=",
"GetRedisStore",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"rediStore",
".",
"SetKeyPrefix",
"(",
"prefix",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetKeyPrefix sets the key prefix in the redis database. | [
"SetKeyPrefix",
"sets",
"the",
"key",
"prefix",
"in",
"the",
"redis",
"database",
"."
] | 1532893d996f0fedbac1162ea1311ebfb57a3da5 | https://github.com/gin-contrib/sessions/blob/1532893d996f0fedbac1162ea1311ebfb57a3da5/redis/redis.go#L78-L86 |
150,506 | bamzi/jobrunner | runjob.go | Every | func Every(duration time.Duration, job cron.Job) {
MainCron.Schedule(cron.Every(duration), New(job))
} | go | func Every(duration time.Duration, job cron.Job) {
MainCron.Schedule(cron.Every(duration), New(job))
} | [
"func",
"Every",
"(",
"duration",
"time",
".",
"Duration",
",",
"job",
"cron",
".",
"Job",
")",
"{",
"MainCron",
".",
"Schedule",
"(",
"cron",
".",
"Every",
"(",
"duration",
")",
",",
"New",
"(",
"job",
")",
")",
"\n",
"}"
] | // Run the given job at a fixed interval.
// The interval provided is the time between the job ending and the job being run again.
// The time that the job takes to run is not included in the interval. | [
"Run",
"the",
"given",
"job",
"at",
"a",
"fixed",
"interval",
".",
"The",
"interval",
"provided",
"is",
"the",
"time",
"between",
"the",
"job",
"ending",
"and",
"the",
"job",
"being",
"run",
"again",
".",
"The",
"time",
"that",
"the",
"job",
"takes",
"to",
"run",
"is",
"not",
"included",
"in",
"the",
"interval",
"."
] | 273175f8b6ebabab8a639a4e6260a5c50fbf016a | https://github.com/bamzi/jobrunner/blob/273175f8b6ebabab8a639a4e6260a5c50fbf016a/runjob.go#L40-L43 |
150,507 | bamzi/jobrunner | runjob.go | In | func In(duration time.Duration, job cron.Job) {
go func() {
time.Sleep(duration)
New(job).Run()
}()
} | go | func In(duration time.Duration, job cron.Job) {
go func() {
time.Sleep(duration)
New(job).Run()
}()
} | [
"func",
"In",
"(",
"duration",
"time",
".",
"Duration",
",",
"job",
"cron",
".",
"Job",
")",
"{",
"go",
"func",
"(",
")",
"{",
"time",
".",
"Sleep",
"(",
"duration",
")",
"\n",
"New",
"(",
"job",
")",
".",
"Run",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"}"
] | // Run the given job once, after the given delay. | [
"Run",
"the",
"given",
"job",
"once",
"after",
"the",
"given",
"delay",
"."
] | 273175f8b6ebabab8a639a4e6260a5c50fbf016a | https://github.com/bamzi/jobrunner/blob/273175f8b6ebabab8a639a4e6260a5c50fbf016a/runjob.go#L51-L56 |
150,508 | klauspost/reedsolomon | streaming.go | NewStream | func NewStream(dataShards, parityShards int, o ...Option) (StreamEncoder, error) {
enc, err := New(dataShards, parityShards, o...)
if err != nil {
return nil, err
}
rs := enc.(*reedSolomon)
r := rsStream{r: rs, bs: 4 << 20}
r.readShards = readShards
r.writeShards = writeShards
return &r, err
} | go | func NewStream(dataShards, parityShards int, o ...Option) (StreamEncoder, error) {
enc, err := New(dataShards, parityShards, o...)
if err != nil {
return nil, err
}
rs := enc.(*reedSolomon)
r := rsStream{r: rs, bs: 4 << 20}
r.readShards = readShards
r.writeShards = writeShards
return &r, err
} | [
"func",
"NewStream",
"(",
"dataShards",
",",
"parityShards",
"int",
",",
"o",
"...",
"Option",
")",
"(",
"StreamEncoder",
",",
"error",
")",
"{",
"enc",
",",
"err",
":=",
"New",
"(",
"dataShards",
",",
"parityShards",
",",
"o",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"rs",
":=",
"enc",
".",
"(",
"*",
"reedSolomon",
")",
"\n",
"r",
":=",
"rsStream",
"{",
"r",
":",
"rs",
",",
"bs",
":",
"4",
"<<",
"20",
"}",
"\n",
"r",
".",
"readShards",
"=",
"readShards",
"\n",
"r",
".",
"writeShards",
"=",
"writeShards",
"\n",
"return",
"&",
"r",
",",
"err",
"\n",
"}"
] | // NewStream creates a new encoder and initializes it to
// the number of data shards and parity shards that
// you want to use. You can reuse this encoder.
// Note that the maximum number of data shards is 256. | [
"NewStream",
"creates",
"a",
"new",
"encoder",
"and",
"initializes",
"it",
"to",
"the",
"number",
"of",
"data",
"shards",
"and",
"parity",
"shards",
"that",
"you",
"want",
"to",
"use",
".",
"You",
"can",
"reuse",
"this",
"encoder",
".",
"Note",
"that",
"the",
"maximum",
"number",
"of",
"data",
"shards",
"is",
"256",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/streaming.go#L148-L158 |
150,509 | klauspost/reedsolomon | streaming.go | NewStreamC | func NewStreamC(dataShards, parityShards int, conReads, conWrites bool, o ...Option) (StreamEncoder, error) {
enc, err := New(dataShards, parityShards, o...)
if err != nil {
return nil, err
}
rs := enc.(*reedSolomon)
r := rsStream{r: rs, bs: 4 << 20}
r.readShards = readShards
r.writeShards = writeShards
if conReads {
r.readShards = cReadShards
}
if conWrites {
r.writeShards = cWriteShards
}
return &r, err
} | go | func NewStreamC(dataShards, parityShards int, conReads, conWrites bool, o ...Option) (StreamEncoder, error) {
enc, err := New(dataShards, parityShards, o...)
if err != nil {
return nil, err
}
rs := enc.(*reedSolomon)
r := rsStream{r: rs, bs: 4 << 20}
r.readShards = readShards
r.writeShards = writeShards
if conReads {
r.readShards = cReadShards
}
if conWrites {
r.writeShards = cWriteShards
}
return &r, err
} | [
"func",
"NewStreamC",
"(",
"dataShards",
",",
"parityShards",
"int",
",",
"conReads",
",",
"conWrites",
"bool",
",",
"o",
"...",
"Option",
")",
"(",
"StreamEncoder",
",",
"error",
")",
"{",
"enc",
",",
"err",
":=",
"New",
"(",
"dataShards",
",",
"parityShards",
",",
"o",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"rs",
":=",
"enc",
".",
"(",
"*",
"reedSolomon",
")",
"\n",
"r",
":=",
"rsStream",
"{",
"r",
":",
"rs",
",",
"bs",
":",
"4",
"<<",
"20",
"}",
"\n",
"r",
".",
"readShards",
"=",
"readShards",
"\n",
"r",
".",
"writeShards",
"=",
"writeShards",
"\n",
"if",
"conReads",
"{",
"r",
".",
"readShards",
"=",
"cReadShards",
"\n",
"}",
"\n",
"if",
"conWrites",
"{",
"r",
".",
"writeShards",
"=",
"cWriteShards",
"\n",
"}",
"\n",
"return",
"&",
"r",
",",
"err",
"\n",
"}"
] | // NewStreamC creates a new encoder and initializes it to
// the number of data shards and parity shards given.
//
// This functions as 'NewStream', but allows you to enable CONCURRENT reads and writes. | [
"NewStreamC",
"creates",
"a",
"new",
"encoder",
"and",
"initializes",
"it",
"to",
"the",
"number",
"of",
"data",
"shards",
"and",
"parity",
"shards",
"given",
".",
"This",
"functions",
"as",
"NewStream",
"but",
"allows",
"you",
"to",
"enable",
"CONCURRENT",
"reads",
"and",
"writes",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/streaming.go#L164-L180 |
150,510 | klauspost/reedsolomon | streaming.go | trimShards | func trimShards(in [][]byte, size int) [][]byte {
for i := range in {
if in[i] != nil {
in[i] = in[i][0:size]
}
if len(in[i]) < size {
in[i] = nil
}
}
return in
} | go | func trimShards(in [][]byte, size int) [][]byte {
for i := range in {
if in[i] != nil {
in[i] = in[i][0:size]
}
if len(in[i]) < size {
in[i] = nil
}
}
return in
} | [
"func",
"trimShards",
"(",
"in",
"[",
"]",
"[",
"]",
"byte",
",",
"size",
"int",
")",
"[",
"]",
"[",
"]",
"byte",
"{",
"for",
"i",
":=",
"range",
"in",
"{",
"if",
"in",
"[",
"i",
"]",
"!=",
"nil",
"{",
"in",
"[",
"i",
"]",
"=",
"in",
"[",
"i",
"]",
"[",
"0",
":",
"size",
"]",
"\n",
"}",
"\n",
"if",
"len",
"(",
"in",
"[",
"i",
"]",
")",
"<",
"size",
"{",
"in",
"[",
"i",
"]",
"=",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"in",
"\n",
"}"
] | // Trim the shards so they are all the same size | [
"Trim",
"the",
"shards",
"so",
"they",
"are",
"all",
"the",
"same",
"size"
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/streaming.go#L245-L255 |
150,511 | klauspost/reedsolomon | streaming.go | cReadShards | func cReadShards(dst [][]byte, in []io.Reader) error {
if len(in) != len(dst) {
panic("internal error: in and dst size do not match")
}
var wg sync.WaitGroup
wg.Add(len(in))
res := make(chan readResult, len(in))
for i := range in {
if in[i] == nil {
dst[i] = nil
wg.Done()
continue
}
go func(i int) {
defer wg.Done()
n, err := io.ReadFull(in[i], dst[i])
// The error is EOF only if no bytes were read.
// If an EOF happens after reading some but not all the bytes,
// ReadFull returns ErrUnexpectedEOF.
res <- readResult{size: n, err: err, n: i}
}(i)
}
wg.Wait()
close(res)
size := -1
for r := range res {
switch r.err {
case io.ErrUnexpectedEOF, io.EOF:
if size < 0 {
size = r.size
} else if r.size != size {
// Shard sizes must match.
return ErrShardSize
}
dst[r.n] = dst[r.n][0:r.size]
case nil:
default:
return StreamReadError{Err: r.err, Stream: r.n}
}
}
if size == 0 {
return io.EOF
}
return nil
} | go | func cReadShards(dst [][]byte, in []io.Reader) error {
if len(in) != len(dst) {
panic("internal error: in and dst size do not match")
}
var wg sync.WaitGroup
wg.Add(len(in))
res := make(chan readResult, len(in))
for i := range in {
if in[i] == nil {
dst[i] = nil
wg.Done()
continue
}
go func(i int) {
defer wg.Done()
n, err := io.ReadFull(in[i], dst[i])
// The error is EOF only if no bytes were read.
// If an EOF happens after reading some but not all the bytes,
// ReadFull returns ErrUnexpectedEOF.
res <- readResult{size: n, err: err, n: i}
}(i)
}
wg.Wait()
close(res)
size := -1
for r := range res {
switch r.err {
case io.ErrUnexpectedEOF, io.EOF:
if size < 0 {
size = r.size
} else if r.size != size {
// Shard sizes must match.
return ErrShardSize
}
dst[r.n] = dst[r.n][0:r.size]
case nil:
default:
return StreamReadError{Err: r.err, Stream: r.n}
}
}
if size == 0 {
return io.EOF
}
return nil
} | [
"func",
"cReadShards",
"(",
"dst",
"[",
"]",
"[",
"]",
"byte",
",",
"in",
"[",
"]",
"io",
".",
"Reader",
")",
"error",
"{",
"if",
"len",
"(",
"in",
")",
"!=",
"len",
"(",
"dst",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"wg",
".",
"Add",
"(",
"len",
"(",
"in",
")",
")",
"\n",
"res",
":=",
"make",
"(",
"chan",
"readResult",
",",
"len",
"(",
"in",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"in",
"{",
"if",
"in",
"[",
"i",
"]",
"==",
"nil",
"{",
"dst",
"[",
"i",
"]",
"=",
"nil",
"\n",
"wg",
".",
"Done",
"(",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"go",
"func",
"(",
"i",
"int",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"n",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"in",
"[",
"i",
"]",
",",
"dst",
"[",
"i",
"]",
")",
"\n",
"// The error is EOF only if no bytes were read.",
"// If an EOF happens after reading some but not all the bytes,",
"// ReadFull returns ErrUnexpectedEOF.",
"res",
"<-",
"readResult",
"{",
"size",
":",
"n",
",",
"err",
":",
"err",
",",
"n",
":",
"i",
"}",
"\n\n",
"}",
"(",
"i",
")",
"\n",
"}",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"close",
"(",
"res",
")",
"\n",
"size",
":=",
"-",
"1",
"\n",
"for",
"r",
":=",
"range",
"res",
"{",
"switch",
"r",
".",
"err",
"{",
"case",
"io",
".",
"ErrUnexpectedEOF",
",",
"io",
".",
"EOF",
":",
"if",
"size",
"<",
"0",
"{",
"size",
"=",
"r",
".",
"size",
"\n",
"}",
"else",
"if",
"r",
".",
"size",
"!=",
"size",
"{",
"// Shard sizes must match.",
"return",
"ErrShardSize",
"\n",
"}",
"\n",
"dst",
"[",
"r",
".",
"n",
"]",
"=",
"dst",
"[",
"r",
".",
"n",
"]",
"[",
"0",
":",
"r",
".",
"size",
"]",
"\n",
"case",
"nil",
":",
"default",
":",
"return",
"StreamReadError",
"{",
"Err",
":",
"r",
".",
"err",
",",
"Stream",
":",
"r",
".",
"n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"size",
"==",
"0",
"{",
"return",
"io",
".",
"EOF",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // cReadShards reads shards concurrently | [
"cReadShards",
"reads",
"shards",
"concurrently"
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/streaming.go#L319-L364 |
150,512 | klauspost/reedsolomon | streaming.go | cWriteShards | func cWriteShards(out []io.Writer, in [][]byte) error {
if len(out) != len(in) {
panic("internal error: in and out size do not match")
}
var errs = make(chan error, len(out))
var wg sync.WaitGroup
wg.Add(len(out))
for i := range in {
go func(i int) {
defer wg.Done()
if out[i] == nil {
errs <- nil
return
}
n, err := out[i].Write(in[i])
if err != nil {
errs <- StreamWriteError{Err: err, Stream: i}
return
}
if n != len(in[i]) {
errs <- StreamWriteError{Err: io.ErrShortWrite, Stream: i}
}
}(i)
}
wg.Wait()
close(errs)
for err := range errs {
if err != nil {
return err
}
}
return nil
} | go | func cWriteShards(out []io.Writer, in [][]byte) error {
if len(out) != len(in) {
panic("internal error: in and out size do not match")
}
var errs = make(chan error, len(out))
var wg sync.WaitGroup
wg.Add(len(out))
for i := range in {
go func(i int) {
defer wg.Done()
if out[i] == nil {
errs <- nil
return
}
n, err := out[i].Write(in[i])
if err != nil {
errs <- StreamWriteError{Err: err, Stream: i}
return
}
if n != len(in[i]) {
errs <- StreamWriteError{Err: io.ErrShortWrite, Stream: i}
}
}(i)
}
wg.Wait()
close(errs)
for err := range errs {
if err != nil {
return err
}
}
return nil
} | [
"func",
"cWriteShards",
"(",
"out",
"[",
"]",
"io",
".",
"Writer",
",",
"in",
"[",
"]",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"out",
")",
"!=",
"len",
"(",
"in",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"errs",
"=",
"make",
"(",
"chan",
"error",
",",
"len",
"(",
"out",
")",
")",
"\n",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"wg",
".",
"Add",
"(",
"len",
"(",
"out",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"in",
"{",
"go",
"func",
"(",
"i",
"int",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"if",
"out",
"[",
"i",
"]",
"==",
"nil",
"{",
"errs",
"<-",
"nil",
"\n",
"return",
"\n",
"}",
"\n",
"n",
",",
"err",
":=",
"out",
"[",
"i",
"]",
".",
"Write",
"(",
"in",
"[",
"i",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"errs",
"<-",
"StreamWriteError",
"{",
"Err",
":",
"err",
",",
"Stream",
":",
"i",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"n",
"!=",
"len",
"(",
"in",
"[",
"i",
"]",
")",
"{",
"errs",
"<-",
"StreamWriteError",
"{",
"Err",
":",
"io",
".",
"ErrShortWrite",
",",
"Stream",
":",
"i",
"}",
"\n",
"}",
"\n",
"}",
"(",
"i",
")",
"\n",
"}",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"close",
"(",
"errs",
")",
"\n",
"for",
"err",
":=",
"range",
"errs",
"{",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // cWriteShards writes shards concurrently | [
"cWriteShards",
"writes",
"shards",
"concurrently"
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/streaming.go#L367-L400 |
150,513 | klauspost/reedsolomon | streaming.go | Join | func (r rsStream) Join(dst io.Writer, shards []io.Reader, outSize int64) error {
// Do we have enough shards?
if len(shards) < r.r.DataShards {
return ErrTooFewShards
}
// Trim off parity shards if any
shards = shards[:r.r.DataShards]
for i := range shards {
if shards[i] == nil {
return StreamReadError{Err: ErrShardNoData, Stream: i}
}
}
// Join all shards
src := io.MultiReader(shards...)
// Copy data to dst
n, err := io.CopyN(dst, src, outSize)
if err == io.EOF {
return ErrShortData
}
if err != nil {
return err
}
if n != outSize {
return ErrShortData
}
return nil
} | go | func (r rsStream) Join(dst io.Writer, shards []io.Reader, outSize int64) error {
// Do we have enough shards?
if len(shards) < r.r.DataShards {
return ErrTooFewShards
}
// Trim off parity shards if any
shards = shards[:r.r.DataShards]
for i := range shards {
if shards[i] == nil {
return StreamReadError{Err: ErrShardNoData, Stream: i}
}
}
// Join all shards
src := io.MultiReader(shards...)
// Copy data to dst
n, err := io.CopyN(dst, src, outSize)
if err == io.EOF {
return ErrShortData
}
if err != nil {
return err
}
if n != outSize {
return ErrShortData
}
return nil
} | [
"func",
"(",
"r",
"rsStream",
")",
"Join",
"(",
"dst",
"io",
".",
"Writer",
",",
"shards",
"[",
"]",
"io",
".",
"Reader",
",",
"outSize",
"int64",
")",
"error",
"{",
"// Do we have enough shards?",
"if",
"len",
"(",
"shards",
")",
"<",
"r",
".",
"r",
".",
"DataShards",
"{",
"return",
"ErrTooFewShards",
"\n",
"}",
"\n\n",
"// Trim off parity shards if any",
"shards",
"=",
"shards",
"[",
":",
"r",
".",
"r",
".",
"DataShards",
"]",
"\n",
"for",
"i",
":=",
"range",
"shards",
"{",
"if",
"shards",
"[",
"i",
"]",
"==",
"nil",
"{",
"return",
"StreamReadError",
"{",
"Err",
":",
"ErrShardNoData",
",",
"Stream",
":",
"i",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"// Join all shards",
"src",
":=",
"io",
".",
"MultiReader",
"(",
"shards",
"...",
")",
"\n\n",
"// Copy data to dst",
"n",
",",
"err",
":=",
"io",
".",
"CopyN",
"(",
"dst",
",",
"src",
",",
"outSize",
")",
"\n",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"return",
"ErrShortData",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"n",
"!=",
"outSize",
"{",
"return",
"ErrShortData",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Join the shards and write the data segment to dst.
//
// Only the data shards are considered.
//
// You must supply the exact output size you want.
// If there are to few shards given, ErrTooFewShards will be returned.
// If the total data size is less than outSize, ErrShortData will be returned. | [
"Join",
"the",
"shards",
"and",
"write",
"the",
"data",
"segment",
"to",
"dst",
".",
"Only",
"the",
"data",
"shards",
"are",
"considered",
".",
"You",
"must",
"supply",
"the",
"exact",
"output",
"size",
"you",
"want",
".",
"If",
"there",
"are",
"to",
"few",
"shards",
"given",
"ErrTooFewShards",
"will",
"be",
"returned",
".",
"If",
"the",
"total",
"data",
"size",
"is",
"less",
"than",
"outSize",
"ErrShortData",
"will",
"be",
"returned",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/streaming.go#L512-L540 |
150,514 | klauspost/reedsolomon | streaming.go | Split | func (r rsStream) Split(data io.Reader, dst []io.Writer, size int64) error {
if size == 0 {
return ErrShortData
}
if len(dst) != r.r.DataShards {
return ErrInvShardNum
}
for i := range dst {
if dst[i] == nil {
return StreamWriteError{Err: ErrShardNoData, Stream: i}
}
}
// Calculate number of bytes per shard.
perShard := (size + int64(r.r.DataShards) - 1) / int64(r.r.DataShards)
// Pad data to r.Shards*perShard.
padding := make([]byte, (int64(r.r.Shards)*perShard)-size)
data = io.MultiReader(data, bytes.NewBuffer(padding))
// Split into equal-length shards and copy.
for i := range dst {
n, err := io.CopyN(dst[i], data, perShard)
if err != io.EOF && err != nil {
return err
}
if n != perShard {
return ErrShortData
}
}
return nil
} | go | func (r rsStream) Split(data io.Reader, dst []io.Writer, size int64) error {
if size == 0 {
return ErrShortData
}
if len(dst) != r.r.DataShards {
return ErrInvShardNum
}
for i := range dst {
if dst[i] == nil {
return StreamWriteError{Err: ErrShardNoData, Stream: i}
}
}
// Calculate number of bytes per shard.
perShard := (size + int64(r.r.DataShards) - 1) / int64(r.r.DataShards)
// Pad data to r.Shards*perShard.
padding := make([]byte, (int64(r.r.Shards)*perShard)-size)
data = io.MultiReader(data, bytes.NewBuffer(padding))
// Split into equal-length shards and copy.
for i := range dst {
n, err := io.CopyN(dst[i], data, perShard)
if err != io.EOF && err != nil {
return err
}
if n != perShard {
return ErrShortData
}
}
return nil
} | [
"func",
"(",
"r",
"rsStream",
")",
"Split",
"(",
"data",
"io",
".",
"Reader",
",",
"dst",
"[",
"]",
"io",
".",
"Writer",
",",
"size",
"int64",
")",
"error",
"{",
"if",
"size",
"==",
"0",
"{",
"return",
"ErrShortData",
"\n",
"}",
"\n",
"if",
"len",
"(",
"dst",
")",
"!=",
"r",
".",
"r",
".",
"DataShards",
"{",
"return",
"ErrInvShardNum",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"dst",
"{",
"if",
"dst",
"[",
"i",
"]",
"==",
"nil",
"{",
"return",
"StreamWriteError",
"{",
"Err",
":",
"ErrShardNoData",
",",
"Stream",
":",
"i",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Calculate number of bytes per shard.",
"perShard",
":=",
"(",
"size",
"+",
"int64",
"(",
"r",
".",
"r",
".",
"DataShards",
")",
"-",
"1",
")",
"/",
"int64",
"(",
"r",
".",
"r",
".",
"DataShards",
")",
"\n\n",
"// Pad data to r.Shards*perShard.",
"padding",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"(",
"int64",
"(",
"r",
".",
"r",
".",
"Shards",
")",
"*",
"perShard",
")",
"-",
"size",
")",
"\n",
"data",
"=",
"io",
".",
"MultiReader",
"(",
"data",
",",
"bytes",
".",
"NewBuffer",
"(",
"padding",
")",
")",
"\n\n",
"// Split into equal-length shards and copy.",
"for",
"i",
":=",
"range",
"dst",
"{",
"n",
",",
"err",
":=",
"io",
".",
"CopyN",
"(",
"dst",
"[",
"i",
"]",
",",
"data",
",",
"perShard",
")",
"\n",
"if",
"err",
"!=",
"io",
".",
"EOF",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"n",
"!=",
"perShard",
"{",
"return",
"ErrShortData",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Split a an input stream into the number of shards given to the encoder.
//
// The data will be split into equally sized shards.
// If the data size isn't dividable by the number of shards,
// the last shard will contain extra zeros.
//
// You must supply the total size of your input.
// 'ErrShortData' will be returned if it is unable to retrieve the
// number of bytes indicated. | [
"Split",
"a",
"an",
"input",
"stream",
"into",
"the",
"number",
"of",
"shards",
"given",
"to",
"the",
"encoder",
".",
"The",
"data",
"will",
"be",
"split",
"into",
"equally",
"sized",
"shards",
".",
"If",
"the",
"data",
"size",
"isn",
"t",
"dividable",
"by",
"the",
"number",
"of",
"shards",
"the",
"last",
"shard",
"will",
"contain",
"extra",
"zeros",
".",
"You",
"must",
"supply",
"the",
"total",
"size",
"of",
"your",
"input",
".",
"ErrShortData",
"will",
"be",
"returned",
"if",
"it",
"is",
"unable",
"to",
"retrieve",
"the",
"number",
"of",
"bytes",
"indicated",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/streaming.go#L551-L584 |
150,515 | klauspost/reedsolomon | options.go | WithMinSplitSize | func WithMinSplitSize(n int) Option {
return func(o *options) {
if n > 0 {
o.minSplitSize = n
}
}
} | go | func WithMinSplitSize(n int) Option {
return func(o *options) {
if n > 0 {
o.minSplitSize = n
}
}
} | [
"func",
"WithMinSplitSize",
"(",
"n",
"int",
")",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"options",
")",
"{",
"if",
"n",
">",
"0",
"{",
"o",
".",
"minSplitSize",
"=",
"n",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // WithMinSplitSize is the minimum encoding size in bytes per goroutine.
// See WithMaxGoroutines on how jobs are split.
// If n <= 0, it is ignored. | [
"WithMinSplitSize",
"is",
"the",
"minimum",
"encoding",
"size",
"in",
"bytes",
"per",
"goroutine",
".",
"See",
"WithMaxGoroutines",
"on",
"how",
"jobs",
"are",
"split",
".",
"If",
"n",
"<",
"=",
"0",
"it",
"is",
"ignored",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/options.go#L66-L72 |
150,516 | klauspost/reedsolomon | options.go | WithPAR1Matrix | func WithPAR1Matrix() Option {
return func(o *options) {
o.usePAR1Matrix = true
o.useCauchy = false
}
} | go | func WithPAR1Matrix() Option {
return func(o *options) {
o.usePAR1Matrix = true
o.useCauchy = false
}
} | [
"func",
"WithPAR1Matrix",
"(",
")",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"options",
")",
"{",
"o",
".",
"usePAR1Matrix",
"=",
"true",
"\n",
"o",
".",
"useCauchy",
"=",
"false",
"\n",
"}",
"\n",
"}"
] | // WithPAR1Matrix causes the encoder to build the matrix how PARv1
// does. Note that the method they use is buggy, and may lead to cases
// where recovery is impossible, even if there are enough parity
// shards. | [
"WithPAR1Matrix",
"causes",
"the",
"encoder",
"to",
"build",
"the",
"matrix",
"how",
"PARv1",
"does",
".",
"Note",
"that",
"the",
"method",
"they",
"use",
"is",
"buggy",
"and",
"may",
"lead",
"to",
"cases",
"where",
"recovery",
"is",
"impossible",
"even",
"if",
"there",
"are",
"enough",
"parity",
"shards",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/options.go#L102-L107 |
150,517 | klauspost/reedsolomon | options.go | WithCauchyMatrix | func WithCauchyMatrix() Option {
return func(o *options) {
o.useCauchy = true
o.usePAR1Matrix = false
}
} | go | func WithCauchyMatrix() Option {
return func(o *options) {
o.useCauchy = true
o.usePAR1Matrix = false
}
} | [
"func",
"WithCauchyMatrix",
"(",
")",
"Option",
"{",
"return",
"func",
"(",
"o",
"*",
"options",
")",
"{",
"o",
".",
"useCauchy",
"=",
"true",
"\n",
"o",
".",
"usePAR1Matrix",
"=",
"false",
"\n",
"}",
"\n",
"}"
] | // WithCauchyMatrix will make the encoder build a Cauchy style matrix.
// The output of this is not compatible with the standard output.
// A Cauchy matrix is faster to generate. This does not affect data throughput,
// but will result in slightly faster start-up time. | [
"WithCauchyMatrix",
"will",
"make",
"the",
"encoder",
"build",
"a",
"Cauchy",
"style",
"matrix",
".",
"The",
"output",
"of",
"this",
"is",
"not",
"compatible",
"with",
"the",
"standard",
"output",
".",
"A",
"Cauchy",
"matrix",
"is",
"faster",
"to",
"generate",
".",
"This",
"does",
"not",
"affect",
"data",
"throughput",
"but",
"will",
"result",
"in",
"slightly",
"faster",
"start",
"-",
"up",
"time",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/options.go#L113-L118 |
150,518 | klauspost/reedsolomon | reedsolomon.go | buildMatrix | func buildMatrix(dataShards, totalShards int) (matrix, error) {
// Start with a Vandermonde matrix. This matrix would work,
// in theory, but doesn't have the property that the data
// shards are unchanged after encoding.
vm, err := vandermonde(totalShards, dataShards)
if err != nil {
return nil, err
}
// Multiply by the inverse of the top square of the matrix.
// This will make the top square be the identity matrix, but
// preserve the property that any square subset of rows is
// invertible.
top, err := vm.SubMatrix(0, 0, dataShards, dataShards)
if err != nil {
return nil, err
}
topInv, err := top.Invert()
if err != nil {
return nil, err
}
return vm.Multiply(topInv)
} | go | func buildMatrix(dataShards, totalShards int) (matrix, error) {
// Start with a Vandermonde matrix. This matrix would work,
// in theory, but doesn't have the property that the data
// shards are unchanged after encoding.
vm, err := vandermonde(totalShards, dataShards)
if err != nil {
return nil, err
}
// Multiply by the inverse of the top square of the matrix.
// This will make the top square be the identity matrix, but
// preserve the property that any square subset of rows is
// invertible.
top, err := vm.SubMatrix(0, 0, dataShards, dataShards)
if err != nil {
return nil, err
}
topInv, err := top.Invert()
if err != nil {
return nil, err
}
return vm.Multiply(topInv)
} | [
"func",
"buildMatrix",
"(",
"dataShards",
",",
"totalShards",
"int",
")",
"(",
"matrix",
",",
"error",
")",
"{",
"// Start with a Vandermonde matrix. This matrix would work,",
"// in theory, but doesn't have the property that the data",
"// shards are unchanged after encoding.",
"vm",
",",
"err",
":=",
"vandermonde",
"(",
"totalShards",
",",
"dataShards",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Multiply by the inverse of the top square of the matrix.",
"// This will make the top square be the identity matrix, but",
"// preserve the property that any square subset of rows is",
"// invertible.",
"top",
",",
"err",
":=",
"vm",
".",
"SubMatrix",
"(",
"0",
",",
"0",
",",
"dataShards",
",",
"dataShards",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"topInv",
",",
"err",
":=",
"top",
".",
"Invert",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"vm",
".",
"Multiply",
"(",
"topInv",
")",
"\n",
"}"
] | // buildMatrix creates the matrix to use for encoding, given the
// number of data shards and the number of total shards.
//
// The top square of the matrix is guaranteed to be an identity
// matrix, which means that the data shards are unchanged after
// encoding. | [
"buildMatrix",
"creates",
"the",
"matrix",
"to",
"use",
"for",
"encoding",
"given",
"the",
"number",
"of",
"data",
"shards",
"and",
"the",
"number",
"of",
"total",
"shards",
".",
"The",
"top",
"square",
"of",
"the",
"matrix",
"is",
"guaranteed",
"to",
"be",
"an",
"identity",
"matrix",
"which",
"means",
"that",
"the",
"data",
"shards",
"are",
"unchanged",
"after",
"encoding",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L133-L157 |
150,519 | klauspost/reedsolomon | reedsolomon.go | buildMatrixPAR1 | func buildMatrixPAR1(dataShards, totalShards int) (matrix, error) {
result, err := newMatrix(totalShards, dataShards)
if err != nil {
return nil, err
}
for r, row := range result {
// The top portion of the matrix is the identity
// matrix, and the bottom is a transposed Vandermonde
// matrix starting at 1 instead of 0.
if r < dataShards {
result[r][r] = 1
} else {
for c := range row {
result[r][c] = galExp(byte(c+1), r-dataShards)
}
}
}
return result, nil
} | go | func buildMatrixPAR1(dataShards, totalShards int) (matrix, error) {
result, err := newMatrix(totalShards, dataShards)
if err != nil {
return nil, err
}
for r, row := range result {
// The top portion of the matrix is the identity
// matrix, and the bottom is a transposed Vandermonde
// matrix starting at 1 instead of 0.
if r < dataShards {
result[r][r] = 1
} else {
for c := range row {
result[r][c] = galExp(byte(c+1), r-dataShards)
}
}
}
return result, nil
} | [
"func",
"buildMatrixPAR1",
"(",
"dataShards",
",",
"totalShards",
"int",
")",
"(",
"matrix",
",",
"error",
")",
"{",
"result",
",",
"err",
":=",
"newMatrix",
"(",
"totalShards",
",",
"dataShards",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"r",
",",
"row",
":=",
"range",
"result",
"{",
"// The top portion of the matrix is the identity",
"// matrix, and the bottom is a transposed Vandermonde",
"// matrix starting at 1 instead of 0.",
"if",
"r",
"<",
"dataShards",
"{",
"result",
"[",
"r",
"]",
"[",
"r",
"]",
"=",
"1",
"\n",
"}",
"else",
"{",
"for",
"c",
":=",
"range",
"row",
"{",
"result",
"[",
"r",
"]",
"[",
"c",
"]",
"=",
"galExp",
"(",
"byte",
"(",
"c",
"+",
"1",
")",
",",
"r",
"-",
"dataShards",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // buildMatrixPAR1 creates the matrix to use for encoding according to
// the PARv1 spec, given the number of data shards and the number of
// total shards. Note that the method they use is buggy, and may lead
// to cases where recovery is impossible, even if there are enough
// parity shards.
//
// The top square of the matrix is guaranteed to be an identity
// matrix, which means that the data shards are unchanged after
// encoding. | [
"buildMatrixPAR1",
"creates",
"the",
"matrix",
"to",
"use",
"for",
"encoding",
"according",
"to",
"the",
"PARv1",
"spec",
"given",
"the",
"number",
"of",
"data",
"shards",
"and",
"the",
"number",
"of",
"total",
"shards",
".",
"Note",
"that",
"the",
"method",
"they",
"use",
"is",
"buggy",
"and",
"may",
"lead",
"to",
"cases",
"where",
"recovery",
"is",
"impossible",
"even",
"if",
"there",
"are",
"enough",
"parity",
"shards",
".",
"The",
"top",
"square",
"of",
"the",
"matrix",
"is",
"guaranteed",
"to",
"be",
"an",
"identity",
"matrix",
"which",
"means",
"that",
"the",
"data",
"shards",
"are",
"unchanged",
"after",
"encoding",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L168-L187 |
150,520 | klauspost/reedsolomon | reedsolomon.go | New | func New(dataShards, parityShards int, opts ...Option) (Encoder, error) {
r := reedSolomon{
DataShards: dataShards,
ParityShards: parityShards,
Shards: dataShards + parityShards,
o: defaultOptions,
}
for _, opt := range opts {
opt(&r.o)
}
if dataShards <= 0 || parityShards <= 0 {
return nil, ErrInvShardNum
}
if dataShards+parityShards > 256 {
return nil, ErrMaxShardNum
}
var err error
switch {
case r.o.useCauchy:
r.m, err = buildMatrixCauchy(dataShards, r.Shards)
case r.o.usePAR1Matrix:
r.m, err = buildMatrixPAR1(dataShards, r.Shards)
default:
r.m, err = buildMatrix(dataShards, r.Shards)
}
if err != nil {
return nil, err
}
if r.o.shardSize > 0 {
cacheSize := cpuid.CPU.Cache.L2
if cacheSize <= 0 {
// Set to 128K if undetectable.
cacheSize = 128 << 10
}
p := runtime.NumCPU()
// 1 input + parity must fit in cache, and we add one more to be safer.
shards := 1 + parityShards
g := (r.o.shardSize * shards) / (cacheSize - (cacheSize >> 4))
if cpuid.CPU.ThreadsPerCore > 1 {
// If multiple threads per core, make sure they don't contend for cache.
g *= cpuid.CPU.ThreadsPerCore
}
g *= 2
if g < p {
g = p
}
// Have g be multiple of p
g += p - 1
g -= g % p
r.o.maxGoroutines = g
}
// Inverted matrices are cached in a tree keyed by the indices
// of the invalid rows of the data to reconstruct.
// The inversion root node will have the identity matrix as
// its inversion matrix because it implies there are no errors
// with the original data.
r.tree = newInversionTree(dataShards, parityShards)
r.parity = make([][]byte, parityShards)
for i := range r.parity {
r.parity[i] = r.m[dataShards+i]
}
return &r, err
} | go | func New(dataShards, parityShards int, opts ...Option) (Encoder, error) {
r := reedSolomon{
DataShards: dataShards,
ParityShards: parityShards,
Shards: dataShards + parityShards,
o: defaultOptions,
}
for _, opt := range opts {
opt(&r.o)
}
if dataShards <= 0 || parityShards <= 0 {
return nil, ErrInvShardNum
}
if dataShards+parityShards > 256 {
return nil, ErrMaxShardNum
}
var err error
switch {
case r.o.useCauchy:
r.m, err = buildMatrixCauchy(dataShards, r.Shards)
case r.o.usePAR1Matrix:
r.m, err = buildMatrixPAR1(dataShards, r.Shards)
default:
r.m, err = buildMatrix(dataShards, r.Shards)
}
if err != nil {
return nil, err
}
if r.o.shardSize > 0 {
cacheSize := cpuid.CPU.Cache.L2
if cacheSize <= 0 {
// Set to 128K if undetectable.
cacheSize = 128 << 10
}
p := runtime.NumCPU()
// 1 input + parity must fit in cache, and we add one more to be safer.
shards := 1 + parityShards
g := (r.o.shardSize * shards) / (cacheSize - (cacheSize >> 4))
if cpuid.CPU.ThreadsPerCore > 1 {
// If multiple threads per core, make sure they don't contend for cache.
g *= cpuid.CPU.ThreadsPerCore
}
g *= 2
if g < p {
g = p
}
// Have g be multiple of p
g += p - 1
g -= g % p
r.o.maxGoroutines = g
}
// Inverted matrices are cached in a tree keyed by the indices
// of the invalid rows of the data to reconstruct.
// The inversion root node will have the identity matrix as
// its inversion matrix because it implies there are no errors
// with the original data.
r.tree = newInversionTree(dataShards, parityShards)
r.parity = make([][]byte, parityShards)
for i := range r.parity {
r.parity[i] = r.m[dataShards+i]
}
return &r, err
} | [
"func",
"New",
"(",
"dataShards",
",",
"parityShards",
"int",
",",
"opts",
"...",
"Option",
")",
"(",
"Encoder",
",",
"error",
")",
"{",
"r",
":=",
"reedSolomon",
"{",
"DataShards",
":",
"dataShards",
",",
"ParityShards",
":",
"parityShards",
",",
"Shards",
":",
"dataShards",
"+",
"parityShards",
",",
"o",
":",
"defaultOptions",
",",
"}",
"\n\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"opt",
"(",
"&",
"r",
".",
"o",
")",
"\n",
"}",
"\n",
"if",
"dataShards",
"<=",
"0",
"||",
"parityShards",
"<=",
"0",
"{",
"return",
"nil",
",",
"ErrInvShardNum",
"\n",
"}",
"\n\n",
"if",
"dataShards",
"+",
"parityShards",
">",
"256",
"{",
"return",
"nil",
",",
"ErrMaxShardNum",
"\n",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"switch",
"{",
"case",
"r",
".",
"o",
".",
"useCauchy",
":",
"r",
".",
"m",
",",
"err",
"=",
"buildMatrixCauchy",
"(",
"dataShards",
",",
"r",
".",
"Shards",
")",
"\n",
"case",
"r",
".",
"o",
".",
"usePAR1Matrix",
":",
"r",
".",
"m",
",",
"err",
"=",
"buildMatrixPAR1",
"(",
"dataShards",
",",
"r",
".",
"Shards",
")",
"\n",
"default",
":",
"r",
".",
"m",
",",
"err",
"=",
"buildMatrix",
"(",
"dataShards",
",",
"r",
".",
"Shards",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"r",
".",
"o",
".",
"shardSize",
">",
"0",
"{",
"cacheSize",
":=",
"cpuid",
".",
"CPU",
".",
"Cache",
".",
"L2",
"\n",
"if",
"cacheSize",
"<=",
"0",
"{",
"// Set to 128K if undetectable.",
"cacheSize",
"=",
"128",
"<<",
"10",
"\n",
"}",
"\n",
"p",
":=",
"runtime",
".",
"NumCPU",
"(",
")",
"\n\n",
"// 1 input + parity must fit in cache, and we add one more to be safer.",
"shards",
":=",
"1",
"+",
"parityShards",
"\n",
"g",
":=",
"(",
"r",
".",
"o",
".",
"shardSize",
"*",
"shards",
")",
"/",
"(",
"cacheSize",
"-",
"(",
"cacheSize",
">>",
"4",
")",
")",
"\n\n",
"if",
"cpuid",
".",
"CPU",
".",
"ThreadsPerCore",
">",
"1",
"{",
"// If multiple threads per core, make sure they don't contend for cache.",
"g",
"*=",
"cpuid",
".",
"CPU",
".",
"ThreadsPerCore",
"\n",
"}",
"\n",
"g",
"*=",
"2",
"\n",
"if",
"g",
"<",
"p",
"{",
"g",
"=",
"p",
"\n",
"}",
"\n\n",
"// Have g be multiple of p",
"g",
"+=",
"p",
"-",
"1",
"\n",
"g",
"-=",
"g",
"%",
"p",
"\n\n",
"r",
".",
"o",
".",
"maxGoroutines",
"=",
"g",
"\n",
"}",
"\n\n",
"// Inverted matrices are cached in a tree keyed by the indices",
"// of the invalid rows of the data to reconstruct.",
"// The inversion root node will have the identity matrix as",
"// its inversion matrix because it implies there are no errors",
"// with the original data.",
"r",
".",
"tree",
"=",
"newInversionTree",
"(",
"dataShards",
",",
"parityShards",
")",
"\n\n",
"r",
".",
"parity",
"=",
"make",
"(",
"[",
"]",
"[",
"]",
"byte",
",",
"parityShards",
")",
"\n",
"for",
"i",
":=",
"range",
"r",
".",
"parity",
"{",
"r",
".",
"parity",
"[",
"i",
"]",
"=",
"r",
".",
"m",
"[",
"dataShards",
"+",
"i",
"]",
"\n",
"}",
"\n\n",
"return",
"&",
"r",
",",
"err",
"\n",
"}"
] | // New creates a new encoder and initializes it to
// the number of data shards and parity shards that
// you want to use. You can reuse this encoder.
// Note that the maximum number of total shards is 256.
// If no options are supplied, default options are used. | [
"New",
"creates",
"a",
"new",
"encoder",
"and",
"initializes",
"it",
"to",
"the",
"number",
"of",
"data",
"shards",
"and",
"parity",
"shards",
"that",
"you",
"want",
"to",
"use",
".",
"You",
"can",
"reuse",
"this",
"encoder",
".",
"Note",
"that",
"the",
"maximum",
"number",
"of",
"total",
"shards",
"is",
"256",
".",
"If",
"no",
"options",
"are",
"supplied",
"default",
"options",
"are",
"used",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L214-L286 |
150,521 | klauspost/reedsolomon | reedsolomon.go | Encode | func (r reedSolomon) Encode(shards [][]byte) error {
if len(shards) != r.Shards {
return ErrTooFewShards
}
err := checkShards(shards, false)
if err != nil {
return err
}
// Get the slice of output buffers.
output := shards[r.DataShards:]
// Do the coding.
r.codeSomeShards(r.parity, shards[0:r.DataShards], output, r.ParityShards, len(shards[0]))
return nil
} | go | func (r reedSolomon) Encode(shards [][]byte) error {
if len(shards) != r.Shards {
return ErrTooFewShards
}
err := checkShards(shards, false)
if err != nil {
return err
}
// Get the slice of output buffers.
output := shards[r.DataShards:]
// Do the coding.
r.codeSomeShards(r.parity, shards[0:r.DataShards], output, r.ParityShards, len(shards[0]))
return nil
} | [
"func",
"(",
"r",
"reedSolomon",
")",
"Encode",
"(",
"shards",
"[",
"]",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"shards",
")",
"!=",
"r",
".",
"Shards",
"{",
"return",
"ErrTooFewShards",
"\n",
"}",
"\n\n",
"err",
":=",
"checkShards",
"(",
"shards",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Get the slice of output buffers.",
"output",
":=",
"shards",
"[",
"r",
".",
"DataShards",
":",
"]",
"\n\n",
"// Do the coding.",
"r",
".",
"codeSomeShards",
"(",
"r",
".",
"parity",
",",
"shards",
"[",
"0",
":",
"r",
".",
"DataShards",
"]",
",",
"output",
",",
"r",
".",
"ParityShards",
",",
"len",
"(",
"shards",
"[",
"0",
"]",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Encodes parity for a set of data shards.
// An array 'shards' containing data shards followed by parity shards.
// The number of shards must match the number given to New.
// Each shard is a byte array, and they must all be the same size.
// The parity shards will always be overwritten and the data shards
// will remain the same. | [
"Encodes",
"parity",
"for",
"a",
"set",
"of",
"data",
"shards",
".",
"An",
"array",
"shards",
"containing",
"data",
"shards",
"followed",
"by",
"parity",
"shards",
".",
"The",
"number",
"of",
"shards",
"must",
"match",
"the",
"number",
"given",
"to",
"New",
".",
"Each",
"shard",
"is",
"a",
"byte",
"array",
"and",
"they",
"must",
"all",
"be",
"the",
"same",
"size",
".",
"The",
"parity",
"shards",
"will",
"always",
"be",
"overwritten",
"and",
"the",
"data",
"shards",
"will",
"remain",
"the",
"same",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L299-L315 |
150,522 | klauspost/reedsolomon | reedsolomon.go | Verify | func (r reedSolomon) Verify(shards [][]byte) (bool, error) {
if len(shards) != r.Shards {
return false, ErrTooFewShards
}
err := checkShards(shards, false)
if err != nil {
return false, err
}
// Slice of buffers being checked.
toCheck := shards[r.DataShards:]
// Do the checking.
return r.checkSomeShards(r.parity, shards[0:r.DataShards], toCheck, r.ParityShards, len(shards[0])), nil
} | go | func (r reedSolomon) Verify(shards [][]byte) (bool, error) {
if len(shards) != r.Shards {
return false, ErrTooFewShards
}
err := checkShards(shards, false)
if err != nil {
return false, err
}
// Slice of buffers being checked.
toCheck := shards[r.DataShards:]
// Do the checking.
return r.checkSomeShards(r.parity, shards[0:r.DataShards], toCheck, r.ParityShards, len(shards[0])), nil
} | [
"func",
"(",
"r",
"reedSolomon",
")",
"Verify",
"(",
"shards",
"[",
"]",
"[",
"]",
"byte",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"len",
"(",
"shards",
")",
"!=",
"r",
".",
"Shards",
"{",
"return",
"false",
",",
"ErrTooFewShards",
"\n",
"}",
"\n",
"err",
":=",
"checkShards",
"(",
"shards",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"// Slice of buffers being checked.",
"toCheck",
":=",
"shards",
"[",
"r",
".",
"DataShards",
":",
"]",
"\n\n",
"// Do the checking.",
"return",
"r",
".",
"checkSomeShards",
"(",
"r",
".",
"parity",
",",
"shards",
"[",
"0",
":",
"r",
".",
"DataShards",
"]",
",",
"toCheck",
",",
"r",
".",
"ParityShards",
",",
"len",
"(",
"shards",
"[",
"0",
"]",
")",
")",
",",
"nil",
"\n",
"}"
] | // Verify returns true if the parity shards contain the right data.
// The data is the same format as Encode. No data is modified. | [
"Verify",
"returns",
"true",
"if",
"the",
"parity",
"shards",
"contain",
"the",
"right",
"data",
".",
"The",
"data",
"is",
"the",
"same",
"format",
"as",
"Encode",
".",
"No",
"data",
"is",
"modified",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L414-L428 |
150,523 | klauspost/reedsolomon | reedsolomon.go | codeSomeShards | func (r reedSolomon) codeSomeShards(matrixRows, inputs, outputs [][]byte, outputCount, byteCount int) {
if r.o.useAVX512 && len(inputs) >= 4 && len(outputs) >= 2 {
r.codeSomeShardsAvx512(matrixRows, inputs, outputs, outputCount, byteCount)
return
} else if r.o.maxGoroutines > 1 && byteCount > r.o.minSplitSize {
r.codeSomeShardsP(matrixRows, inputs, outputs, outputCount, byteCount)
return
}
for c := 0; c < r.DataShards; c++ {
in := inputs[c]
for iRow := 0; iRow < outputCount; iRow++ {
if c == 0 {
galMulSlice(matrixRows[iRow][c], in, outputs[iRow], &r.o)
} else {
galMulSliceXor(matrixRows[iRow][c], in, outputs[iRow], &r.o)
}
}
}
} | go | func (r reedSolomon) codeSomeShards(matrixRows, inputs, outputs [][]byte, outputCount, byteCount int) {
if r.o.useAVX512 && len(inputs) >= 4 && len(outputs) >= 2 {
r.codeSomeShardsAvx512(matrixRows, inputs, outputs, outputCount, byteCount)
return
} else if r.o.maxGoroutines > 1 && byteCount > r.o.minSplitSize {
r.codeSomeShardsP(matrixRows, inputs, outputs, outputCount, byteCount)
return
}
for c := 0; c < r.DataShards; c++ {
in := inputs[c]
for iRow := 0; iRow < outputCount; iRow++ {
if c == 0 {
galMulSlice(matrixRows[iRow][c], in, outputs[iRow], &r.o)
} else {
galMulSliceXor(matrixRows[iRow][c], in, outputs[iRow], &r.o)
}
}
}
} | [
"func",
"(",
"r",
"reedSolomon",
")",
"codeSomeShards",
"(",
"matrixRows",
",",
"inputs",
",",
"outputs",
"[",
"]",
"[",
"]",
"byte",
",",
"outputCount",
",",
"byteCount",
"int",
")",
"{",
"if",
"r",
".",
"o",
".",
"useAVX512",
"&&",
"len",
"(",
"inputs",
")",
">=",
"4",
"&&",
"len",
"(",
"outputs",
")",
">=",
"2",
"{",
"r",
".",
"codeSomeShardsAvx512",
"(",
"matrixRows",
",",
"inputs",
",",
"outputs",
",",
"outputCount",
",",
"byteCount",
")",
"\n",
"return",
"\n",
"}",
"else",
"if",
"r",
".",
"o",
".",
"maxGoroutines",
">",
"1",
"&&",
"byteCount",
">",
"r",
".",
"o",
".",
"minSplitSize",
"{",
"r",
".",
"codeSomeShardsP",
"(",
"matrixRows",
",",
"inputs",
",",
"outputs",
",",
"outputCount",
",",
"byteCount",
")",
"\n",
"return",
"\n",
"}",
"\n",
"for",
"c",
":=",
"0",
";",
"c",
"<",
"r",
".",
"DataShards",
";",
"c",
"++",
"{",
"in",
":=",
"inputs",
"[",
"c",
"]",
"\n",
"for",
"iRow",
":=",
"0",
";",
"iRow",
"<",
"outputCount",
";",
"iRow",
"++",
"{",
"if",
"c",
"==",
"0",
"{",
"galMulSlice",
"(",
"matrixRows",
"[",
"iRow",
"]",
"[",
"c",
"]",
",",
"in",
",",
"outputs",
"[",
"iRow",
"]",
",",
"&",
"r",
".",
"o",
")",
"\n",
"}",
"else",
"{",
"galMulSliceXor",
"(",
"matrixRows",
"[",
"iRow",
"]",
"[",
"c",
"]",
",",
"in",
",",
"outputs",
"[",
"iRow",
"]",
",",
"&",
"r",
".",
"o",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Multiplies a subset of rows from a coding matrix by a full set of
// input shards to produce some output shards.
// 'matrixRows' is The rows from the matrix to use.
// 'inputs' An array of byte arrays, each of which is one input shard.
// The number of inputs used is determined by the length of each matrix row.
// outputs Byte arrays where the computed shards are stored.
// The number of outputs computed, and the
// number of matrix rows used, is determined by
// outputCount, which is the number of outputs to compute. | [
"Multiplies",
"a",
"subset",
"of",
"rows",
"from",
"a",
"coding",
"matrix",
"by",
"a",
"full",
"set",
"of",
"input",
"shards",
"to",
"produce",
"some",
"output",
"shards",
".",
"matrixRows",
"is",
"The",
"rows",
"from",
"the",
"matrix",
"to",
"use",
".",
"inputs",
"An",
"array",
"of",
"byte",
"arrays",
"each",
"of",
"which",
"is",
"one",
"input",
"shard",
".",
"The",
"number",
"of",
"inputs",
"used",
"is",
"determined",
"by",
"the",
"length",
"of",
"each",
"matrix",
"row",
".",
"outputs",
"Byte",
"arrays",
"where",
"the",
"computed",
"shards",
"are",
"stored",
".",
"The",
"number",
"of",
"outputs",
"computed",
"and",
"the",
"number",
"of",
"matrix",
"rows",
"used",
"is",
"determined",
"by",
"outputCount",
"which",
"is",
"the",
"number",
"of",
"outputs",
"to",
"compute",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L439-L457 |
150,524 | klauspost/reedsolomon | reedsolomon.go | codeSomeShardsP | func (r reedSolomon) codeSomeShardsP(matrixRows, inputs, outputs [][]byte, outputCount, byteCount int) {
var wg sync.WaitGroup
do := byteCount / r.o.maxGoroutines
if do < r.o.minSplitSize {
do = r.o.minSplitSize
}
// Make sizes divisible by 32
do = (do + 31) & (^31)
start := 0
for start < byteCount {
if start+do > byteCount {
do = byteCount - start
}
wg.Add(1)
go func(start, stop int) {
for c := 0; c < r.DataShards; c++ {
in := inputs[c][start:stop]
for iRow := 0; iRow < outputCount; iRow++ {
if c == 0 {
galMulSlice(matrixRows[iRow][c], in, outputs[iRow][start:stop], &r.o)
} else {
galMulSliceXor(matrixRows[iRow][c], in, outputs[iRow][start:stop], &r.o)
}
}
}
wg.Done()
}(start, start+do)
start += do
}
wg.Wait()
} | go | func (r reedSolomon) codeSomeShardsP(matrixRows, inputs, outputs [][]byte, outputCount, byteCount int) {
var wg sync.WaitGroup
do := byteCount / r.o.maxGoroutines
if do < r.o.minSplitSize {
do = r.o.minSplitSize
}
// Make sizes divisible by 32
do = (do + 31) & (^31)
start := 0
for start < byteCount {
if start+do > byteCount {
do = byteCount - start
}
wg.Add(1)
go func(start, stop int) {
for c := 0; c < r.DataShards; c++ {
in := inputs[c][start:stop]
for iRow := 0; iRow < outputCount; iRow++ {
if c == 0 {
galMulSlice(matrixRows[iRow][c], in, outputs[iRow][start:stop], &r.o)
} else {
galMulSliceXor(matrixRows[iRow][c], in, outputs[iRow][start:stop], &r.o)
}
}
}
wg.Done()
}(start, start+do)
start += do
}
wg.Wait()
} | [
"func",
"(",
"r",
"reedSolomon",
")",
"codeSomeShardsP",
"(",
"matrixRows",
",",
"inputs",
",",
"outputs",
"[",
"]",
"[",
"]",
"byte",
",",
"outputCount",
",",
"byteCount",
"int",
")",
"{",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"do",
":=",
"byteCount",
"/",
"r",
".",
"o",
".",
"maxGoroutines",
"\n",
"if",
"do",
"<",
"r",
".",
"o",
".",
"minSplitSize",
"{",
"do",
"=",
"r",
".",
"o",
".",
"minSplitSize",
"\n",
"}",
"\n",
"// Make sizes divisible by 32",
"do",
"=",
"(",
"do",
"+",
"31",
")",
"&",
"(",
"^",
"31",
")",
"\n",
"start",
":=",
"0",
"\n",
"for",
"start",
"<",
"byteCount",
"{",
"if",
"start",
"+",
"do",
">",
"byteCount",
"{",
"do",
"=",
"byteCount",
"-",
"start",
"\n",
"}",
"\n",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
"start",
",",
"stop",
"int",
")",
"{",
"for",
"c",
":=",
"0",
";",
"c",
"<",
"r",
".",
"DataShards",
";",
"c",
"++",
"{",
"in",
":=",
"inputs",
"[",
"c",
"]",
"[",
"start",
":",
"stop",
"]",
"\n",
"for",
"iRow",
":=",
"0",
";",
"iRow",
"<",
"outputCount",
";",
"iRow",
"++",
"{",
"if",
"c",
"==",
"0",
"{",
"galMulSlice",
"(",
"matrixRows",
"[",
"iRow",
"]",
"[",
"c",
"]",
",",
"in",
",",
"outputs",
"[",
"iRow",
"]",
"[",
"start",
":",
"stop",
"]",
",",
"&",
"r",
".",
"o",
")",
"\n",
"}",
"else",
"{",
"galMulSliceXor",
"(",
"matrixRows",
"[",
"iRow",
"]",
"[",
"c",
"]",
",",
"in",
",",
"outputs",
"[",
"iRow",
"]",
"[",
"start",
":",
"stop",
"]",
",",
"&",
"r",
".",
"o",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"wg",
".",
"Done",
"(",
")",
"\n",
"}",
"(",
"start",
",",
"start",
"+",
"do",
")",
"\n",
"start",
"+=",
"do",
"\n",
"}",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"}"
] | // Perform the same as codeSomeShards, but split the workload into
// several goroutines. | [
"Perform",
"the",
"same",
"as",
"codeSomeShards",
"but",
"split",
"the",
"workload",
"into",
"several",
"goroutines",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L461-L491 |
150,525 | klauspost/reedsolomon | reedsolomon.go | checkSomeShards | func (r reedSolomon) checkSomeShards(matrixRows, inputs, toCheck [][]byte, outputCount, byteCount int) bool {
if r.o.maxGoroutines > 1 && byteCount > r.o.minSplitSize {
return r.checkSomeShardsP(matrixRows, inputs, toCheck, outputCount, byteCount)
}
outputs := make([][]byte, len(toCheck))
for i := range outputs {
outputs[i] = make([]byte, byteCount)
}
for c := 0; c < r.DataShards; c++ {
in := inputs[c]
for iRow := 0; iRow < outputCount; iRow++ {
galMulSliceXor(matrixRows[iRow][c], in, outputs[iRow], &r.o)
}
}
for i, calc := range outputs {
if !bytes.Equal(calc, toCheck[i]) {
return false
}
}
return true
} | go | func (r reedSolomon) checkSomeShards(matrixRows, inputs, toCheck [][]byte, outputCount, byteCount int) bool {
if r.o.maxGoroutines > 1 && byteCount > r.o.minSplitSize {
return r.checkSomeShardsP(matrixRows, inputs, toCheck, outputCount, byteCount)
}
outputs := make([][]byte, len(toCheck))
for i := range outputs {
outputs[i] = make([]byte, byteCount)
}
for c := 0; c < r.DataShards; c++ {
in := inputs[c]
for iRow := 0; iRow < outputCount; iRow++ {
galMulSliceXor(matrixRows[iRow][c], in, outputs[iRow], &r.o)
}
}
for i, calc := range outputs {
if !bytes.Equal(calc, toCheck[i]) {
return false
}
}
return true
} | [
"func",
"(",
"r",
"reedSolomon",
")",
"checkSomeShards",
"(",
"matrixRows",
",",
"inputs",
",",
"toCheck",
"[",
"]",
"[",
"]",
"byte",
",",
"outputCount",
",",
"byteCount",
"int",
")",
"bool",
"{",
"if",
"r",
".",
"o",
".",
"maxGoroutines",
">",
"1",
"&&",
"byteCount",
">",
"r",
".",
"o",
".",
"minSplitSize",
"{",
"return",
"r",
".",
"checkSomeShardsP",
"(",
"matrixRows",
",",
"inputs",
",",
"toCheck",
",",
"outputCount",
",",
"byteCount",
")",
"\n",
"}",
"\n",
"outputs",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"byte",
",",
"len",
"(",
"toCheck",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"outputs",
"{",
"outputs",
"[",
"i",
"]",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"byteCount",
")",
"\n",
"}",
"\n",
"for",
"c",
":=",
"0",
";",
"c",
"<",
"r",
".",
"DataShards",
";",
"c",
"++",
"{",
"in",
":=",
"inputs",
"[",
"c",
"]",
"\n",
"for",
"iRow",
":=",
"0",
";",
"iRow",
"<",
"outputCount",
";",
"iRow",
"++",
"{",
"galMulSliceXor",
"(",
"matrixRows",
"[",
"iRow",
"]",
"[",
"c",
"]",
",",
"in",
",",
"outputs",
"[",
"iRow",
"]",
",",
"&",
"r",
".",
"o",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"calc",
":=",
"range",
"outputs",
"{",
"if",
"!",
"bytes",
".",
"Equal",
"(",
"calc",
",",
"toCheck",
"[",
"i",
"]",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // checkSomeShards is mostly the same as codeSomeShards,
// except this will check values and return
// as soon as a difference is found. | [
"checkSomeShards",
"is",
"mostly",
"the",
"same",
"as",
"codeSomeShards",
"except",
"this",
"will",
"check",
"values",
"and",
"return",
"as",
"soon",
"as",
"a",
"difference",
"is",
"found",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L496-L517 |
150,526 | klauspost/reedsolomon | reedsolomon.go | checkShards | func checkShards(shards [][]byte, nilok bool) error {
size := shardSize(shards)
if size == 0 {
return ErrShardNoData
}
for _, shard := range shards {
if len(shard) != size {
if len(shard) != 0 || !nilok {
return ErrShardSize
}
}
}
return nil
} | go | func checkShards(shards [][]byte, nilok bool) error {
size := shardSize(shards)
if size == 0 {
return ErrShardNoData
}
for _, shard := range shards {
if len(shard) != size {
if len(shard) != 0 || !nilok {
return ErrShardSize
}
}
}
return nil
} | [
"func",
"checkShards",
"(",
"shards",
"[",
"]",
"[",
"]",
"byte",
",",
"nilok",
"bool",
")",
"error",
"{",
"size",
":=",
"shardSize",
"(",
"shards",
")",
"\n",
"if",
"size",
"==",
"0",
"{",
"return",
"ErrShardNoData",
"\n",
"}",
"\n",
"for",
"_",
",",
"shard",
":=",
"range",
"shards",
"{",
"if",
"len",
"(",
"shard",
")",
"!=",
"size",
"{",
"if",
"len",
"(",
"shard",
")",
"!=",
"0",
"||",
"!",
"nilok",
"{",
"return",
"ErrShardSize",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // checkShards will check if shards are the same size
// or 0, if allowed. An error is returned if this fails.
// An error is also returned if all shards are size 0. | [
"checkShards",
"will",
"check",
"if",
"shards",
"are",
"the",
"same",
"size",
"or",
"0",
"if",
"allowed",
".",
"An",
"error",
"is",
"returned",
"if",
"this",
"fails",
".",
"An",
"error",
"is",
"also",
"returned",
"if",
"all",
"shards",
"are",
"size",
"0",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L581-L594 |
150,527 | klauspost/reedsolomon | reedsolomon.go | shardSize | func shardSize(shards [][]byte) int {
for _, shard := range shards {
if len(shard) != 0 {
return len(shard)
}
}
return 0
} | go | func shardSize(shards [][]byte) int {
for _, shard := range shards {
if len(shard) != 0 {
return len(shard)
}
}
return 0
} | [
"func",
"shardSize",
"(",
"shards",
"[",
"]",
"[",
"]",
"byte",
")",
"int",
"{",
"for",
"_",
",",
"shard",
":=",
"range",
"shards",
"{",
"if",
"len",
"(",
"shard",
")",
"!=",
"0",
"{",
"return",
"len",
"(",
"shard",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}"
] | // shardSize return the size of a single shard.
// The first non-zero size is returned,
// or 0 if all shards are size 0. | [
"shardSize",
"return",
"the",
"size",
"of",
"a",
"single",
"shard",
".",
"The",
"first",
"non",
"-",
"zero",
"size",
"is",
"returned",
"or",
"0",
"if",
"all",
"shards",
"are",
"size",
"0",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L599-L606 |
150,528 | klauspost/reedsolomon | reedsolomon.go | Split | func (r reedSolomon) Split(data []byte) ([][]byte, error) {
if len(data) == 0 {
return nil, ErrShortData
}
// Calculate number of bytes per data shard.
perShard := (len(data) + r.DataShards - 1) / r.DataShards
if cap(data) > len(data) {
data = data[:cap(data)]
}
// Only allocate memory if necessary
if len(data) < (r.Shards * perShard) {
// Pad data to r.Shards*perShard.
padding := make([]byte, (r.Shards*perShard)-len(data))
data = append(data, padding...)
}
// Split into equal-length shards.
dst := make([][]byte, r.Shards)
for i := range dst {
dst[i] = data[:perShard]
data = data[perShard:]
}
return dst, nil
} | go | func (r reedSolomon) Split(data []byte) ([][]byte, error) {
if len(data) == 0 {
return nil, ErrShortData
}
// Calculate number of bytes per data shard.
perShard := (len(data) + r.DataShards - 1) / r.DataShards
if cap(data) > len(data) {
data = data[:cap(data)]
}
// Only allocate memory if necessary
if len(data) < (r.Shards * perShard) {
// Pad data to r.Shards*perShard.
padding := make([]byte, (r.Shards*perShard)-len(data))
data = append(data, padding...)
}
// Split into equal-length shards.
dst := make([][]byte, r.Shards)
for i := range dst {
dst[i] = data[:perShard]
data = data[perShard:]
}
return dst, nil
} | [
"func",
"(",
"r",
"reedSolomon",
")",
"Split",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"len",
"(",
"data",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"ErrShortData",
"\n",
"}",
"\n",
"// Calculate number of bytes per data shard.",
"perShard",
":=",
"(",
"len",
"(",
"data",
")",
"+",
"r",
".",
"DataShards",
"-",
"1",
")",
"/",
"r",
".",
"DataShards",
"\n\n",
"if",
"cap",
"(",
"data",
")",
">",
"len",
"(",
"data",
")",
"{",
"data",
"=",
"data",
"[",
":",
"cap",
"(",
"data",
")",
"]",
"\n",
"}",
"\n\n",
"// Only allocate memory if necessary",
"if",
"len",
"(",
"data",
")",
"<",
"(",
"r",
".",
"Shards",
"*",
"perShard",
")",
"{",
"// Pad data to r.Shards*perShard.",
"padding",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"(",
"r",
".",
"Shards",
"*",
"perShard",
")",
"-",
"len",
"(",
"data",
")",
")",
"\n",
"data",
"=",
"append",
"(",
"data",
",",
"padding",
"...",
")",
"\n",
"}",
"\n\n",
"// Split into equal-length shards.",
"dst",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"byte",
",",
"r",
".",
"Shards",
")",
"\n",
"for",
"i",
":=",
"range",
"dst",
"{",
"dst",
"[",
"i",
"]",
"=",
"data",
"[",
":",
"perShard",
"]",
"\n",
"data",
"=",
"data",
"[",
"perShard",
":",
"]",
"\n",
"}",
"\n\n",
"return",
"dst",
",",
"nil",
"\n",
"}"
] | // Split a data slice into the number of shards given to the encoder,
// and create empty parity shards if necessary.
//
// The data will be split into equally sized shards.
// If the data size isn't divisible by the number of shards,
// the last shard will contain extra zeros.
//
// There must be at least 1 byte otherwise ErrShortData will be
// returned.
//
// The data will not be copied, except for the last shard, so you
// should not modify the data of the input slice afterwards. | [
"Split",
"a",
"data",
"slice",
"into",
"the",
"number",
"of",
"shards",
"given",
"to",
"the",
"encoder",
"and",
"create",
"empty",
"parity",
"shards",
"if",
"necessary",
".",
"The",
"data",
"will",
"be",
"split",
"into",
"equally",
"sized",
"shards",
".",
"If",
"the",
"data",
"size",
"isn",
"t",
"divisible",
"by",
"the",
"number",
"of",
"shards",
"the",
"last",
"shard",
"will",
"contain",
"extra",
"zeros",
".",
"There",
"must",
"be",
"at",
"least",
"1",
"byte",
"otherwise",
"ErrShortData",
"will",
"be",
"returned",
".",
"The",
"data",
"will",
"not",
"be",
"copied",
"except",
"for",
"the",
"last",
"shard",
"so",
"you",
"should",
"not",
"modify",
"the",
"data",
"of",
"the",
"input",
"slice",
"afterwards",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L809-L835 |
150,529 | klauspost/reedsolomon | reedsolomon.go | Join | func (r reedSolomon) Join(dst io.Writer, shards [][]byte, outSize int) error {
// Do we have enough shards?
if len(shards) < r.DataShards {
return ErrTooFewShards
}
shards = shards[:r.DataShards]
// Do we have enough data?
size := 0
for _, shard := range shards {
if shard == nil {
return ErrReconstructRequired
}
size += len(shard)
// Do we have enough data already?
if size >= outSize {
break
}
}
if size < outSize {
return ErrShortData
}
// Copy data to dst
write := outSize
for _, shard := range shards {
if write < len(shard) {
_, err := dst.Write(shard[:write])
return err
}
n, err := dst.Write(shard)
if err != nil {
return err
}
write -= n
}
return nil
} | go | func (r reedSolomon) Join(dst io.Writer, shards [][]byte, outSize int) error {
// Do we have enough shards?
if len(shards) < r.DataShards {
return ErrTooFewShards
}
shards = shards[:r.DataShards]
// Do we have enough data?
size := 0
for _, shard := range shards {
if shard == nil {
return ErrReconstructRequired
}
size += len(shard)
// Do we have enough data already?
if size >= outSize {
break
}
}
if size < outSize {
return ErrShortData
}
// Copy data to dst
write := outSize
for _, shard := range shards {
if write < len(shard) {
_, err := dst.Write(shard[:write])
return err
}
n, err := dst.Write(shard)
if err != nil {
return err
}
write -= n
}
return nil
} | [
"func",
"(",
"r",
"reedSolomon",
")",
"Join",
"(",
"dst",
"io",
".",
"Writer",
",",
"shards",
"[",
"]",
"[",
"]",
"byte",
",",
"outSize",
"int",
")",
"error",
"{",
"// Do we have enough shards?",
"if",
"len",
"(",
"shards",
")",
"<",
"r",
".",
"DataShards",
"{",
"return",
"ErrTooFewShards",
"\n",
"}",
"\n",
"shards",
"=",
"shards",
"[",
":",
"r",
".",
"DataShards",
"]",
"\n\n",
"// Do we have enough data?",
"size",
":=",
"0",
"\n",
"for",
"_",
",",
"shard",
":=",
"range",
"shards",
"{",
"if",
"shard",
"==",
"nil",
"{",
"return",
"ErrReconstructRequired",
"\n",
"}",
"\n",
"size",
"+=",
"len",
"(",
"shard",
")",
"\n\n",
"// Do we have enough data already?",
"if",
"size",
">=",
"outSize",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"size",
"<",
"outSize",
"{",
"return",
"ErrShortData",
"\n",
"}",
"\n\n",
"// Copy data to dst",
"write",
":=",
"outSize",
"\n",
"for",
"_",
",",
"shard",
":=",
"range",
"shards",
"{",
"if",
"write",
"<",
"len",
"(",
"shard",
")",
"{",
"_",
",",
"err",
":=",
"dst",
".",
"Write",
"(",
"shard",
"[",
":",
"write",
"]",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"n",
",",
"err",
":=",
"dst",
".",
"Write",
"(",
"shard",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"write",
"-=",
"n",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Join the shards and write the data segment to dst.
//
// Only the data shards are considered.
// You must supply the exact output size you want.
//
// If there are to few shards given, ErrTooFewShards will be returned.
// If the total data size is less than outSize, ErrShortData will be returned.
// If one or more required data shards are nil, ErrReconstructRequired will be returned. | [
"Join",
"the",
"shards",
"and",
"write",
"the",
"data",
"segment",
"to",
"dst",
".",
"Only",
"the",
"data",
"shards",
"are",
"considered",
".",
"You",
"must",
"supply",
"the",
"exact",
"output",
"size",
"you",
"want",
".",
"If",
"there",
"are",
"to",
"few",
"shards",
"given",
"ErrTooFewShards",
"will",
"be",
"returned",
".",
"If",
"the",
"total",
"data",
"size",
"is",
"less",
"than",
"outSize",
"ErrShortData",
"will",
"be",
"returned",
".",
"If",
"one",
"or",
"more",
"required",
"data",
"shards",
"are",
"nil",
"ErrReconstructRequired",
"will",
"be",
"returned",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L849-L887 |
150,530 | klauspost/reedsolomon | gentables.go | generateExpTable | func generateExpTable() []byte {
result := make([]byte, fieldSize*2-2)
for i := 1; i < fieldSize; i++ {
log := logTable[i]
result[log] = byte(i)
result[log+fieldSize-1] = byte(i)
}
return result
} | go | func generateExpTable() []byte {
result := make([]byte, fieldSize*2-2)
for i := 1; i < fieldSize; i++ {
log := logTable[i]
result[log] = byte(i)
result[log+fieldSize-1] = byte(i)
}
return result
} | [
"func",
"generateExpTable",
"(",
")",
"[",
"]",
"byte",
"{",
"result",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"fieldSize",
"*",
"2",
"-",
"2",
")",
"\n",
"for",
"i",
":=",
"1",
";",
"i",
"<",
"fieldSize",
";",
"i",
"++",
"{",
"log",
":=",
"logTable",
"[",
"i",
"]",
"\n",
"result",
"[",
"log",
"]",
"=",
"byte",
"(",
"i",
")",
"\n",
"result",
"[",
"log",
"+",
"fieldSize",
"-",
"1",
"]",
"=",
"byte",
"(",
"i",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | /**
* Generates the inverse log table.
*/ | [
"Generates",
"the",
"inverse",
"log",
"table",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/gentables.go#L72-L80 |
150,531 | klauspost/reedsolomon | matrix.go | newMatrix | func newMatrix(rows, cols int) (matrix, error) {
if rows <= 0 {
return nil, errInvalidRowSize
}
if cols <= 0 {
return nil, errInvalidColSize
}
m := matrix(make([][]byte, rows))
for i := range m {
m[i] = make([]byte, cols)
}
return m, nil
} | go | func newMatrix(rows, cols int) (matrix, error) {
if rows <= 0 {
return nil, errInvalidRowSize
}
if cols <= 0 {
return nil, errInvalidColSize
}
m := matrix(make([][]byte, rows))
for i := range m {
m[i] = make([]byte, cols)
}
return m, nil
} | [
"func",
"newMatrix",
"(",
"rows",
",",
"cols",
"int",
")",
"(",
"matrix",
",",
"error",
")",
"{",
"if",
"rows",
"<=",
"0",
"{",
"return",
"nil",
",",
"errInvalidRowSize",
"\n",
"}",
"\n",
"if",
"cols",
"<=",
"0",
"{",
"return",
"nil",
",",
"errInvalidColSize",
"\n",
"}",
"\n\n",
"m",
":=",
"matrix",
"(",
"make",
"(",
"[",
"]",
"[",
"]",
"byte",
",",
"rows",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"m",
"{",
"m",
"[",
"i",
"]",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"cols",
")",
"\n",
"}",
"\n",
"return",
"m",
",",
"nil",
"\n",
"}"
] | // newMatrix returns a matrix of zeros. | [
"newMatrix",
"returns",
"a",
"matrix",
"of",
"zeros",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/matrix.go#L21-L34 |
150,532 | klauspost/reedsolomon | matrix.go | newMatrixData | func newMatrixData(data [][]byte) (matrix, error) {
m := matrix(data)
err := m.Check()
if err != nil {
return nil, err
}
return m, nil
} | go | func newMatrixData(data [][]byte) (matrix, error) {
m := matrix(data)
err := m.Check()
if err != nil {
return nil, err
}
return m, nil
} | [
"func",
"newMatrixData",
"(",
"data",
"[",
"]",
"[",
"]",
"byte",
")",
"(",
"matrix",
",",
"error",
")",
"{",
"m",
":=",
"matrix",
"(",
"data",
")",
"\n",
"err",
":=",
"m",
".",
"Check",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"m",
",",
"nil",
"\n",
"}"
] | // NewMatrixData initializes a matrix with the given row-major data.
// Note that data is not copied from input. | [
"NewMatrixData",
"initializes",
"a",
"matrix",
"with",
"the",
"given",
"row",
"-",
"major",
"data",
".",
"Note",
"that",
"data",
"is",
"not",
"copied",
"from",
"input",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/matrix.go#L38-L45 |
150,533 | klauspost/reedsolomon | matrix.go | identityMatrix | func identityMatrix(size int) (matrix, error) {
m, err := newMatrix(size, size)
if err != nil {
return nil, err
}
for i := range m {
m[i][i] = 1
}
return m, nil
} | go | func identityMatrix(size int) (matrix, error) {
m, err := newMatrix(size, size)
if err != nil {
return nil, err
}
for i := range m {
m[i][i] = 1
}
return m, nil
} | [
"func",
"identityMatrix",
"(",
"size",
"int",
")",
"(",
"matrix",
",",
"error",
")",
"{",
"m",
",",
"err",
":=",
"newMatrix",
"(",
"size",
",",
"size",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"m",
"{",
"m",
"[",
"i",
"]",
"[",
"i",
"]",
"=",
"1",
"\n",
"}",
"\n",
"return",
"m",
",",
"nil",
"\n",
"}"
] | // IdentityMatrix returns an identity matrix of the given size. | [
"IdentityMatrix",
"returns",
"an",
"identity",
"matrix",
"of",
"the",
"given",
"size",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/matrix.go#L48-L57 |
150,534 | klauspost/reedsolomon | matrix.go | Augment | func (m matrix) Augment(right matrix) (matrix, error) {
if len(m) != len(right) {
return nil, errMatrixSize
}
result, _ := newMatrix(len(m), len(m[0])+len(right[0]))
for r, row := range m {
for c := range row {
result[r][c] = m[r][c]
}
cols := len(m[0])
for c := range right[0] {
result[r][cols+c] = right[r][c]
}
}
return result, nil
} | go | func (m matrix) Augment(right matrix) (matrix, error) {
if len(m) != len(right) {
return nil, errMatrixSize
}
result, _ := newMatrix(len(m), len(m[0])+len(right[0]))
for r, row := range m {
for c := range row {
result[r][c] = m[r][c]
}
cols := len(m[0])
for c := range right[0] {
result[r][cols+c] = right[r][c]
}
}
return result, nil
} | [
"func",
"(",
"m",
"matrix",
")",
"Augment",
"(",
"right",
"matrix",
")",
"(",
"matrix",
",",
"error",
")",
"{",
"if",
"len",
"(",
"m",
")",
"!=",
"len",
"(",
"right",
")",
"{",
"return",
"nil",
",",
"errMatrixSize",
"\n",
"}",
"\n\n",
"result",
",",
"_",
":=",
"newMatrix",
"(",
"len",
"(",
"m",
")",
",",
"len",
"(",
"m",
"[",
"0",
"]",
")",
"+",
"len",
"(",
"right",
"[",
"0",
"]",
")",
")",
"\n",
"for",
"r",
",",
"row",
":=",
"range",
"m",
"{",
"for",
"c",
":=",
"range",
"row",
"{",
"result",
"[",
"r",
"]",
"[",
"c",
"]",
"=",
"m",
"[",
"r",
"]",
"[",
"c",
"]",
"\n",
"}",
"\n",
"cols",
":=",
"len",
"(",
"m",
"[",
"0",
"]",
")",
"\n",
"for",
"c",
":=",
"range",
"right",
"[",
"0",
"]",
"{",
"result",
"[",
"r",
"]",
"[",
"cols",
"+",
"c",
"]",
"=",
"right",
"[",
"r",
"]",
"[",
"c",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // Augment returns the concatenation of this matrix and the matrix on the right. | [
"Augment",
"returns",
"the",
"concatenation",
"of",
"this",
"matrix",
"and",
"the",
"matrix",
"on",
"the",
"right",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/matrix.go#L121-L137 |
150,535 | klauspost/reedsolomon | matrix.go | SubMatrix | func (m matrix) SubMatrix(rmin, cmin, rmax, cmax int) (matrix, error) {
result, err := newMatrix(rmax-rmin, cmax-cmin)
if err != nil {
return nil, err
}
// OPTME: If used heavily, use copy function to copy slice
for r := rmin; r < rmax; r++ {
for c := cmin; c < cmax; c++ {
result[r-rmin][c-cmin] = m[r][c]
}
}
return result, nil
} | go | func (m matrix) SubMatrix(rmin, cmin, rmax, cmax int) (matrix, error) {
result, err := newMatrix(rmax-rmin, cmax-cmin)
if err != nil {
return nil, err
}
// OPTME: If used heavily, use copy function to copy slice
for r := rmin; r < rmax; r++ {
for c := cmin; c < cmax; c++ {
result[r-rmin][c-cmin] = m[r][c]
}
}
return result, nil
} | [
"func",
"(",
"m",
"matrix",
")",
"SubMatrix",
"(",
"rmin",
",",
"cmin",
",",
"rmax",
",",
"cmax",
"int",
")",
"(",
"matrix",
",",
"error",
")",
"{",
"result",
",",
"err",
":=",
"newMatrix",
"(",
"rmax",
"-",
"rmin",
",",
"cmax",
"-",
"cmin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// OPTME: If used heavily, use copy function to copy slice",
"for",
"r",
":=",
"rmin",
";",
"r",
"<",
"rmax",
";",
"r",
"++",
"{",
"for",
"c",
":=",
"cmin",
";",
"c",
"<",
"cmax",
";",
"c",
"++",
"{",
"result",
"[",
"r",
"-",
"rmin",
"]",
"[",
"c",
"-",
"cmin",
"]",
"=",
"m",
"[",
"r",
"]",
"[",
"c",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // SubMatrix returns a part of this matrix. Data is copied. | [
"SubMatrix",
"returns",
"a",
"part",
"of",
"this",
"matrix",
".",
"Data",
"is",
"copied",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/matrix.go#L155-L167 |
150,536 | klauspost/reedsolomon | matrix.go | SwapRows | func (m matrix) SwapRows(r1, r2 int) error {
if r1 < 0 || len(m) <= r1 || r2 < 0 || len(m) <= r2 {
return errInvalidRowSize
}
m[r2], m[r1] = m[r1], m[r2]
return nil
} | go | func (m matrix) SwapRows(r1, r2 int) error {
if r1 < 0 || len(m) <= r1 || r2 < 0 || len(m) <= r2 {
return errInvalidRowSize
}
m[r2], m[r1] = m[r1], m[r2]
return nil
} | [
"func",
"(",
"m",
"matrix",
")",
"SwapRows",
"(",
"r1",
",",
"r2",
"int",
")",
"error",
"{",
"if",
"r1",
"<",
"0",
"||",
"len",
"(",
"m",
")",
"<=",
"r1",
"||",
"r2",
"<",
"0",
"||",
"len",
"(",
"m",
")",
"<=",
"r2",
"{",
"return",
"errInvalidRowSize",
"\n",
"}",
"\n",
"m",
"[",
"r2",
"]",
",",
"m",
"[",
"r1",
"]",
"=",
"m",
"[",
"r1",
"]",
",",
"m",
"[",
"r2",
"]",
"\n",
"return",
"nil",
"\n",
"}"
] | // SwapRows Exchanges two rows in the matrix. | [
"SwapRows",
"Exchanges",
"two",
"rows",
"in",
"the",
"matrix",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/matrix.go#L170-L176 |
150,537 | klauspost/reedsolomon | matrix.go | Invert | func (m matrix) Invert() (matrix, error) {
if !m.IsSquare() {
return nil, errNotSquare
}
size := len(m)
work, _ := identityMatrix(size)
work, _ = m.Augment(work)
err := work.gaussianElimination()
if err != nil {
return nil, err
}
return work.SubMatrix(0, size, size, size*2)
} | go | func (m matrix) Invert() (matrix, error) {
if !m.IsSquare() {
return nil, errNotSquare
}
size := len(m)
work, _ := identityMatrix(size)
work, _ = m.Augment(work)
err := work.gaussianElimination()
if err != nil {
return nil, err
}
return work.SubMatrix(0, size, size, size*2)
} | [
"func",
"(",
"m",
"matrix",
")",
"Invert",
"(",
")",
"(",
"matrix",
",",
"error",
")",
"{",
"if",
"!",
"m",
".",
"IsSquare",
"(",
")",
"{",
"return",
"nil",
",",
"errNotSquare",
"\n",
"}",
"\n\n",
"size",
":=",
"len",
"(",
"m",
")",
"\n",
"work",
",",
"_",
":=",
"identityMatrix",
"(",
"size",
")",
"\n",
"work",
",",
"_",
"=",
"m",
".",
"Augment",
"(",
"work",
")",
"\n\n",
"err",
":=",
"work",
".",
"gaussianElimination",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"work",
".",
"SubMatrix",
"(",
"0",
",",
"size",
",",
"size",
",",
"size",
"*",
"2",
")",
"\n",
"}"
] | // Invert returns the inverse of this matrix.
// Returns ErrSingular when the matrix is singular and doesn't have an inverse.
// The matrix must be square, otherwise ErrNotSquare is returned. | [
"Invert",
"returns",
"the",
"inverse",
"of",
"this",
"matrix",
".",
"Returns",
"ErrSingular",
"when",
"the",
"matrix",
"is",
"singular",
"and",
"doesn",
"t",
"have",
"an",
"inverse",
".",
"The",
"matrix",
"must",
"be",
"square",
"otherwise",
"ErrNotSquare",
"is",
"returned",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/matrix.go#L193-L208 |
150,538 | klauspost/reedsolomon | matrix.go | vandermonde | func vandermonde(rows, cols int) (matrix, error) {
result, err := newMatrix(rows, cols)
if err != nil {
return nil, err
}
for r, row := range result {
for c := range row {
result[r][c] = galExp(byte(r), c)
}
}
return result, nil
} | go | func vandermonde(rows, cols int) (matrix, error) {
result, err := newMatrix(rows, cols)
if err != nil {
return nil, err
}
for r, row := range result {
for c := range row {
result[r][c] = galExp(byte(r), c)
}
}
return result, nil
} | [
"func",
"vandermonde",
"(",
"rows",
",",
"cols",
"int",
")",
"(",
"matrix",
",",
"error",
")",
"{",
"result",
",",
"err",
":=",
"newMatrix",
"(",
"rows",
",",
"cols",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"r",
",",
"row",
":=",
"range",
"result",
"{",
"for",
"c",
":=",
"range",
"row",
"{",
"result",
"[",
"r",
"]",
"[",
"c",
"]",
"=",
"galExp",
"(",
"byte",
"(",
"r",
")",
",",
"c",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // Create a Vandermonde matrix, which is guaranteed to have the
// property that any subset of rows that forms a square matrix
// is invertible. | [
"Create",
"a",
"Vandermonde",
"matrix",
"which",
"is",
"guaranteed",
"to",
"have",
"the",
"property",
"that",
"any",
"subset",
"of",
"rows",
"that",
"forms",
"a",
"square",
"matrix",
"is",
"invertible",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/matrix.go#L268-L279 |
150,539 | klauspost/reedsolomon | inversion_tree.go | newInversionTree | func newInversionTree(dataShards, parityShards int) inversionTree {
identity, _ := identityMatrix(dataShards)
root := inversionNode{
matrix: identity,
children: make([]*inversionNode, dataShards+parityShards),
}
return inversionTree{
mutex: &sync.RWMutex{},
root: root,
}
} | go | func newInversionTree(dataShards, parityShards int) inversionTree {
identity, _ := identityMatrix(dataShards)
root := inversionNode{
matrix: identity,
children: make([]*inversionNode, dataShards+parityShards),
}
return inversionTree{
mutex: &sync.RWMutex{},
root: root,
}
} | [
"func",
"newInversionTree",
"(",
"dataShards",
",",
"parityShards",
"int",
")",
"inversionTree",
"{",
"identity",
",",
"_",
":=",
"identityMatrix",
"(",
"dataShards",
")",
"\n",
"root",
":=",
"inversionNode",
"{",
"matrix",
":",
"identity",
",",
"children",
":",
"make",
"(",
"[",
"]",
"*",
"inversionNode",
",",
"dataShards",
"+",
"parityShards",
")",
",",
"}",
"\n",
"return",
"inversionTree",
"{",
"mutex",
":",
"&",
"sync",
".",
"RWMutex",
"{",
"}",
",",
"root",
":",
"root",
",",
"}",
"\n",
"}"
] | // newInversionTree initializes a tree for storing inverted matrices.
// Note that the root node is the identity matrix as it implies
// there were no errors with the original data. | [
"newInversionTree",
"initializes",
"a",
"tree",
"for",
"storing",
"inverted",
"matrices",
".",
"Note",
"that",
"the",
"root",
"node",
"is",
"the",
"identity",
"matrix",
"as",
"it",
"implies",
"there",
"were",
"no",
"errors",
"with",
"the",
"original",
"data",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/inversion_tree.go#L29-L39 |
150,540 | klauspost/reedsolomon | inversion_tree.go | GetInvertedMatrix | func (t inversionTree) GetInvertedMatrix(invalidIndices []int) matrix {
// Lock the tree for reading before accessing the tree.
t.mutex.RLock()
defer t.mutex.RUnlock()
// If no invalid indices were give we should return the root
// identity matrix.
if len(invalidIndices) == 0 {
return t.root.matrix
}
// Recursively search for the inverted matrix in the tree, passing in
// 0 as the parent index as we start at the root of the tree.
return t.root.getInvertedMatrix(invalidIndices, 0)
} | go | func (t inversionTree) GetInvertedMatrix(invalidIndices []int) matrix {
// Lock the tree for reading before accessing the tree.
t.mutex.RLock()
defer t.mutex.RUnlock()
// If no invalid indices were give we should return the root
// identity matrix.
if len(invalidIndices) == 0 {
return t.root.matrix
}
// Recursively search for the inverted matrix in the tree, passing in
// 0 as the parent index as we start at the root of the tree.
return t.root.getInvertedMatrix(invalidIndices, 0)
} | [
"func",
"(",
"t",
"inversionTree",
")",
"GetInvertedMatrix",
"(",
"invalidIndices",
"[",
"]",
"int",
")",
"matrix",
"{",
"// Lock the tree for reading before accessing the tree.",
"t",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"// If no invalid indices were give we should return the root",
"// identity matrix.",
"if",
"len",
"(",
"invalidIndices",
")",
"==",
"0",
"{",
"return",
"t",
".",
"root",
".",
"matrix",
"\n",
"}",
"\n\n",
"// Recursively search for the inverted matrix in the tree, passing in",
"// 0 as the parent index as we start at the root of the tree.",
"return",
"t",
".",
"root",
".",
"getInvertedMatrix",
"(",
"invalidIndices",
",",
"0",
")",
"\n",
"}"
] | // GetInvertedMatrix returns the cached inverted matrix or nil if it
// is not found in the tree keyed on the indices of invalid rows. | [
"GetInvertedMatrix",
"returns",
"the",
"cached",
"inverted",
"matrix",
"or",
"nil",
"if",
"it",
"is",
"not",
"found",
"in",
"the",
"tree",
"keyed",
"on",
"the",
"indices",
"of",
"invalid",
"rows",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/inversion_tree.go#L43-L57 |
150,541 | klauspost/reedsolomon | inversion_tree.go | InsertInvertedMatrix | func (t inversionTree) InsertInvertedMatrix(invalidIndices []int, matrix matrix, shards int) error {
// If no invalid indices were given then we are done because the
// root node is already set with the identity matrix.
if len(invalidIndices) == 0 {
return errAlreadySet
}
if !matrix.IsSquare() {
return errNotSquare
}
// Lock the tree for writing and reading before accessing the tree.
t.mutex.Lock()
defer t.mutex.Unlock()
// Recursively create nodes for the inverted matrix in the tree until
// we reach the node to insert the matrix to. We start by passing in
// 0 as the parent index as we start at the root of the tree.
t.root.insertInvertedMatrix(invalidIndices, matrix, shards, 0)
return nil
} | go | func (t inversionTree) InsertInvertedMatrix(invalidIndices []int, matrix matrix, shards int) error {
// If no invalid indices were given then we are done because the
// root node is already set with the identity matrix.
if len(invalidIndices) == 0 {
return errAlreadySet
}
if !matrix.IsSquare() {
return errNotSquare
}
// Lock the tree for writing and reading before accessing the tree.
t.mutex.Lock()
defer t.mutex.Unlock()
// Recursively create nodes for the inverted matrix in the tree until
// we reach the node to insert the matrix to. We start by passing in
// 0 as the parent index as we start at the root of the tree.
t.root.insertInvertedMatrix(invalidIndices, matrix, shards, 0)
return nil
} | [
"func",
"(",
"t",
"inversionTree",
")",
"InsertInvertedMatrix",
"(",
"invalidIndices",
"[",
"]",
"int",
",",
"matrix",
"matrix",
",",
"shards",
"int",
")",
"error",
"{",
"// If no invalid indices were given then we are done because the",
"// root node is already set with the identity matrix.",
"if",
"len",
"(",
"invalidIndices",
")",
"==",
"0",
"{",
"return",
"errAlreadySet",
"\n",
"}",
"\n\n",
"if",
"!",
"matrix",
".",
"IsSquare",
"(",
")",
"{",
"return",
"errNotSquare",
"\n",
"}",
"\n\n",
"// Lock the tree for writing and reading before accessing the tree.",
"t",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// Recursively create nodes for the inverted matrix in the tree until",
"// we reach the node to insert the matrix to. We start by passing in",
"// 0 as the parent index as we start at the root of the tree.",
"t",
".",
"root",
".",
"insertInvertedMatrix",
"(",
"invalidIndices",
",",
"matrix",
",",
"shards",
",",
"0",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // InsertInvertedMatrix inserts a new inverted matrix into the tree
// keyed by the indices of invalid rows. The total number of shards
// is required for creating the proper length lists of child nodes for
// each node. | [
"InsertInvertedMatrix",
"inserts",
"a",
"new",
"inverted",
"matrix",
"into",
"the",
"tree",
"keyed",
"by",
"the",
"indices",
"of",
"invalid",
"rows",
".",
"The",
"total",
"number",
"of",
"shards",
"is",
"required",
"for",
"creating",
"the",
"proper",
"length",
"lists",
"of",
"child",
"nodes",
"for",
"each",
"node",
"."
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/inversion_tree.go#L66-L87 |
150,542 | klauspost/reedsolomon | galoisAvx512_amd64.go | setupMatrix82 | func setupMatrix82(matrixRows [][]byte, inputOffset, outputOffset int, matrix *[matrixSize82]byte) {
offset := 0
for c := inputOffset; c < inputOffset+dimIn; c++ {
for iRow := outputOffset; iRow < outputOffset+dimOut82; iRow++ {
if c < len(matrixRows[iRow]) {
coeff := matrixRows[iRow][c]
copy(matrix[offset*32:], mulTableLow[coeff][:])
copy(matrix[offset*32+16:], mulTableHigh[coeff][:])
} else {
// coefficients not used for this input shard (so null out)
v := matrix[offset*32 : offset*32+32]
for i := range v {
v[i] = 0
}
}
offset += dimIn
if offset >= dimIn*dimOut82 {
offset -= dimIn*dimOut82 - 1
}
}
}
} | go | func setupMatrix82(matrixRows [][]byte, inputOffset, outputOffset int, matrix *[matrixSize82]byte) {
offset := 0
for c := inputOffset; c < inputOffset+dimIn; c++ {
for iRow := outputOffset; iRow < outputOffset+dimOut82; iRow++ {
if c < len(matrixRows[iRow]) {
coeff := matrixRows[iRow][c]
copy(matrix[offset*32:], mulTableLow[coeff][:])
copy(matrix[offset*32+16:], mulTableHigh[coeff][:])
} else {
// coefficients not used for this input shard (so null out)
v := matrix[offset*32 : offset*32+32]
for i := range v {
v[i] = 0
}
}
offset += dimIn
if offset >= dimIn*dimOut82 {
offset -= dimIn*dimOut82 - 1
}
}
}
} | [
"func",
"setupMatrix82",
"(",
"matrixRows",
"[",
"]",
"[",
"]",
"byte",
",",
"inputOffset",
",",
"outputOffset",
"int",
",",
"matrix",
"*",
"[",
"matrixSize82",
"]",
"byte",
")",
"{",
"offset",
":=",
"0",
"\n",
"for",
"c",
":=",
"inputOffset",
";",
"c",
"<",
"inputOffset",
"+",
"dimIn",
";",
"c",
"++",
"{",
"for",
"iRow",
":=",
"outputOffset",
";",
"iRow",
"<",
"outputOffset",
"+",
"dimOut82",
";",
"iRow",
"++",
"{",
"if",
"c",
"<",
"len",
"(",
"matrixRows",
"[",
"iRow",
"]",
")",
"{",
"coeff",
":=",
"matrixRows",
"[",
"iRow",
"]",
"[",
"c",
"]",
"\n",
"copy",
"(",
"matrix",
"[",
"offset",
"*",
"32",
":",
"]",
",",
"mulTableLow",
"[",
"coeff",
"]",
"[",
":",
"]",
")",
"\n",
"copy",
"(",
"matrix",
"[",
"offset",
"*",
"32",
"+",
"16",
":",
"]",
",",
"mulTableHigh",
"[",
"coeff",
"]",
"[",
":",
"]",
")",
"\n",
"}",
"else",
"{",
"// coefficients not used for this input shard (so null out)",
"v",
":=",
"matrix",
"[",
"offset",
"*",
"32",
":",
"offset",
"*",
"32",
"+",
"32",
"]",
"\n",
"for",
"i",
":=",
"range",
"v",
"{",
"v",
"[",
"i",
"]",
"=",
"0",
"\n",
"}",
"\n",
"}",
"\n",
"offset",
"+=",
"dimIn",
"\n",
"if",
"offset",
">=",
"dimIn",
"*",
"dimOut82",
"{",
"offset",
"-=",
"dimIn",
"*",
"dimOut82",
"-",
"1",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Construct block of matrix coefficients for 2 outputs rows in parallel | [
"Construct",
"block",
"of",
"matrix",
"coefficients",
"for",
"2",
"outputs",
"rows",
"in",
"parallel"
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/galoisAvx512_amd64.go#L25-L46 |
150,543 | klauspost/reedsolomon | galoisAvx512_amd64.go | setupMatrix84 | func setupMatrix84(matrixRows [][]byte, inputOffset, outputOffset int, matrix *[matrixSize84]byte) {
offset := 0
for c := inputOffset; c < inputOffset+dimIn; c++ {
for iRow := outputOffset; iRow < outputOffset+dimOut84; iRow++ {
if c < len(matrixRows[iRow]) {
coeff := matrixRows[iRow][c]
copy(matrix[offset*32:], mulTableLow[coeff][:])
copy(matrix[offset*32+16:], mulTableHigh[coeff][:])
} else {
// coefficients not used for this input shard (so null out)
v := matrix[offset*32 : offset*32+32]
for i := range v {
v[i] = 0
}
}
offset += dimIn
if offset >= dimIn*dimOut84 {
offset -= dimIn*dimOut84 - 1
}
}
}
} | go | func setupMatrix84(matrixRows [][]byte, inputOffset, outputOffset int, matrix *[matrixSize84]byte) {
offset := 0
for c := inputOffset; c < inputOffset+dimIn; c++ {
for iRow := outputOffset; iRow < outputOffset+dimOut84; iRow++ {
if c < len(matrixRows[iRow]) {
coeff := matrixRows[iRow][c]
copy(matrix[offset*32:], mulTableLow[coeff][:])
copy(matrix[offset*32+16:], mulTableHigh[coeff][:])
} else {
// coefficients not used for this input shard (so null out)
v := matrix[offset*32 : offset*32+32]
for i := range v {
v[i] = 0
}
}
offset += dimIn
if offset >= dimIn*dimOut84 {
offset -= dimIn*dimOut84 - 1
}
}
}
} | [
"func",
"setupMatrix84",
"(",
"matrixRows",
"[",
"]",
"[",
"]",
"byte",
",",
"inputOffset",
",",
"outputOffset",
"int",
",",
"matrix",
"*",
"[",
"matrixSize84",
"]",
"byte",
")",
"{",
"offset",
":=",
"0",
"\n",
"for",
"c",
":=",
"inputOffset",
";",
"c",
"<",
"inputOffset",
"+",
"dimIn",
";",
"c",
"++",
"{",
"for",
"iRow",
":=",
"outputOffset",
";",
"iRow",
"<",
"outputOffset",
"+",
"dimOut84",
";",
"iRow",
"++",
"{",
"if",
"c",
"<",
"len",
"(",
"matrixRows",
"[",
"iRow",
"]",
")",
"{",
"coeff",
":=",
"matrixRows",
"[",
"iRow",
"]",
"[",
"c",
"]",
"\n",
"copy",
"(",
"matrix",
"[",
"offset",
"*",
"32",
":",
"]",
",",
"mulTableLow",
"[",
"coeff",
"]",
"[",
":",
"]",
")",
"\n",
"copy",
"(",
"matrix",
"[",
"offset",
"*",
"32",
"+",
"16",
":",
"]",
",",
"mulTableHigh",
"[",
"coeff",
"]",
"[",
":",
"]",
")",
"\n",
"}",
"else",
"{",
"// coefficients not used for this input shard (so null out)",
"v",
":=",
"matrix",
"[",
"offset",
"*",
"32",
":",
"offset",
"*",
"32",
"+",
"32",
"]",
"\n",
"for",
"i",
":=",
"range",
"v",
"{",
"v",
"[",
"i",
"]",
"=",
"0",
"\n",
"}",
"\n",
"}",
"\n",
"offset",
"+=",
"dimIn",
"\n",
"if",
"offset",
">=",
"dimIn",
"*",
"dimOut84",
"{",
"offset",
"-=",
"dimIn",
"*",
"dimOut84",
"-",
"1",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Construct block of matrix coefficients for 4 outputs rows in parallel | [
"Construct",
"block",
"of",
"matrix",
"coefficients",
"for",
"4",
"outputs",
"rows",
"in",
"parallel"
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/galoisAvx512_amd64.go#L49-L70 |
150,544 | klauspost/reedsolomon | galoisAvx512_amd64.go | galMulAVX512Parallel82 | func galMulAVX512Parallel82(in, out [][]byte, matrixRows [][]byte, inputOffset, outputOffset int) {
done := len(in[0])
if done == 0 {
return
}
inputEnd := inputOffset + dimIn
if inputEnd > len(in) {
inputEnd = len(in)
}
outputEnd := outputOffset + dimOut82
if outputEnd > len(out) {
outputEnd = len(out)
}
matrix82 := [matrixSize82]byte{}
setupMatrix82(matrixRows, inputOffset, outputOffset, &matrix82)
addTo := inputOffset != 0 // Except for the first input column, add to previous results
_galMulAVX512Parallel82(in[inputOffset:inputEnd], out[outputOffset:outputEnd], &matrix82, addTo)
done = (done >> 6) << 6
if len(in[0])-done == 0 {
return
}
for c := inputOffset; c < inputOffset+dimIn; c++ {
for iRow := outputOffset; iRow < outputOffset+dimOut82; iRow++ {
if c < len(matrixRows[iRow]) {
mt := mulTable[matrixRows[iRow][c]][:256]
for i := done; i < len(in[0]); i++ {
if c == 0 { // only set value for first input column
out[iRow][i] = mt[in[c][i]]
} else { // and add for all others
out[iRow][i] ^= mt[in[c][i]]
}
}
}
}
}
} | go | func galMulAVX512Parallel82(in, out [][]byte, matrixRows [][]byte, inputOffset, outputOffset int) {
done := len(in[0])
if done == 0 {
return
}
inputEnd := inputOffset + dimIn
if inputEnd > len(in) {
inputEnd = len(in)
}
outputEnd := outputOffset + dimOut82
if outputEnd > len(out) {
outputEnd = len(out)
}
matrix82 := [matrixSize82]byte{}
setupMatrix82(matrixRows, inputOffset, outputOffset, &matrix82)
addTo := inputOffset != 0 // Except for the first input column, add to previous results
_galMulAVX512Parallel82(in[inputOffset:inputEnd], out[outputOffset:outputEnd], &matrix82, addTo)
done = (done >> 6) << 6
if len(in[0])-done == 0 {
return
}
for c := inputOffset; c < inputOffset+dimIn; c++ {
for iRow := outputOffset; iRow < outputOffset+dimOut82; iRow++ {
if c < len(matrixRows[iRow]) {
mt := mulTable[matrixRows[iRow][c]][:256]
for i := done; i < len(in[0]); i++ {
if c == 0 { // only set value for first input column
out[iRow][i] = mt[in[c][i]]
} else { // and add for all others
out[iRow][i] ^= mt[in[c][i]]
}
}
}
}
}
} | [
"func",
"galMulAVX512Parallel82",
"(",
"in",
",",
"out",
"[",
"]",
"[",
"]",
"byte",
",",
"matrixRows",
"[",
"]",
"[",
"]",
"byte",
",",
"inputOffset",
",",
"outputOffset",
"int",
")",
"{",
"done",
":=",
"len",
"(",
"in",
"[",
"0",
"]",
")",
"\n",
"if",
"done",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"inputEnd",
":=",
"inputOffset",
"+",
"dimIn",
"\n",
"if",
"inputEnd",
">",
"len",
"(",
"in",
")",
"{",
"inputEnd",
"=",
"len",
"(",
"in",
")",
"\n",
"}",
"\n",
"outputEnd",
":=",
"outputOffset",
"+",
"dimOut82",
"\n",
"if",
"outputEnd",
">",
"len",
"(",
"out",
")",
"{",
"outputEnd",
"=",
"len",
"(",
"out",
")",
"\n",
"}",
"\n\n",
"matrix82",
":=",
"[",
"matrixSize82",
"]",
"byte",
"{",
"}",
"\n",
"setupMatrix82",
"(",
"matrixRows",
",",
"inputOffset",
",",
"outputOffset",
",",
"&",
"matrix82",
")",
"\n",
"addTo",
":=",
"inputOffset",
"!=",
"0",
"// Except for the first input column, add to previous results",
"\n",
"_galMulAVX512Parallel82",
"(",
"in",
"[",
"inputOffset",
":",
"inputEnd",
"]",
",",
"out",
"[",
"outputOffset",
":",
"outputEnd",
"]",
",",
"&",
"matrix82",
",",
"addTo",
")",
"\n\n",
"done",
"=",
"(",
"done",
">>",
"6",
")",
"<<",
"6",
"\n",
"if",
"len",
"(",
"in",
"[",
"0",
"]",
")",
"-",
"done",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"for",
"c",
":=",
"inputOffset",
";",
"c",
"<",
"inputOffset",
"+",
"dimIn",
";",
"c",
"++",
"{",
"for",
"iRow",
":=",
"outputOffset",
";",
"iRow",
"<",
"outputOffset",
"+",
"dimOut82",
";",
"iRow",
"++",
"{",
"if",
"c",
"<",
"len",
"(",
"matrixRows",
"[",
"iRow",
"]",
")",
"{",
"mt",
":=",
"mulTable",
"[",
"matrixRows",
"[",
"iRow",
"]",
"[",
"c",
"]",
"]",
"[",
":",
"256",
"]",
"\n",
"for",
"i",
":=",
"done",
";",
"i",
"<",
"len",
"(",
"in",
"[",
"0",
"]",
")",
";",
"i",
"++",
"{",
"if",
"c",
"==",
"0",
"{",
"// only set value for first input column",
"out",
"[",
"iRow",
"]",
"[",
"i",
"]",
"=",
"mt",
"[",
"in",
"[",
"c",
"]",
"[",
"i",
"]",
"]",
"\n",
"}",
"else",
"{",
"// and add for all others",
"out",
"[",
"iRow",
"]",
"[",
"i",
"]",
"^=",
"mt",
"[",
"in",
"[",
"c",
"]",
"[",
"i",
"]",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Invoke AVX512 routine for 2 output rows in parallel | [
"Invoke",
"AVX512",
"routine",
"for",
"2",
"output",
"rows",
"in",
"parallel"
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/galoisAvx512_amd64.go#L73-L112 |
150,545 | klauspost/reedsolomon | galoisAvx512_amd64.go | galMulAVX512Parallel84 | func galMulAVX512Parallel84(in, out [][]byte, matrixRows [][]byte, inputOffset, outputOffset int) {
done := len(in[0])
if done == 0 {
return
}
inputEnd := inputOffset + dimIn
if inputEnd > len(in) {
inputEnd = len(in)
}
outputEnd := outputOffset + dimOut84
if outputEnd > len(out) {
outputEnd = len(out)
}
matrix84 := [matrixSize84]byte{}
setupMatrix84(matrixRows, inputOffset, outputOffset, &matrix84)
addTo := inputOffset != 0 // Except for the first input column, add to previous results
_galMulAVX512Parallel84(in[inputOffset:inputEnd], out[outputOffset:outputEnd], &matrix84, addTo)
done = (done >> 6) << 6
if len(in[0])-done == 0 {
return
}
for c := inputOffset; c < inputOffset+dimIn; c++ {
for iRow := outputOffset; iRow < outputOffset+dimOut84; iRow++ {
if c < len(matrixRows[iRow]) {
mt := mulTable[matrixRows[iRow][c]][:256]
for i := done; i < len(in[0]); i++ {
if c == 0 { // only set value for first input column
out[iRow][i] = mt[in[c][i]]
} else { // and add for all others
out[iRow][i] ^= mt[in[c][i]]
}
}
}
}
}
} | go | func galMulAVX512Parallel84(in, out [][]byte, matrixRows [][]byte, inputOffset, outputOffset int) {
done := len(in[0])
if done == 0 {
return
}
inputEnd := inputOffset + dimIn
if inputEnd > len(in) {
inputEnd = len(in)
}
outputEnd := outputOffset + dimOut84
if outputEnd > len(out) {
outputEnd = len(out)
}
matrix84 := [matrixSize84]byte{}
setupMatrix84(matrixRows, inputOffset, outputOffset, &matrix84)
addTo := inputOffset != 0 // Except for the first input column, add to previous results
_galMulAVX512Parallel84(in[inputOffset:inputEnd], out[outputOffset:outputEnd], &matrix84, addTo)
done = (done >> 6) << 6
if len(in[0])-done == 0 {
return
}
for c := inputOffset; c < inputOffset+dimIn; c++ {
for iRow := outputOffset; iRow < outputOffset+dimOut84; iRow++ {
if c < len(matrixRows[iRow]) {
mt := mulTable[matrixRows[iRow][c]][:256]
for i := done; i < len(in[0]); i++ {
if c == 0 { // only set value for first input column
out[iRow][i] = mt[in[c][i]]
} else { // and add for all others
out[iRow][i] ^= mt[in[c][i]]
}
}
}
}
}
} | [
"func",
"galMulAVX512Parallel84",
"(",
"in",
",",
"out",
"[",
"]",
"[",
"]",
"byte",
",",
"matrixRows",
"[",
"]",
"[",
"]",
"byte",
",",
"inputOffset",
",",
"outputOffset",
"int",
")",
"{",
"done",
":=",
"len",
"(",
"in",
"[",
"0",
"]",
")",
"\n",
"if",
"done",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"inputEnd",
":=",
"inputOffset",
"+",
"dimIn",
"\n",
"if",
"inputEnd",
">",
"len",
"(",
"in",
")",
"{",
"inputEnd",
"=",
"len",
"(",
"in",
")",
"\n",
"}",
"\n",
"outputEnd",
":=",
"outputOffset",
"+",
"dimOut84",
"\n",
"if",
"outputEnd",
">",
"len",
"(",
"out",
")",
"{",
"outputEnd",
"=",
"len",
"(",
"out",
")",
"\n",
"}",
"\n\n",
"matrix84",
":=",
"[",
"matrixSize84",
"]",
"byte",
"{",
"}",
"\n",
"setupMatrix84",
"(",
"matrixRows",
",",
"inputOffset",
",",
"outputOffset",
",",
"&",
"matrix84",
")",
"\n",
"addTo",
":=",
"inputOffset",
"!=",
"0",
"// Except for the first input column, add to previous results",
"\n",
"_galMulAVX512Parallel84",
"(",
"in",
"[",
"inputOffset",
":",
"inputEnd",
"]",
",",
"out",
"[",
"outputOffset",
":",
"outputEnd",
"]",
",",
"&",
"matrix84",
",",
"addTo",
")",
"\n\n",
"done",
"=",
"(",
"done",
">>",
"6",
")",
"<<",
"6",
"\n",
"if",
"len",
"(",
"in",
"[",
"0",
"]",
")",
"-",
"done",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"for",
"c",
":=",
"inputOffset",
";",
"c",
"<",
"inputOffset",
"+",
"dimIn",
";",
"c",
"++",
"{",
"for",
"iRow",
":=",
"outputOffset",
";",
"iRow",
"<",
"outputOffset",
"+",
"dimOut84",
";",
"iRow",
"++",
"{",
"if",
"c",
"<",
"len",
"(",
"matrixRows",
"[",
"iRow",
"]",
")",
"{",
"mt",
":=",
"mulTable",
"[",
"matrixRows",
"[",
"iRow",
"]",
"[",
"c",
"]",
"]",
"[",
":",
"256",
"]",
"\n",
"for",
"i",
":=",
"done",
";",
"i",
"<",
"len",
"(",
"in",
"[",
"0",
"]",
")",
";",
"i",
"++",
"{",
"if",
"c",
"==",
"0",
"{",
"// only set value for first input column",
"out",
"[",
"iRow",
"]",
"[",
"i",
"]",
"=",
"mt",
"[",
"in",
"[",
"c",
"]",
"[",
"i",
"]",
"]",
"\n",
"}",
"else",
"{",
"// and add for all others",
"out",
"[",
"iRow",
"]",
"[",
"i",
"]",
"^=",
"mt",
"[",
"in",
"[",
"c",
"]",
"[",
"i",
"]",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Invoke AVX512 routine for 4 output rows in parallel | [
"Invoke",
"AVX512",
"routine",
"for",
"4",
"output",
"rows",
"in",
"parallel"
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/galoisAvx512_amd64.go#L115-L154 |
150,546 | klauspost/reedsolomon | galoisAvx512_amd64.go | codeSomeShardsAvx512 | func (r reedSolomon) codeSomeShardsAvx512(matrixRows, inputs, outputs [][]byte, outputCount, byteCount int) {
outputRow := 0
// First process (multiple) batches of 4 output rows in parallel
for ; outputRow+dimOut84 <= len(outputs); outputRow += dimOut84 {
for inputRow := 0; inputRow < len(inputs); inputRow += dimIn {
galMulAVX512Parallel84(inputs, outputs, matrixRows, inputRow, outputRow)
}
}
// Then process a (single) batch of 2 output rows in parallel
if outputRow+dimOut82 <= len(outputs) {
// fmt.Println(outputRow, len(outputs))
for inputRow := 0; inputRow < len(inputs); inputRow += dimIn {
galMulAVX512Parallel82(inputs, outputs, matrixRows, inputRow, outputRow)
}
outputRow += dimOut82
}
// Lastly, we may have a single output row left (for uneven parity)
if outputRow < len(outputs) {
for c := 0; c < r.DataShards; c++ {
if c == 0 {
galMulSlice(matrixRows[outputRow][c], inputs[c], outputs[outputRow], &r.o)
} else {
galMulSliceXor(matrixRows[outputRow][c], inputs[c], outputs[outputRow], &r.o)
}
}
}
} | go | func (r reedSolomon) codeSomeShardsAvx512(matrixRows, inputs, outputs [][]byte, outputCount, byteCount int) {
outputRow := 0
// First process (multiple) batches of 4 output rows in parallel
for ; outputRow+dimOut84 <= len(outputs); outputRow += dimOut84 {
for inputRow := 0; inputRow < len(inputs); inputRow += dimIn {
galMulAVX512Parallel84(inputs, outputs, matrixRows, inputRow, outputRow)
}
}
// Then process a (single) batch of 2 output rows in parallel
if outputRow+dimOut82 <= len(outputs) {
// fmt.Println(outputRow, len(outputs))
for inputRow := 0; inputRow < len(inputs); inputRow += dimIn {
galMulAVX512Parallel82(inputs, outputs, matrixRows, inputRow, outputRow)
}
outputRow += dimOut82
}
// Lastly, we may have a single output row left (for uneven parity)
if outputRow < len(outputs) {
for c := 0; c < r.DataShards; c++ {
if c == 0 {
galMulSlice(matrixRows[outputRow][c], inputs[c], outputs[outputRow], &r.o)
} else {
galMulSliceXor(matrixRows[outputRow][c], inputs[c], outputs[outputRow], &r.o)
}
}
}
} | [
"func",
"(",
"r",
"reedSolomon",
")",
"codeSomeShardsAvx512",
"(",
"matrixRows",
",",
"inputs",
",",
"outputs",
"[",
"]",
"[",
"]",
"byte",
",",
"outputCount",
",",
"byteCount",
"int",
")",
"{",
"outputRow",
":=",
"0",
"\n",
"// First process (multiple) batches of 4 output rows in parallel",
"for",
";",
"outputRow",
"+",
"dimOut84",
"<=",
"len",
"(",
"outputs",
")",
";",
"outputRow",
"+=",
"dimOut84",
"{",
"for",
"inputRow",
":=",
"0",
";",
"inputRow",
"<",
"len",
"(",
"inputs",
")",
";",
"inputRow",
"+=",
"dimIn",
"{",
"galMulAVX512Parallel84",
"(",
"inputs",
",",
"outputs",
",",
"matrixRows",
",",
"inputRow",
",",
"outputRow",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// Then process a (single) batch of 2 output rows in parallel",
"if",
"outputRow",
"+",
"dimOut82",
"<=",
"len",
"(",
"outputs",
")",
"{",
"// fmt.Println(outputRow, len(outputs))",
"for",
"inputRow",
":=",
"0",
";",
"inputRow",
"<",
"len",
"(",
"inputs",
")",
";",
"inputRow",
"+=",
"dimIn",
"{",
"galMulAVX512Parallel82",
"(",
"inputs",
",",
"outputs",
",",
"matrixRows",
",",
"inputRow",
",",
"outputRow",
")",
"\n",
"}",
"\n",
"outputRow",
"+=",
"dimOut82",
"\n",
"}",
"\n",
"// Lastly, we may have a single output row left (for uneven parity)",
"if",
"outputRow",
"<",
"len",
"(",
"outputs",
")",
"{",
"for",
"c",
":=",
"0",
";",
"c",
"<",
"r",
".",
"DataShards",
";",
"c",
"++",
"{",
"if",
"c",
"==",
"0",
"{",
"galMulSlice",
"(",
"matrixRows",
"[",
"outputRow",
"]",
"[",
"c",
"]",
",",
"inputs",
"[",
"c",
"]",
",",
"outputs",
"[",
"outputRow",
"]",
",",
"&",
"r",
".",
"o",
")",
"\n",
"}",
"else",
"{",
"galMulSliceXor",
"(",
"matrixRows",
"[",
"outputRow",
"]",
"[",
"c",
"]",
",",
"inputs",
"[",
"c",
"]",
",",
"outputs",
"[",
"outputRow",
"]",
",",
"&",
"r",
".",
"o",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Perform the same as codeSomeShards, but taking advantage of
// AVX512 parallelism for up to 4x faster execution as compared to AVX2 | [
"Perform",
"the",
"same",
"as",
"codeSomeShards",
"but",
"taking",
"advantage",
"of",
"AVX512",
"parallelism",
"for",
"up",
"to",
"4x",
"faster",
"execution",
"as",
"compared",
"to",
"AVX2"
] | a373324398e4d088b67d6dd6157285b5d4e29642 | https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/galoisAvx512_amd64.go#L158-L184 |
150,547 | gocraft/dbr | union.go | Union | func Union(builder ...Builder) interface {
Builder
As(string) Builder
} {
return &union{
builder: builder,
}
} | go | func Union(builder ...Builder) interface {
Builder
As(string) Builder
} {
return &union{
builder: builder,
}
} | [
"func",
"Union",
"(",
"builder",
"...",
"Builder",
")",
"interface",
"{",
"Builder",
"\n",
"As",
"(",
"string",
")",
"Builder",
"\n",
"}",
"{",
"return",
"&",
"union",
"{",
"builder",
":",
"builder",
",",
"}",
"\n",
"}"
] | // Union builds `... UNION ...`. | [
"Union",
"builds",
"...",
"UNION",
"...",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/union.go#L9-L16 |
150,548 | gocraft/dbr | union.go | UnionAll | func UnionAll(builder ...Builder) interface {
Builder
As(string) Builder
} {
return &union{
builder: builder,
all: true,
}
} | go | func UnionAll(builder ...Builder) interface {
Builder
As(string) Builder
} {
return &union{
builder: builder,
all: true,
}
} | [
"func",
"UnionAll",
"(",
"builder",
"...",
"Builder",
")",
"interface",
"{",
"Builder",
"\n",
"As",
"(",
"string",
")",
"Builder",
"\n",
"}",
"{",
"return",
"&",
"union",
"{",
"builder",
":",
"builder",
",",
"all",
":",
"true",
",",
"}",
"\n",
"}"
] | // UnionAll builds `... UNION ALL ...`. | [
"UnionAll",
"builds",
"...",
"UNION",
"ALL",
"...",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/union.go#L19-L27 |
150,549 | gocraft/dbr | select.go | Where | func (b *SelectStmt) Where(query interface{}, value ...interface{}) *SelectStmt {
switch query := query.(type) {
case string:
b.WhereCond = append(b.WhereCond, Expr(query, value...))
case Builder:
b.WhereCond = append(b.WhereCond, query)
}
return b
} | go | func (b *SelectStmt) Where(query interface{}, value ...interface{}) *SelectStmt {
switch query := query.(type) {
case string:
b.WhereCond = append(b.WhereCond, Expr(query, value...))
case Builder:
b.WhereCond = append(b.WhereCond, query)
}
return b
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"Where",
"(",
"query",
"interface",
"{",
"}",
",",
"value",
"...",
"interface",
"{",
"}",
")",
"*",
"SelectStmt",
"{",
"switch",
"query",
":=",
"query",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"b",
".",
"WhereCond",
"=",
"append",
"(",
"b",
".",
"WhereCond",
",",
"Expr",
"(",
"query",
",",
"value",
"...",
")",
")",
"\n",
"case",
"Builder",
":",
"b",
".",
"WhereCond",
"=",
"append",
"(",
"b",
".",
"WhereCond",
",",
"query",
")",
"\n",
"}",
"\n",
"return",
"b",
"\n",
"}"
] | // Where adds a where condition.
// query can be Builder or string. value is used only if query type is string. | [
"Where",
"adds",
"a",
"where",
"condition",
".",
"query",
"can",
"be",
"Builder",
"or",
"string",
".",
"value",
"is",
"used",
"only",
"if",
"query",
"type",
"is",
"string",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select.go#L216-L224 |
150,550 | gocraft/dbr | select.go | Having | func (b *SelectStmt) Having(query interface{}, value ...interface{}) *SelectStmt {
switch query := query.(type) {
case string:
b.HavingCond = append(b.HavingCond, Expr(query, value...))
case Builder:
b.HavingCond = append(b.HavingCond, query)
}
return b
} | go | func (b *SelectStmt) Having(query interface{}, value ...interface{}) *SelectStmt {
switch query := query.(type) {
case string:
b.HavingCond = append(b.HavingCond, Expr(query, value...))
case Builder:
b.HavingCond = append(b.HavingCond, query)
}
return b
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"Having",
"(",
"query",
"interface",
"{",
"}",
",",
"value",
"...",
"interface",
"{",
"}",
")",
"*",
"SelectStmt",
"{",
"switch",
"query",
":=",
"query",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"b",
".",
"HavingCond",
"=",
"append",
"(",
"b",
".",
"HavingCond",
",",
"Expr",
"(",
"query",
",",
"value",
"...",
")",
")",
"\n",
"case",
"Builder",
":",
"b",
".",
"HavingCond",
"=",
"append",
"(",
"b",
".",
"HavingCond",
",",
"query",
")",
"\n",
"}",
"\n",
"return",
"b",
"\n",
"}"
] | // Having adds a having condition.
// query can be Builder or string. value is used only if query type is string. | [
"Having",
"adds",
"a",
"having",
"condition",
".",
"query",
"can",
"be",
"Builder",
"or",
"string",
".",
"value",
"is",
"used",
"only",
"if",
"query",
"type",
"is",
"string",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select.go#L228-L236 |
150,551 | gocraft/dbr | select.go | GroupBy | func (b *SelectStmt) GroupBy(col ...string) *SelectStmt {
for _, group := range col {
b.Group = append(b.Group, Expr(group))
}
return b
} | go | func (b *SelectStmt) GroupBy(col ...string) *SelectStmt {
for _, group := range col {
b.Group = append(b.Group, Expr(group))
}
return b
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"GroupBy",
"(",
"col",
"...",
"string",
")",
"*",
"SelectStmt",
"{",
"for",
"_",
",",
"group",
":=",
"range",
"col",
"{",
"b",
".",
"Group",
"=",
"append",
"(",
"b",
".",
"Group",
",",
"Expr",
"(",
"group",
")",
")",
"\n",
"}",
"\n",
"return",
"b",
"\n",
"}"
] | // GroupBy specifies columns for grouping. | [
"GroupBy",
"specifies",
"columns",
"for",
"grouping",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select.go#L239-L244 |
150,552 | gocraft/dbr | select.go | OrderBy | func (b *SelectStmt) OrderBy(col string) *SelectStmt {
b.Order = append(b.Order, Expr(col))
return b
} | go | func (b *SelectStmt) OrderBy(col string) *SelectStmt {
b.Order = append(b.Order, Expr(col))
return b
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"OrderBy",
"(",
"col",
"string",
")",
"*",
"SelectStmt",
"{",
"b",
".",
"Order",
"=",
"append",
"(",
"b",
".",
"Order",
",",
"Expr",
"(",
"col",
")",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // OrderBy specifies columns for ordering. | [
"OrderBy",
"specifies",
"columns",
"for",
"ordering",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select.go#L257-L260 |
150,553 | gocraft/dbr | select.go | Paginate | func (b *SelectStmt) Paginate(page, perPage uint64) *SelectStmt {
b.Limit(perPage)
b.Offset((page - 1) * perPage)
return b
} | go | func (b *SelectStmt) Paginate(page, perPage uint64) *SelectStmt {
b.Limit(perPage)
b.Offset((page - 1) * perPage)
return b
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"Paginate",
"(",
"page",
",",
"perPage",
"uint64",
")",
"*",
"SelectStmt",
"{",
"b",
".",
"Limit",
"(",
"perPage",
")",
"\n",
"b",
".",
"Offset",
"(",
"(",
"page",
"-",
"1",
")",
"*",
"perPage",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Paginate fetches a page in a naive way for a small set of data. | [
"Paginate",
"fetches",
"a",
"page",
"in",
"a",
"naive",
"way",
"for",
"a",
"small",
"set",
"of",
"data",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select.go#L273-L277 |
150,554 | gocraft/dbr | select.go | OrderDir | func (b *SelectStmt) OrderDir(col string, isAsc bool) *SelectStmt {
if isAsc {
b.OrderAsc(col)
} else {
b.OrderDesc(col)
}
return b
} | go | func (b *SelectStmt) OrderDir(col string, isAsc bool) *SelectStmt {
if isAsc {
b.OrderAsc(col)
} else {
b.OrderDesc(col)
}
return b
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"OrderDir",
"(",
"col",
"string",
",",
"isAsc",
"bool",
")",
"*",
"SelectStmt",
"{",
"if",
"isAsc",
"{",
"b",
".",
"OrderAsc",
"(",
"col",
")",
"\n",
"}",
"else",
"{",
"b",
".",
"OrderDesc",
"(",
"col",
")",
"\n",
"}",
"\n",
"return",
"b",
"\n",
"}"
] | // OrderDir is a helper for OrderAsc and OrderDesc. | [
"OrderDir",
"is",
"a",
"helper",
"for",
"OrderAsc",
"and",
"OrderDesc",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select.go#L280-L287 |
150,555 | gocraft/dbr | select.go | Join | func (b *SelectStmt) Join(table, on interface{}) *SelectStmt {
b.JoinTable = append(b.JoinTable, join(inner, table, on))
return b
} | go | func (b *SelectStmt) Join(table, on interface{}) *SelectStmt {
b.JoinTable = append(b.JoinTable, join(inner, table, on))
return b
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"Join",
"(",
"table",
",",
"on",
"interface",
"{",
"}",
")",
"*",
"SelectStmt",
"{",
"b",
".",
"JoinTable",
"=",
"append",
"(",
"b",
".",
"JoinTable",
",",
"join",
"(",
"inner",
",",
"table",
",",
"on",
")",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Join add inner-join.
// on can be Builder or string. | [
"Join",
"add",
"inner",
"-",
"join",
".",
"on",
"can",
"be",
"Builder",
"or",
"string",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select.go#L291-L294 |
150,556 | gocraft/dbr | select.go | LeftJoin | func (b *SelectStmt) LeftJoin(table, on interface{}) *SelectStmt {
b.JoinTable = append(b.JoinTable, join(left, table, on))
return b
} | go | func (b *SelectStmt) LeftJoin(table, on interface{}) *SelectStmt {
b.JoinTable = append(b.JoinTable, join(left, table, on))
return b
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"LeftJoin",
"(",
"table",
",",
"on",
"interface",
"{",
"}",
")",
"*",
"SelectStmt",
"{",
"b",
".",
"JoinTable",
"=",
"append",
"(",
"b",
".",
"JoinTable",
",",
"join",
"(",
"left",
",",
"table",
",",
"on",
")",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // LeftJoin add left-join.
// on can be Builder or string. | [
"LeftJoin",
"add",
"left",
"-",
"join",
".",
"on",
"can",
"be",
"Builder",
"or",
"string",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select.go#L298-L301 |
150,557 | gocraft/dbr | select.go | RightJoin | func (b *SelectStmt) RightJoin(table, on interface{}) *SelectStmt {
b.JoinTable = append(b.JoinTable, join(right, table, on))
return b
} | go | func (b *SelectStmt) RightJoin(table, on interface{}) *SelectStmt {
b.JoinTable = append(b.JoinTable, join(right, table, on))
return b
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"RightJoin",
"(",
"table",
",",
"on",
"interface",
"{",
"}",
")",
"*",
"SelectStmt",
"{",
"b",
".",
"JoinTable",
"=",
"append",
"(",
"b",
".",
"JoinTable",
",",
"join",
"(",
"right",
",",
"table",
",",
"on",
")",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // RightJoin add right-join.
// on can be Builder or string. | [
"RightJoin",
"add",
"right",
"-",
"join",
".",
"on",
"can",
"be",
"Builder",
"or",
"string",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select.go#L305-L308 |
150,558 | gocraft/dbr | select.go | FullJoin | func (b *SelectStmt) FullJoin(table, on interface{}) *SelectStmt {
b.JoinTable = append(b.JoinTable, join(full, table, on))
return b
} | go | func (b *SelectStmt) FullJoin(table, on interface{}) *SelectStmt {
b.JoinTable = append(b.JoinTable, join(full, table, on))
return b
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"FullJoin",
"(",
"table",
",",
"on",
"interface",
"{",
"}",
")",
"*",
"SelectStmt",
"{",
"b",
".",
"JoinTable",
"=",
"append",
"(",
"b",
".",
"JoinTable",
",",
"join",
"(",
"full",
",",
"table",
",",
"on",
")",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // FullJoin add full-join.
// on can be Builder or string. | [
"FullJoin",
"add",
"full",
"-",
"join",
".",
"on",
"can",
"be",
"Builder",
"or",
"string",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select.go#L312-L315 |
150,559 | gocraft/dbr | select.go | Rows | func (b *SelectStmt) Rows() (*sql.Rows, error) {
return b.RowsContext(context.Background())
} | go | func (b *SelectStmt) Rows() (*sql.Rows, error) {
return b.RowsContext(context.Background())
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"Rows",
"(",
")",
"(",
"*",
"sql",
".",
"Rows",
",",
"error",
")",
"{",
"return",
"b",
".",
"RowsContext",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"}"
] | // Rows executes the query and returns the rows returned, or any error encountered. | [
"Rows",
"executes",
"the",
"query",
"and",
"returns",
"the",
"rows",
"returned",
"or",
"any",
"error",
"encountered",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select.go#L323-L325 |
150,560 | gocraft/dbr | builder.go | Build | func (b BuildFunc) Build(d Dialect, buf Buffer) error {
return b(d, buf)
} | go | func (b BuildFunc) Build(d Dialect, buf Buffer) error {
return b(d, buf)
} | [
"func",
"(",
"b",
"BuildFunc",
")",
"Build",
"(",
"d",
"Dialect",
",",
"buf",
"Buffer",
")",
"error",
"{",
"return",
"b",
"(",
"d",
",",
"buf",
")",
"\n",
"}"
] | // Build calls itself to build SQL. | [
"Build",
"calls",
"itself",
"to",
"build",
"SQL",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/builder.go#L20-L22 |
150,561 | gocraft/dbr | condition.go | And | func And(cond ...Builder) Builder {
return BuildFunc(func(d Dialect, buf Buffer) error {
return buildCond(d, buf, "AND", cond...)
})
} | go | func And(cond ...Builder) Builder {
return BuildFunc(func(d Dialect, buf Buffer) error {
return buildCond(d, buf, "AND", cond...)
})
} | [
"func",
"And",
"(",
"cond",
"...",
"Builder",
")",
"Builder",
"{",
"return",
"BuildFunc",
"(",
"func",
"(",
"d",
"Dialect",
",",
"buf",
"Buffer",
")",
"error",
"{",
"return",
"buildCond",
"(",
"d",
",",
"buf",
",",
"\"",
"\"",
",",
"cond",
"...",
")",
"\n",
"}",
")",
"\n",
"}"
] | // And creates AND from a list of conditions. | [
"And",
"creates",
"AND",
"from",
"a",
"list",
"of",
"conditions",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/condition.go#L25-L29 |
150,562 | gocraft/dbr | condition.go | Eq | func Eq(column string, value interface{}) Builder {
return BuildFunc(func(d Dialect, buf Buffer) error {
if value == nil {
buf.WriteString(d.QuoteIdent(column))
buf.WriteString(" IS NULL")
return nil
}
v := reflect.ValueOf(value)
if v.Kind() == reflect.Slice {
if v.Len() == 0 {
buf.WriteString(d.EncodeBool(false))
return nil
}
return buildCmp(d, buf, "IN", column, value)
}
return buildCmp(d, buf, "=", column, value)
})
} | go | func Eq(column string, value interface{}) Builder {
return BuildFunc(func(d Dialect, buf Buffer) error {
if value == nil {
buf.WriteString(d.QuoteIdent(column))
buf.WriteString(" IS NULL")
return nil
}
v := reflect.ValueOf(value)
if v.Kind() == reflect.Slice {
if v.Len() == 0 {
buf.WriteString(d.EncodeBool(false))
return nil
}
return buildCmp(d, buf, "IN", column, value)
}
return buildCmp(d, buf, "=", column, value)
})
} | [
"func",
"Eq",
"(",
"column",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"Builder",
"{",
"return",
"BuildFunc",
"(",
"func",
"(",
"d",
"Dialect",
",",
"buf",
"Buffer",
")",
"error",
"{",
"if",
"value",
"==",
"nil",
"{",
"buf",
".",
"WriteString",
"(",
"d",
".",
"QuoteIdent",
"(",
"column",
")",
")",
"\n",
"buf",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"value",
")",
"\n",
"if",
"v",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Slice",
"{",
"if",
"v",
".",
"Len",
"(",
")",
"==",
"0",
"{",
"buf",
".",
"WriteString",
"(",
"d",
".",
"EncodeBool",
"(",
"false",
")",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"buildCmp",
"(",
"d",
",",
"buf",
",",
"\"",
"\"",
",",
"column",
",",
"value",
")",
"\n",
"}",
"\n",
"return",
"buildCmp",
"(",
"d",
",",
"buf",
",",
"\"",
"\"",
",",
"column",
",",
"value",
")",
"\n",
"}",
")",
"\n",
"}"
] | // Eq is `=`.
// When value is nil, it will be translated to `IS NULL`.
// When value is a slice, it will be translated to `IN`.
// Otherwise it will be translated to `=`. | [
"Eq",
"is",
"=",
".",
"When",
"value",
"is",
"nil",
"it",
"will",
"be",
"translated",
"to",
"IS",
"NULL",
".",
"When",
"value",
"is",
"a",
"slice",
"it",
"will",
"be",
"translated",
"to",
"IN",
".",
"Otherwise",
"it",
"will",
"be",
"translated",
"to",
"=",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/condition.go#L53-L70 |
150,563 | gocraft/dbr | condition.go | Gt | func Gt(column string, value interface{}) Builder {
return BuildFunc(func(d Dialect, buf Buffer) error {
return buildCmp(d, buf, ">", column, value)
})
} | go | func Gt(column string, value interface{}) Builder {
return BuildFunc(func(d Dialect, buf Buffer) error {
return buildCmp(d, buf, ">", column, value)
})
} | [
"func",
"Gt",
"(",
"column",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"Builder",
"{",
"return",
"BuildFunc",
"(",
"func",
"(",
"d",
"Dialect",
",",
"buf",
"Buffer",
")",
"error",
"{",
"return",
"buildCmp",
"(",
"d",
",",
"buf",
",",
"\"",
"\"",
",",
"column",
",",
"value",
")",
"\n",
"}",
")",
"\n",
"}"
] | // Gt is `>`. | [
"Gt",
"is",
">",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/condition.go#L96-L100 |
150,564 | gocraft/dbr | condition.go | Like | func Like(column, value string, escape ...string) Builder {
return BuildFunc(func(d Dialect, buf Buffer) error {
return buildLike(d, buf, column, value, false, escape)
})
} | go | func Like(column, value string, escape ...string) Builder {
return BuildFunc(func(d Dialect, buf Buffer) error {
return buildLike(d, buf, column, value, false, escape)
})
} | [
"func",
"Like",
"(",
"column",
",",
"value",
"string",
",",
"escape",
"...",
"string",
")",
"Builder",
"{",
"return",
"BuildFunc",
"(",
"func",
"(",
"d",
"Dialect",
",",
"buf",
"Buffer",
")",
"error",
"{",
"return",
"buildLike",
"(",
"d",
",",
"buf",
",",
"column",
",",
"value",
",",
"false",
",",
"escape",
")",
"\n",
"}",
")",
"\n",
"}"
] | // Like is `LIKE`, with an optional `ESCAPE` clause | [
"Like",
"is",
"LIKE",
"with",
"an",
"optional",
"ESCAPE",
"clause"
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/condition.go#L139-L143 |
150,565 | gocraft/dbr | condition.go | NotLike | func NotLike(column, value string, escape ...string) Builder {
return BuildFunc(func(d Dialect, buf Buffer) error {
return buildLike(d, buf, column, value, true, escape)
})
} | go | func NotLike(column, value string, escape ...string) Builder {
return BuildFunc(func(d Dialect, buf Buffer) error {
return buildLike(d, buf, column, value, true, escape)
})
} | [
"func",
"NotLike",
"(",
"column",
",",
"value",
"string",
",",
"escape",
"...",
"string",
")",
"Builder",
"{",
"return",
"BuildFunc",
"(",
"func",
"(",
"d",
"Dialect",
",",
"buf",
"Buffer",
")",
"error",
"{",
"return",
"buildLike",
"(",
"d",
",",
"buf",
",",
"column",
",",
"value",
",",
"true",
",",
"escape",
")",
"\n",
"}",
")",
"\n",
"}"
] | // NotLike is `NOT LIKE`, with an optional `ESCAPE` clause | [
"NotLike",
"is",
"NOT",
"LIKE",
"with",
"an",
"optional",
"ESCAPE",
"clause"
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/condition.go#L146-L150 |
150,566 | gocraft/dbr | ident.go | Build | func (i I) Build(d Dialect, buf Buffer) error {
buf.WriteString(d.QuoteIdent(string(i)))
return nil
} | go | func (i I) Build(d Dialect, buf Buffer) error {
buf.WriteString(d.QuoteIdent(string(i)))
return nil
} | [
"func",
"(",
"i",
"I",
")",
"Build",
"(",
"d",
"Dialect",
",",
"buf",
"Buffer",
")",
"error",
"{",
"buf",
".",
"WriteString",
"(",
"d",
".",
"QuoteIdent",
"(",
"string",
"(",
"i",
")",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Build quotes string with dialect. | [
"Build",
"quotes",
"string",
"with",
"dialect",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/ident.go#L7-L10 |
150,567 | gocraft/dbr | opentracing/event_receiver.go | SpanStart | func (EventReceiver) SpanStart(ctx context.Context, eventName, query string) context.Context {
span, ctx := ot.StartSpanFromContext(ctx, eventName)
otext.DBStatement.Set(span, query)
otext.DBType.Set(span, "sql")
return ctx
} | go | func (EventReceiver) SpanStart(ctx context.Context, eventName, query string) context.Context {
span, ctx := ot.StartSpanFromContext(ctx, eventName)
otext.DBStatement.Set(span, query)
otext.DBType.Set(span, "sql")
return ctx
} | [
"func",
"(",
"EventReceiver",
")",
"SpanStart",
"(",
"ctx",
"context",
".",
"Context",
",",
"eventName",
",",
"query",
"string",
")",
"context",
".",
"Context",
"{",
"span",
",",
"ctx",
":=",
"ot",
".",
"StartSpanFromContext",
"(",
"ctx",
",",
"eventName",
")",
"\n",
"otext",
".",
"DBStatement",
".",
"Set",
"(",
"span",
",",
"query",
")",
"\n",
"otext",
".",
"DBType",
".",
"Set",
"(",
"span",
",",
"\"",
"\"",
")",
"\n",
"return",
"ctx",
"\n",
"}"
] | // SpanStart starts a new query span from ctx, then returns a new context with the new span. | [
"SpanStart",
"starts",
"a",
"new",
"query",
"span",
"from",
"ctx",
"then",
"returns",
"a",
"new",
"context",
"with",
"the",
"new",
"span",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/opentracing/event_receiver.go#L16-L21 |
150,568 | gocraft/dbr | opentracing/event_receiver.go | SpanFinish | func (EventReceiver) SpanFinish(ctx context.Context) {
if span := ot.SpanFromContext(ctx); span != nil {
span.Finish()
}
} | go | func (EventReceiver) SpanFinish(ctx context.Context) {
if span := ot.SpanFromContext(ctx); span != nil {
span.Finish()
}
} | [
"func",
"(",
"EventReceiver",
")",
"SpanFinish",
"(",
"ctx",
"context",
".",
"Context",
")",
"{",
"if",
"span",
":=",
"ot",
".",
"SpanFromContext",
"(",
"ctx",
")",
";",
"span",
"!=",
"nil",
"{",
"span",
".",
"Finish",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // SpanFinish finishes the span associated with ctx. | [
"SpanFinish",
"finishes",
"the",
"span",
"associated",
"with",
"ctx",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/opentracing/event_receiver.go#L24-L28 |
150,569 | gocraft/dbr | opentracing/event_receiver.go | SpanError | func (EventReceiver) SpanError(ctx context.Context, err error) {
if span := ot.SpanFromContext(ctx); span != nil {
otext.Error.Set(span, true)
span.LogFields(otlog.String("event", "error"), otlog.Error(err))
}
} | go | func (EventReceiver) SpanError(ctx context.Context, err error) {
if span := ot.SpanFromContext(ctx); span != nil {
otext.Error.Set(span, true)
span.LogFields(otlog.String("event", "error"), otlog.Error(err))
}
} | [
"func",
"(",
"EventReceiver",
")",
"SpanError",
"(",
"ctx",
"context",
".",
"Context",
",",
"err",
"error",
")",
"{",
"if",
"span",
":=",
"ot",
".",
"SpanFromContext",
"(",
"ctx",
")",
";",
"span",
"!=",
"nil",
"{",
"otext",
".",
"Error",
".",
"Set",
"(",
"span",
",",
"true",
")",
"\n",
"span",
".",
"LogFields",
"(",
"otlog",
".",
"String",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"otlog",
".",
"Error",
"(",
"err",
")",
")",
"\n",
"}",
"\n",
"}"
] | // SpanError adds an error to the span associated with ctx. | [
"SpanError",
"adds",
"an",
"error",
"to",
"the",
"span",
"associated",
"with",
"ctx",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/opentracing/event_receiver.go#L31-L36 |
150,570 | gocraft/dbr | types.go | MarshalJSON | func (n NullString) MarshalJSON() ([]byte, error) {
if n.Valid {
return json.Marshal(n.String)
}
return nullString, nil
} | go | func (n NullString) MarshalJSON() ([]byte, error) {
if n.Valid {
return json.Marshal(n.String)
}
return nullString, nil
} | [
"func",
"(",
"n",
"NullString",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"n",
".",
"Valid",
"{",
"return",
"json",
".",
"Marshal",
"(",
"n",
".",
"String",
")",
"\n",
"}",
"\n",
"return",
"nullString",
",",
"nil",
"\n",
"}"
] | // MarshalJSON correctly serializes a NullString to JSON. | [
"MarshalJSON",
"correctly",
"serializes",
"a",
"NullString",
"to",
"JSON",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/types.go#L52-L57 |
150,571 | gocraft/dbr | types.go | MarshalJSON | func (n NullInt64) MarshalJSON() ([]byte, error) {
if n.Valid {
return json.Marshal(n.Int64)
}
return nullString, nil
} | go | func (n NullInt64) MarshalJSON() ([]byte, error) {
if n.Valid {
return json.Marshal(n.Int64)
}
return nullString, nil
} | [
"func",
"(",
"n",
"NullInt64",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"n",
".",
"Valid",
"{",
"return",
"json",
".",
"Marshal",
"(",
"n",
".",
"Int64",
")",
"\n",
"}",
"\n",
"return",
"nullString",
",",
"nil",
"\n",
"}"
] | // MarshalJSON correctly serializes a NullInt64 to JSON. | [
"MarshalJSON",
"correctly",
"serializes",
"a",
"NullInt64",
"to",
"JSON",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/types.go#L60-L65 |
150,572 | gocraft/dbr | types.go | MarshalJSON | func (n NullBool) MarshalJSON() ([]byte, error) {
if n.Valid {
return json.Marshal(n.Bool)
}
return nullString, nil
} | go | func (n NullBool) MarshalJSON() ([]byte, error) {
if n.Valid {
return json.Marshal(n.Bool)
}
return nullString, nil
} | [
"func",
"(",
"n",
"NullBool",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"n",
".",
"Valid",
"{",
"return",
"json",
".",
"Marshal",
"(",
"n",
".",
"Bool",
")",
"\n",
"}",
"\n",
"return",
"nullString",
",",
"nil",
"\n",
"}"
] | // MarshalJSON correctly serializes a NullBool to JSON. | [
"MarshalJSON",
"correctly",
"serializes",
"a",
"NullBool",
"to",
"JSON",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/types.go#L84-L89 |
150,573 | gocraft/dbr | types.go | UnmarshalJSON | func (n *NullString) UnmarshalJSON(b []byte) error {
var s interface{}
if err := json.Unmarshal(b, &s); err != nil {
return err
}
return n.Scan(s)
} | go | func (n *NullString) UnmarshalJSON(b []byte) error {
var s interface{}
if err := json.Unmarshal(b, &s); err != nil {
return err
}
return n.Scan(s)
} | [
"func",
"(",
"n",
"*",
"NullString",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"s",
"interface",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"s",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"n",
".",
"Scan",
"(",
"s",
")",
"\n",
"}"
] | // UnmarshalJSON correctly deserializes a NullString from JSON. | [
"UnmarshalJSON",
"correctly",
"deserializes",
"a",
"NullString",
"from",
"JSON",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/types.go#L92-L98 |
150,574 | gocraft/dbr | types.go | UnmarshalJSON | func (n *NullInt64) UnmarshalJSON(b []byte) error {
var s json.Number
if err := json.Unmarshal(b, &s); err != nil {
return err
}
if s == "" {
return n.Scan(nil)
}
return n.Scan(s)
} | go | func (n *NullInt64) UnmarshalJSON(b []byte) error {
var s json.Number
if err := json.Unmarshal(b, &s); err != nil {
return err
}
if s == "" {
return n.Scan(nil)
}
return n.Scan(s)
} | [
"func",
"(",
"n",
"*",
"NullInt64",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"s",
"json",
".",
"Number",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"s",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"s",
"==",
"\"",
"\"",
"{",
"return",
"n",
".",
"Scan",
"(",
"nil",
")",
"\n",
"}",
"\n",
"return",
"n",
".",
"Scan",
"(",
"s",
")",
"\n",
"}"
] | // UnmarshalJSON correctly deserializes a NullInt64 from JSON. | [
"UnmarshalJSON",
"correctly",
"deserializes",
"a",
"NullInt64",
"from",
"JSON",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/types.go#L101-L110 |
150,575 | gocraft/dbr | types.go | UnmarshalJSON | func (n *NullTime) UnmarshalJSON(b []byte) error {
// scan for null
if bytes.Equal(b, nullString) {
return n.Scan(nil)
}
// scan for JSON timestamp
var t time.Time
if err := json.Unmarshal(b, &t); err != nil {
return err
}
return n.Scan(t)
} | go | func (n *NullTime) UnmarshalJSON(b []byte) error {
// scan for null
if bytes.Equal(b, nullString) {
return n.Scan(nil)
}
// scan for JSON timestamp
var t time.Time
if err := json.Unmarshal(b, &t); err != nil {
return err
}
return n.Scan(t)
} | [
"func",
"(",
"n",
"*",
"NullTime",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"// scan for null",
"if",
"bytes",
".",
"Equal",
"(",
"b",
",",
"nullString",
")",
"{",
"return",
"n",
".",
"Scan",
"(",
"nil",
")",
"\n",
"}",
"\n",
"// scan for JSON timestamp",
"var",
"t",
"time",
".",
"Time",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"t",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"n",
".",
"Scan",
"(",
"t",
")",
"\n",
"}"
] | // UnmarshalJSON correctly deserializes a NullTime from JSON. | [
"UnmarshalJSON",
"correctly",
"deserializes",
"a",
"NullTime",
"from",
"JSON",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/types.go#L122-L133 |
150,576 | gocraft/dbr | insert.go | Values | func (b *InsertStmt) Values(value ...interface{}) *InsertStmt {
b.Value = append(b.Value, value)
return b
} | go | func (b *InsertStmt) Values(value ...interface{}) *InsertStmt {
b.Value = append(b.Value, value)
return b
} | [
"func",
"(",
"b",
"*",
"InsertStmt",
")",
"Values",
"(",
"value",
"...",
"interface",
"{",
"}",
")",
"*",
"InsertStmt",
"{",
"b",
".",
"Value",
"=",
"append",
"(",
"b",
".",
"Value",
",",
"value",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Values adds a tuple to be inserted.
// The order of the tuple should match Columns. | [
"Values",
"adds",
"a",
"tuple",
"to",
"be",
"inserted",
".",
"The",
"order",
"of",
"the",
"tuple",
"should",
"match",
"Columns",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/insert.go#L140-L143 |
150,577 | gocraft/dbr | insert.go | Record | func (b *InsertStmt) Record(structValue interface{}) *InsertStmt {
v := reflect.Indirect(reflect.ValueOf(structValue))
if v.Kind() == reflect.Struct {
found := make([]interface{}, len(b.Column)+1)
// ID is recommended by golint here
s := newTagStore()
s.findValueByName(v, append(b.Column, "id"), found, false)
value := found[:len(found)-1]
for i, v := range value {
if v != nil {
value[i] = v.(reflect.Value).Interface()
}
}
if v.CanSet() {
switch idField := found[len(found)-1].(type) {
case reflect.Value:
if idField.Kind() == reflect.Int64 {
b.RecordID = idField.Addr().Interface().(*int64)
}
}
}
b.Values(value...)
}
return b
} | go | func (b *InsertStmt) Record(structValue interface{}) *InsertStmt {
v := reflect.Indirect(reflect.ValueOf(structValue))
if v.Kind() == reflect.Struct {
found := make([]interface{}, len(b.Column)+1)
// ID is recommended by golint here
s := newTagStore()
s.findValueByName(v, append(b.Column, "id"), found, false)
value := found[:len(found)-1]
for i, v := range value {
if v != nil {
value[i] = v.(reflect.Value).Interface()
}
}
if v.CanSet() {
switch idField := found[len(found)-1].(type) {
case reflect.Value:
if idField.Kind() == reflect.Int64 {
b.RecordID = idField.Addr().Interface().(*int64)
}
}
}
b.Values(value...)
}
return b
} | [
"func",
"(",
"b",
"*",
"InsertStmt",
")",
"Record",
"(",
"structValue",
"interface",
"{",
"}",
")",
"*",
"InsertStmt",
"{",
"v",
":=",
"reflect",
".",
"Indirect",
"(",
"reflect",
".",
"ValueOf",
"(",
"structValue",
")",
")",
"\n\n",
"if",
"v",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Struct",
"{",
"found",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"b",
".",
"Column",
")",
"+",
"1",
")",
"\n",
"// ID is recommended by golint here",
"s",
":=",
"newTagStore",
"(",
")",
"\n",
"s",
".",
"findValueByName",
"(",
"v",
",",
"append",
"(",
"b",
".",
"Column",
",",
"\"",
"\"",
")",
",",
"found",
",",
"false",
")",
"\n\n",
"value",
":=",
"found",
"[",
":",
"len",
"(",
"found",
")",
"-",
"1",
"]",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"value",
"{",
"if",
"v",
"!=",
"nil",
"{",
"value",
"[",
"i",
"]",
"=",
"v",
".",
"(",
"reflect",
".",
"Value",
")",
".",
"Interface",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"v",
".",
"CanSet",
"(",
")",
"{",
"switch",
"idField",
":=",
"found",
"[",
"len",
"(",
"found",
")",
"-",
"1",
"]",
".",
"(",
"type",
")",
"{",
"case",
"reflect",
".",
"Value",
":",
"if",
"idField",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Int64",
"{",
"b",
".",
"RecordID",
"=",
"idField",
".",
"Addr",
"(",
")",
".",
"Interface",
"(",
")",
".",
"(",
"*",
"int64",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"b",
".",
"Values",
"(",
"value",
"...",
")",
"\n",
"}",
"\n",
"return",
"b",
"\n",
"}"
] | // Record adds a tuple for columns from a struct.
//
// If there is a field called "Id" or "ID" in the struct,
// it will be set to LastInsertId. | [
"Record",
"adds",
"a",
"tuple",
"for",
"columns",
"from",
"a",
"struct",
".",
"If",
"there",
"is",
"a",
"field",
"called",
"Id",
"or",
"ID",
"in",
"the",
"struct",
"it",
"will",
"be",
"set",
"to",
"LastInsertId",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/insert.go#L149-L176 |
150,578 | gocraft/dbr | dbr.go | Open | func Open(driver, dsn string, log EventReceiver) (*Connection, error) {
if log == nil {
log = nullReceiver
}
conn, err := sql.Open(driver, dsn)
if err != nil {
return nil, err
}
var d Dialect
switch driver {
case "mysql":
d = dialect.MySQL
case "postgres":
d = dialect.PostgreSQL
case "sqlite3":
d = dialect.SQLite3
default:
return nil, ErrNotSupported
}
return &Connection{DB: conn, EventReceiver: log, Dialect: d}, nil
} | go | func Open(driver, dsn string, log EventReceiver) (*Connection, error) {
if log == nil {
log = nullReceiver
}
conn, err := sql.Open(driver, dsn)
if err != nil {
return nil, err
}
var d Dialect
switch driver {
case "mysql":
d = dialect.MySQL
case "postgres":
d = dialect.PostgreSQL
case "sqlite3":
d = dialect.SQLite3
default:
return nil, ErrNotSupported
}
return &Connection{DB: conn, EventReceiver: log, Dialect: d}, nil
} | [
"func",
"Open",
"(",
"driver",
",",
"dsn",
"string",
",",
"log",
"EventReceiver",
")",
"(",
"*",
"Connection",
",",
"error",
")",
"{",
"if",
"log",
"==",
"nil",
"{",
"log",
"=",
"nullReceiver",
"\n",
"}",
"\n",
"conn",
",",
"err",
":=",
"sql",
".",
"Open",
"(",
"driver",
",",
"dsn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"d",
"Dialect",
"\n",
"switch",
"driver",
"{",
"case",
"\"",
"\"",
":",
"d",
"=",
"dialect",
".",
"MySQL",
"\n",
"case",
"\"",
"\"",
":",
"d",
"=",
"dialect",
".",
"PostgreSQL",
"\n",
"case",
"\"",
"\"",
":",
"d",
"=",
"dialect",
".",
"SQLite3",
"\n",
"default",
":",
"return",
"nil",
",",
"ErrNotSupported",
"\n",
"}",
"\n",
"return",
"&",
"Connection",
"{",
"DB",
":",
"conn",
",",
"EventReceiver",
":",
"log",
",",
"Dialect",
":",
"d",
"}",
",",
"nil",
"\n",
"}"
] | // Open creates a Connection.
// log can be nil to ignore logging. | [
"Open",
"creates",
"a",
"Connection",
".",
"log",
"can",
"be",
"nil",
"to",
"ignore",
"logging",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/dbr.go#L15-L35 |
150,579 | gocraft/dbr | dbr.go | NewSession | func (conn *Connection) NewSession(log EventReceiver) *Session {
if log == nil {
log = conn.EventReceiver // Use parent instrumentation
}
return &Session{Connection: conn, EventReceiver: log}
} | go | func (conn *Connection) NewSession(log EventReceiver) *Session {
if log == nil {
log = conn.EventReceiver // Use parent instrumentation
}
return &Session{Connection: conn, EventReceiver: log}
} | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"NewSession",
"(",
"log",
"EventReceiver",
")",
"*",
"Session",
"{",
"if",
"log",
"==",
"nil",
"{",
"log",
"=",
"conn",
".",
"EventReceiver",
"// Use parent instrumentation",
"\n",
"}",
"\n",
"return",
"&",
"Session",
"{",
"Connection",
":",
"conn",
",",
"EventReceiver",
":",
"log",
"}",
"\n",
"}"
] | // NewSession instantiates a Session from Connection.
// If log is nil, Connection EventReceiver is used. | [
"NewSession",
"instantiates",
"a",
"Session",
"from",
"Connection",
".",
"If",
"log",
"is",
"nil",
"Connection",
"EventReceiver",
"is",
"used",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/dbr.go#L71-L76 |
150,580 | gocraft/dbr | now.go | Value | func (n nowSentinel) Value() (driver.Value, error) {
now := time.Now().UTC().Format(timeFormat)
return now, nil
} | go | func (n nowSentinel) Value() (driver.Value, error) {
now := time.Now().UTC().Format(timeFormat)
return now, nil
} | [
"func",
"(",
"n",
"nowSentinel",
")",
"Value",
"(",
")",
"(",
"driver",
".",
"Value",
",",
"error",
")",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
".",
"Format",
"(",
"timeFormat",
")",
"\n",
"return",
"now",
",",
"nil",
"\n",
"}"
] | // Value implements a valuer for compatibility | [
"Value",
"implements",
"a",
"valuer",
"for",
"compatibility"
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/now.go#L16-L19 |
150,581 | gocraft/dbr | update.go | Set | func (b *UpdateStmt) Set(column string, value interface{}) *UpdateStmt {
b.Value[column] = value
return b
} | go | func (b *UpdateStmt) Set(column string, value interface{}) *UpdateStmt {
b.Value[column] = value
return b
} | [
"func",
"(",
"b",
"*",
"UpdateStmt",
")",
"Set",
"(",
"column",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"*",
"UpdateStmt",
"{",
"b",
".",
"Value",
"[",
"column",
"]",
"=",
"value",
"\n",
"return",
"b",
"\n",
"}"
] | // Set updates column with value. | [
"Set",
"updates",
"column",
"with",
"value",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/update.go#L158-L161 |
150,582 | gocraft/dbr | select_return.go | ReturnInt64 | func (b *SelectStmt) ReturnInt64() (int64, error) {
var v int64
err := b.LoadOne(&v)
return v, err
} | go | func (b *SelectStmt) ReturnInt64() (int64, error) {
var v int64
err := b.LoadOne(&v)
return v, err
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"ReturnInt64",
"(",
")",
"(",
"int64",
",",
"error",
")",
"{",
"var",
"v",
"int64",
"\n",
"err",
":=",
"b",
".",
"LoadOne",
"(",
"&",
"v",
")",
"\n",
"return",
"v",
",",
"err",
"\n",
"}"
] | // ReturnInt64 executes the SelectStmt and returns the value as an int64. | [
"ReturnInt64",
"executes",
"the",
"SelectStmt",
"and",
"returns",
"the",
"value",
"as",
"an",
"int64",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select_return.go#L4-L8 |
150,583 | gocraft/dbr | select_return.go | ReturnInt64s | func (b *SelectStmt) ReturnInt64s() ([]int64, error) {
var v []int64
_, err := b.Load(&v)
return v, err
} | go | func (b *SelectStmt) ReturnInt64s() ([]int64, error) {
var v []int64
_, err := b.Load(&v)
return v, err
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"ReturnInt64s",
"(",
")",
"(",
"[",
"]",
"int64",
",",
"error",
")",
"{",
"var",
"v",
"[",
"]",
"int64",
"\n",
"_",
",",
"err",
":=",
"b",
".",
"Load",
"(",
"&",
"v",
")",
"\n",
"return",
"v",
",",
"err",
"\n",
"}"
] | // ReturnInt64s executes the SelectStmt and returns the value as a slice of int64s. | [
"ReturnInt64s",
"executes",
"the",
"SelectStmt",
"and",
"returns",
"the",
"value",
"as",
"a",
"slice",
"of",
"int64s",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select_return.go#L11-L15 |
150,584 | gocraft/dbr | select_return.go | ReturnUint64 | func (b *SelectStmt) ReturnUint64() (uint64, error) {
var v uint64
err := b.LoadOne(&v)
return v, err
} | go | func (b *SelectStmt) ReturnUint64() (uint64, error) {
var v uint64
err := b.LoadOne(&v)
return v, err
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"ReturnUint64",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"var",
"v",
"uint64",
"\n",
"err",
":=",
"b",
".",
"LoadOne",
"(",
"&",
"v",
")",
"\n",
"return",
"v",
",",
"err",
"\n",
"}"
] | // ReturnUint64 executes the SelectStmt and returns the value as an uint64. | [
"ReturnUint64",
"executes",
"the",
"SelectStmt",
"and",
"returns",
"the",
"value",
"as",
"an",
"uint64",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select_return.go#L18-L22 |
150,585 | gocraft/dbr | select_return.go | ReturnUint64s | func (b *SelectStmt) ReturnUint64s() ([]uint64, error) {
var v []uint64
_, err := b.Load(&v)
return v, err
} | go | func (b *SelectStmt) ReturnUint64s() ([]uint64, error) {
var v []uint64
_, err := b.Load(&v)
return v, err
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"ReturnUint64s",
"(",
")",
"(",
"[",
"]",
"uint64",
",",
"error",
")",
"{",
"var",
"v",
"[",
"]",
"uint64",
"\n",
"_",
",",
"err",
":=",
"b",
".",
"Load",
"(",
"&",
"v",
")",
"\n",
"return",
"v",
",",
"err",
"\n",
"}"
] | // ReturnUint64s executes the SelectStmt and returns the value as a slice of uint64s. | [
"ReturnUint64s",
"executes",
"the",
"SelectStmt",
"and",
"returns",
"the",
"value",
"as",
"a",
"slice",
"of",
"uint64s",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select_return.go#L25-L29 |
150,586 | gocraft/dbr | select_return.go | ReturnString | func (b *SelectStmt) ReturnString() (string, error) {
var v string
err := b.LoadOne(&v)
return v, err
} | go | func (b *SelectStmt) ReturnString() (string, error) {
var v string
err := b.LoadOne(&v)
return v, err
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"ReturnString",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"v",
"string",
"\n",
"err",
":=",
"b",
".",
"LoadOne",
"(",
"&",
"v",
")",
"\n",
"return",
"v",
",",
"err",
"\n",
"}"
] | // ReturnString executes the SelectStmt and returns the value as a string. | [
"ReturnString",
"executes",
"the",
"SelectStmt",
"and",
"returns",
"the",
"value",
"as",
"a",
"string",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select_return.go#L32-L36 |
150,587 | gocraft/dbr | select_return.go | ReturnStrings | func (b *SelectStmt) ReturnStrings() ([]string, error) {
var v []string
_, err := b.Load(&v)
return v, err
} | go | func (b *SelectStmt) ReturnStrings() ([]string, error) {
var v []string
_, err := b.Load(&v)
return v, err
} | [
"func",
"(",
"b",
"*",
"SelectStmt",
")",
"ReturnStrings",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"v",
"[",
"]",
"string",
"\n",
"_",
",",
"err",
":=",
"b",
".",
"Load",
"(",
"&",
"v",
")",
"\n",
"return",
"v",
",",
"err",
"\n",
"}"
] | // ReturnStrings executes the SelectStmt and returns the value as a slice of strings. | [
"ReturnStrings",
"executes",
"the",
"SelectStmt",
"and",
"returns",
"the",
"value",
"as",
"a",
"slice",
"of",
"strings",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select_return.go#L39-L43 |
150,588 | gocraft/dbr | transaction.go | BeginTx | func (sess *Session) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
tx, err := sess.Connection.BeginTx(ctx, opts)
if err != nil {
return nil, sess.EventErr("dbr.begin.error", err)
}
sess.Event("dbr.begin")
return &Tx{
EventReceiver: sess.EventReceiver,
Dialect: sess.Dialect,
Tx: tx,
Timeout: sess.GetTimeout(),
}, nil
} | go | func (sess *Session) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
tx, err := sess.Connection.BeginTx(ctx, opts)
if err != nil {
return nil, sess.EventErr("dbr.begin.error", err)
}
sess.Event("dbr.begin")
return &Tx{
EventReceiver: sess.EventReceiver,
Dialect: sess.Dialect,
Tx: tx,
Timeout: sess.GetTimeout(),
}, nil
} | [
"func",
"(",
"sess",
"*",
"Session",
")",
"BeginTx",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"*",
"sql",
".",
"TxOptions",
")",
"(",
"*",
"Tx",
",",
"error",
")",
"{",
"tx",
",",
"err",
":=",
"sess",
".",
"Connection",
".",
"BeginTx",
"(",
"ctx",
",",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"sess",
".",
"EventErr",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"sess",
".",
"Event",
"(",
"\"",
"\"",
")",
"\n\n",
"return",
"&",
"Tx",
"{",
"EventReceiver",
":",
"sess",
".",
"EventReceiver",
",",
"Dialect",
":",
"sess",
".",
"Dialect",
",",
"Tx",
":",
"tx",
",",
"Timeout",
":",
"sess",
".",
"GetTimeout",
"(",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // BeginTx creates a transaction with TxOptions. | [
"BeginTx",
"creates",
"a",
"transaction",
"with",
"TxOptions",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/transaction.go#L23-L36 |
150,589 | gocraft/dbr | transaction.go | Begin | func (sess *Session) Begin() (*Tx, error) {
return sess.BeginTx(context.Background(), nil)
} | go | func (sess *Session) Begin() (*Tx, error) {
return sess.BeginTx(context.Background(), nil)
} | [
"func",
"(",
"sess",
"*",
"Session",
")",
"Begin",
"(",
")",
"(",
"*",
"Tx",
",",
"error",
")",
"{",
"return",
"sess",
".",
"BeginTx",
"(",
"context",
".",
"Background",
"(",
")",
",",
"nil",
")",
"\n",
"}"
] | // Begin creates a transaction for the given session. | [
"Begin",
"creates",
"a",
"transaction",
"for",
"the",
"given",
"session",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/transaction.go#L39-L41 |
150,590 | gocraft/dbr | transaction.go | Commit | func (tx *Tx) Commit() error {
err := tx.Tx.Commit()
if err != nil {
return tx.EventErr("dbr.commit.error", err)
}
tx.Event("dbr.commit")
return nil
} | go | func (tx *Tx) Commit() error {
err := tx.Tx.Commit()
if err != nil {
return tx.EventErr("dbr.commit.error", err)
}
tx.Event("dbr.commit")
return nil
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"Commit",
"(",
")",
"error",
"{",
"err",
":=",
"tx",
".",
"Tx",
".",
"Commit",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"tx",
".",
"EventErr",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"tx",
".",
"Event",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Commit finishes the transaction. | [
"Commit",
"finishes",
"the",
"transaction",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/transaction.go#L44-L51 |
150,591 | gocraft/dbr | transaction.go | Rollback | func (tx *Tx) Rollback() error {
err := tx.Tx.Rollback()
if err != nil {
return tx.EventErr("dbr.rollback", err)
}
tx.Event("dbr.rollback")
return nil
} | go | func (tx *Tx) Rollback() error {
err := tx.Tx.Rollback()
if err != nil {
return tx.EventErr("dbr.rollback", err)
}
tx.Event("dbr.rollback")
return nil
} | [
"func",
"(",
"tx",
"*",
"Tx",
")",
"Rollback",
"(",
")",
"error",
"{",
"err",
":=",
"tx",
".",
"Tx",
".",
"Rollback",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"tx",
".",
"EventErr",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"tx",
".",
"Event",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Rollback cancels the transaction. | [
"Rollback",
"cancels",
"the",
"transaction",
"."
] | 48a049970bd235145507f94604005bb7eb9c8bb4 | https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/transaction.go#L54-L61 |
150,592 | ceph/go-ceph | rados/ioctx.go | Stat | func (ioctx *IOContext) Stat(object string) (stat ObjectStat, err error) {
var c_psize C.uint64_t
var c_pmtime C.time_t
c_object := C.CString(object)
defer C.free(unsafe.Pointer(c_object))
ret := C.rados_stat(
ioctx.ioctx,
c_object,
&c_psize,
&c_pmtime)
if ret < 0 {
return ObjectStat{}, GetRadosError(int(ret))
} else {
return ObjectStat{
Size: uint64(c_psize),
ModTime: time.Unix(int64(c_pmtime), 0),
}, nil
}
} | go | func (ioctx *IOContext) Stat(object string) (stat ObjectStat, err error) {
var c_psize C.uint64_t
var c_pmtime C.time_t
c_object := C.CString(object)
defer C.free(unsafe.Pointer(c_object))
ret := C.rados_stat(
ioctx.ioctx,
c_object,
&c_psize,
&c_pmtime)
if ret < 0 {
return ObjectStat{}, GetRadosError(int(ret))
} else {
return ObjectStat{
Size: uint64(c_psize),
ModTime: time.Unix(int64(c_pmtime), 0),
}, nil
}
} | [
"func",
"(",
"ioctx",
"*",
"IOContext",
")",
"Stat",
"(",
"object",
"string",
")",
"(",
"stat",
"ObjectStat",
",",
"err",
"error",
")",
"{",
"var",
"c_psize",
"C",
".",
"uint64_t",
"\n",
"var",
"c_pmtime",
"C",
".",
"time_t",
"\n",
"c_object",
":=",
"C",
".",
"CString",
"(",
"object",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"c_object",
")",
")",
"\n\n",
"ret",
":=",
"C",
".",
"rados_stat",
"(",
"ioctx",
".",
"ioctx",
",",
"c_object",
",",
"&",
"c_psize",
",",
"&",
"c_pmtime",
")",
"\n\n",
"if",
"ret",
"<",
"0",
"{",
"return",
"ObjectStat",
"{",
"}",
",",
"GetRadosError",
"(",
"int",
"(",
"ret",
")",
")",
"\n",
"}",
"else",
"{",
"return",
"ObjectStat",
"{",
"Size",
":",
"uint64",
"(",
"c_psize",
")",
",",
"ModTime",
":",
"time",
".",
"Unix",
"(",
"int64",
"(",
"c_pmtime",
")",
",",
"0",
")",
",",
"}",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // Stat returns the size of the object and its last modification time | [
"Stat",
"returns",
"the",
"size",
"of",
"the",
"object",
"and",
"its",
"last",
"modification",
"time"
] | e32f9f0f2e941422937c0a6c4f0a61b8f0c82995 | https://github.com/ceph/go-ceph/blob/e32f9f0f2e941422937c0a6c4f0a61b8f0c82995/rados/ioctx.go#L264-L284 |
150,593 | ceph/go-ceph | rados/ioctx.go | GetXattr | func (ioctx *IOContext) GetXattr(object string, name string, data []byte) (int, error) {
c_object := C.CString(object)
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_object))
defer C.free(unsafe.Pointer(c_name))
ret := C.rados_getxattr(
ioctx.ioctx,
c_object,
c_name,
(*C.char)(unsafe.Pointer(&data[0])),
(C.size_t)(len(data)))
if ret >= 0 {
return int(ret), nil
} else {
return 0, GetRadosError(int(ret))
}
} | go | func (ioctx *IOContext) GetXattr(object string, name string, data []byte) (int, error) {
c_object := C.CString(object)
c_name := C.CString(name)
defer C.free(unsafe.Pointer(c_object))
defer C.free(unsafe.Pointer(c_name))
ret := C.rados_getxattr(
ioctx.ioctx,
c_object,
c_name,
(*C.char)(unsafe.Pointer(&data[0])),
(C.size_t)(len(data)))
if ret >= 0 {
return int(ret), nil
} else {
return 0, GetRadosError(int(ret))
}
} | [
"func",
"(",
"ioctx",
"*",
"IOContext",
")",
"GetXattr",
"(",
"object",
"string",
",",
"name",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"c_object",
":=",
"C",
".",
"CString",
"(",
"object",
")",
"\n",
"c_name",
":=",
"C",
".",
"CString",
"(",
"name",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"c_object",
")",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"c_name",
")",
")",
"\n\n",
"ret",
":=",
"C",
".",
"rados_getxattr",
"(",
"ioctx",
".",
"ioctx",
",",
"c_object",
",",
"c_name",
",",
"(",
"*",
"C",
".",
"char",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"data",
"[",
"0",
"]",
")",
")",
",",
"(",
"C",
".",
"size_t",
")",
"(",
"len",
"(",
"data",
")",
")",
")",
"\n\n",
"if",
"ret",
">=",
"0",
"{",
"return",
"int",
"(",
"ret",
")",
",",
"nil",
"\n",
"}",
"else",
"{",
"return",
"0",
",",
"GetRadosError",
"(",
"int",
"(",
"ret",
")",
")",
"\n",
"}",
"\n",
"}"
] | // GetXattr gets an xattr with key `name`, it returns the length of
// the key read or an error if not successful | [
"GetXattr",
"gets",
"an",
"xattr",
"with",
"key",
"name",
"it",
"returns",
"the",
"length",
"of",
"the",
"key",
"read",
"or",
"an",
"error",
"if",
"not",
"successful"
] | e32f9f0f2e941422937c0a6c4f0a61b8f0c82995 | https://github.com/ceph/go-ceph/blob/e32f9f0f2e941422937c0a6c4f0a61b8f0c82995/rados/ioctx.go#L288-L306 |
150,594 | ceph/go-ceph | rados/ioctx.go | RmOmapKeys | func (ioctx *IOContext) RmOmapKeys(oid string, keys []string) error {
c_oid := C.CString(oid)
defer C.free(unsafe.Pointer(c_oid))
var c *C.char
ptrSize := unsafe.Sizeof(c)
c_keys := C.malloc(C.size_t(len(keys)) * C.size_t(ptrSize))
defer C.free(unsafe.Pointer(c_keys))
i := 0
for _, key := range keys {
c_key_ptr := (**C.char)(unsafe.Pointer(uintptr(c_keys) + uintptr(i)*ptrSize))
*c_key_ptr = C.CString(key)
defer C.free(unsafe.Pointer(*c_key_ptr))
i++
}
op := C.rados_create_write_op()
C.rados_write_op_omap_rm_keys(
op,
(**C.char)(c_keys),
C.size_t(len(keys)))
ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0)
C.rados_release_write_op(op)
return GetRadosError(int(ret))
} | go | func (ioctx *IOContext) RmOmapKeys(oid string, keys []string) error {
c_oid := C.CString(oid)
defer C.free(unsafe.Pointer(c_oid))
var c *C.char
ptrSize := unsafe.Sizeof(c)
c_keys := C.malloc(C.size_t(len(keys)) * C.size_t(ptrSize))
defer C.free(unsafe.Pointer(c_keys))
i := 0
for _, key := range keys {
c_key_ptr := (**C.char)(unsafe.Pointer(uintptr(c_keys) + uintptr(i)*ptrSize))
*c_key_ptr = C.CString(key)
defer C.free(unsafe.Pointer(*c_key_ptr))
i++
}
op := C.rados_create_write_op()
C.rados_write_op_omap_rm_keys(
op,
(**C.char)(c_keys),
C.size_t(len(keys)))
ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0)
C.rados_release_write_op(op)
return GetRadosError(int(ret))
} | [
"func",
"(",
"ioctx",
"*",
"IOContext",
")",
"RmOmapKeys",
"(",
"oid",
"string",
",",
"keys",
"[",
"]",
"string",
")",
"error",
"{",
"c_oid",
":=",
"C",
".",
"CString",
"(",
"oid",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"c_oid",
")",
")",
"\n\n",
"var",
"c",
"*",
"C",
".",
"char",
"\n",
"ptrSize",
":=",
"unsafe",
".",
"Sizeof",
"(",
"c",
")",
"\n\n",
"c_keys",
":=",
"C",
".",
"malloc",
"(",
"C",
".",
"size_t",
"(",
"len",
"(",
"keys",
")",
")",
"*",
"C",
".",
"size_t",
"(",
"ptrSize",
")",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"c_keys",
")",
")",
"\n\n",
"i",
":=",
"0",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"keys",
"{",
"c_key_ptr",
":=",
"(",
"*",
"*",
"C",
".",
"char",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"uintptr",
"(",
"c_keys",
")",
"+",
"uintptr",
"(",
"i",
")",
"*",
"ptrSize",
")",
")",
"\n",
"*",
"c_key_ptr",
"=",
"C",
".",
"CString",
"(",
"key",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"*",
"c_key_ptr",
")",
")",
"\n",
"i",
"++",
"\n",
"}",
"\n\n",
"op",
":=",
"C",
".",
"rados_create_write_op",
"(",
")",
"\n",
"C",
".",
"rados_write_op_omap_rm_keys",
"(",
"op",
",",
"(",
"*",
"*",
"C",
".",
"char",
")",
"(",
"c_keys",
")",
",",
"C",
".",
"size_t",
"(",
"len",
"(",
"keys",
")",
")",
")",
"\n\n",
"ret",
":=",
"C",
".",
"rados_write_op_operate",
"(",
"op",
",",
"ioctx",
".",
"ioctx",
",",
"c_oid",
",",
"nil",
",",
"0",
")",
"\n",
"C",
".",
"rados_release_write_op",
"(",
"op",
")",
"\n\n",
"return",
"GetRadosError",
"(",
"int",
"(",
"ret",
")",
")",
"\n",
"}"
] | // Remove the specified `keys` from the omap `oid` | [
"Remove",
"the",
"specified",
"keys",
"from",
"the",
"omap",
"oid"
] | e32f9f0f2e941422937c0a6c4f0a61b8f0c82995 | https://github.com/ceph/go-ceph/blob/e32f9f0f2e941422937c0a6c4f0a61b8f0c82995/rados/ioctx.go#L545-L573 |
150,595 | ceph/go-ceph | rados/ioctx.go | CleanOmap | func (ioctx *IOContext) CleanOmap(oid string) error {
c_oid := C.CString(oid)
defer C.free(unsafe.Pointer(c_oid))
op := C.rados_create_write_op()
C.rados_write_op_omap_clear(op)
ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0)
C.rados_release_write_op(op)
return GetRadosError(int(ret))
} | go | func (ioctx *IOContext) CleanOmap(oid string) error {
c_oid := C.CString(oid)
defer C.free(unsafe.Pointer(c_oid))
op := C.rados_create_write_op()
C.rados_write_op_omap_clear(op)
ret := C.rados_write_op_operate(op, ioctx.ioctx, c_oid, nil, 0)
C.rados_release_write_op(op)
return GetRadosError(int(ret))
} | [
"func",
"(",
"ioctx",
"*",
"IOContext",
")",
"CleanOmap",
"(",
"oid",
"string",
")",
"error",
"{",
"c_oid",
":=",
"C",
".",
"CString",
"(",
"oid",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"c_oid",
")",
")",
"\n\n",
"op",
":=",
"C",
".",
"rados_create_write_op",
"(",
")",
"\n",
"C",
".",
"rados_write_op_omap_clear",
"(",
"op",
")",
"\n\n",
"ret",
":=",
"C",
".",
"rados_write_op_operate",
"(",
"op",
",",
"ioctx",
".",
"ioctx",
",",
"c_oid",
",",
"nil",
",",
"0",
")",
"\n",
"C",
".",
"rados_release_write_op",
"(",
"op",
")",
"\n\n",
"return",
"GetRadosError",
"(",
"int",
"(",
"ret",
")",
")",
"\n",
"}"
] | // Clear the omap `oid` | [
"Clear",
"the",
"omap",
"oid"
] | e32f9f0f2e941422937c0a6c4f0a61b8f0c82995 | https://github.com/ceph/go-ceph/blob/e32f9f0f2e941422937c0a6c4f0a61b8f0c82995/rados/ioctx.go#L576-L587 |
150,596 | ceph/go-ceph | rados/ioctx.go | Iter | func (ioctx *IOContext) Iter() (*Iter, error) {
iter := Iter{}
if cerr := C.rados_nobjects_list_open(ioctx.ioctx, &iter.ctx); cerr < 0 {
return nil, GetRadosError(int(cerr))
}
return &iter, nil
} | go | func (ioctx *IOContext) Iter() (*Iter, error) {
iter := Iter{}
if cerr := C.rados_nobjects_list_open(ioctx.ioctx, &iter.ctx); cerr < 0 {
return nil, GetRadosError(int(cerr))
}
return &iter, nil
} | [
"func",
"(",
"ioctx",
"*",
"IOContext",
")",
"Iter",
"(",
")",
"(",
"*",
"Iter",
",",
"error",
")",
"{",
"iter",
":=",
"Iter",
"{",
"}",
"\n",
"if",
"cerr",
":=",
"C",
".",
"rados_nobjects_list_open",
"(",
"ioctx",
".",
"ioctx",
",",
"&",
"iter",
".",
"ctx",
")",
";",
"cerr",
"<",
"0",
"{",
"return",
"nil",
",",
"GetRadosError",
"(",
"int",
"(",
"cerr",
")",
")",
"\n",
"}",
"\n",
"return",
"&",
"iter",
",",
"nil",
"\n",
"}"
] | // Return a Iterator object that can be used to list the object names in the current pool | [
"Return",
"a",
"Iterator",
"object",
"that",
"can",
"be",
"used",
"to",
"list",
"the",
"object",
"names",
"in",
"the",
"current",
"pool"
] | e32f9f0f2e941422937c0a6c4f0a61b8f0c82995 | https://github.com/ceph/go-ceph/blob/e32f9f0f2e941422937c0a6c4f0a61b8f0c82995/rados/ioctx.go#L599-L605 |
150,597 | ceph/go-ceph | rados/ioctx.go | Err | func (iter *Iter) Err() error {
if iter.err == RadosErrorNotFound {
return nil
}
return iter.err
} | go | func (iter *Iter) Err() error {
if iter.err == RadosErrorNotFound {
return nil
}
return iter.err
} | [
"func",
"(",
"iter",
"*",
"Iter",
")",
"Err",
"(",
")",
"error",
"{",
"if",
"iter",
".",
"err",
"==",
"RadosErrorNotFound",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"iter",
".",
"err",
"\n",
"}"
] | // Checks whether the iterator has encountered an error. | [
"Checks",
"whether",
"the",
"iterator",
"has",
"encountered",
"an",
"error",
"."
] | e32f9f0f2e941422937c0a6c4f0a61b8f0c82995 | https://github.com/ceph/go-ceph/blob/e32f9f0f2e941422937c0a6c4f0a61b8f0c82995/rados/ioctx.go#L659-L664 |
150,598 | ceph/go-ceph | rados/ioctx.go | LockExclusive | func (ioctx *IOContext) LockExclusive(oid, name, cookie, desc string, duration time.Duration, flags *byte) (int, error) {
c_oid := C.CString(oid)
c_name := C.CString(name)
c_cookie := C.CString(cookie)
c_desc := C.CString(desc)
var c_duration C.struct_timeval
if duration != 0 {
tv := syscall.NsecToTimeval(duration.Nanoseconds())
c_duration = C.struct_timeval{tv_sec: C.ceph_time_t(tv.Sec), tv_usec: C.ceph_suseconds_t(tv.Usec)}
}
var c_flags C.uint8_t
if flags != nil {
c_flags = C.uint8_t(*flags)
}
defer C.free(unsafe.Pointer(c_oid))
defer C.free(unsafe.Pointer(c_name))
defer C.free(unsafe.Pointer(c_cookie))
defer C.free(unsafe.Pointer(c_desc))
ret := C.rados_lock_exclusive(
ioctx.ioctx,
c_oid,
c_name,
c_cookie,
c_desc,
&c_duration,
c_flags)
// 0 on success, negative error code on failure
// -EBUSY if the lock is already held by another (client, cookie) pair
// -EEXIST if the lock is already held by the same (client, cookie) pair
switch ret {
case 0:
return int(ret), nil
case -C.EBUSY:
return int(ret), nil
case -C.EEXIST:
return int(ret), nil
default:
return int(ret), RadosError(int(ret))
}
} | go | func (ioctx *IOContext) LockExclusive(oid, name, cookie, desc string, duration time.Duration, flags *byte) (int, error) {
c_oid := C.CString(oid)
c_name := C.CString(name)
c_cookie := C.CString(cookie)
c_desc := C.CString(desc)
var c_duration C.struct_timeval
if duration != 0 {
tv := syscall.NsecToTimeval(duration.Nanoseconds())
c_duration = C.struct_timeval{tv_sec: C.ceph_time_t(tv.Sec), tv_usec: C.ceph_suseconds_t(tv.Usec)}
}
var c_flags C.uint8_t
if flags != nil {
c_flags = C.uint8_t(*flags)
}
defer C.free(unsafe.Pointer(c_oid))
defer C.free(unsafe.Pointer(c_name))
defer C.free(unsafe.Pointer(c_cookie))
defer C.free(unsafe.Pointer(c_desc))
ret := C.rados_lock_exclusive(
ioctx.ioctx,
c_oid,
c_name,
c_cookie,
c_desc,
&c_duration,
c_flags)
// 0 on success, negative error code on failure
// -EBUSY if the lock is already held by another (client, cookie) pair
// -EEXIST if the lock is already held by the same (client, cookie) pair
switch ret {
case 0:
return int(ret), nil
case -C.EBUSY:
return int(ret), nil
case -C.EEXIST:
return int(ret), nil
default:
return int(ret), RadosError(int(ret))
}
} | [
"func",
"(",
"ioctx",
"*",
"IOContext",
")",
"LockExclusive",
"(",
"oid",
",",
"name",
",",
"cookie",
",",
"desc",
"string",
",",
"duration",
"time",
".",
"Duration",
",",
"flags",
"*",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"c_oid",
":=",
"C",
".",
"CString",
"(",
"oid",
")",
"\n",
"c_name",
":=",
"C",
".",
"CString",
"(",
"name",
")",
"\n",
"c_cookie",
":=",
"C",
".",
"CString",
"(",
"cookie",
")",
"\n",
"c_desc",
":=",
"C",
".",
"CString",
"(",
"desc",
")",
"\n\n",
"var",
"c_duration",
"C",
".",
"struct_timeval",
"\n",
"if",
"duration",
"!=",
"0",
"{",
"tv",
":=",
"syscall",
".",
"NsecToTimeval",
"(",
"duration",
".",
"Nanoseconds",
"(",
")",
")",
"\n",
"c_duration",
"=",
"C",
".",
"struct_timeval",
"{",
"tv_sec",
":",
"C",
".",
"ceph_time_t",
"(",
"tv",
".",
"Sec",
")",
",",
"tv_usec",
":",
"C",
".",
"ceph_suseconds_t",
"(",
"tv",
".",
"Usec",
")",
"}",
"\n",
"}",
"\n\n",
"var",
"c_flags",
"C",
".",
"uint8_t",
"\n",
"if",
"flags",
"!=",
"nil",
"{",
"c_flags",
"=",
"C",
".",
"uint8_t",
"(",
"*",
"flags",
")",
"\n",
"}",
"\n\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"c_oid",
")",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"c_name",
")",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"c_cookie",
")",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"c_desc",
")",
")",
"\n\n",
"ret",
":=",
"C",
".",
"rados_lock_exclusive",
"(",
"ioctx",
".",
"ioctx",
",",
"c_oid",
",",
"c_name",
",",
"c_cookie",
",",
"c_desc",
",",
"&",
"c_duration",
",",
"c_flags",
")",
"\n\n",
"// 0 on success, negative error code on failure",
"// -EBUSY if the lock is already held by another (client, cookie) pair",
"// -EEXIST if the lock is already held by the same (client, cookie) pair",
"switch",
"ret",
"{",
"case",
"0",
":",
"return",
"int",
"(",
"ret",
")",
",",
"nil",
"\n",
"case",
"-",
"C",
".",
"EBUSY",
":",
"return",
"int",
"(",
"ret",
")",
",",
"nil",
"\n",
"case",
"-",
"C",
".",
"EEXIST",
":",
"return",
"int",
"(",
"ret",
")",
",",
"nil",
"\n",
"default",
":",
"return",
"int",
"(",
"ret",
")",
",",
"RadosError",
"(",
"int",
"(",
"ret",
")",
")",
"\n",
"}",
"\n",
"}"
] | // Take an exclusive lock on an object. | [
"Take",
"an",
"exclusive",
"lock",
"on",
"an",
"object",
"."
] | e32f9f0f2e941422937c0a6c4f0a61b8f0c82995 | https://github.com/ceph/go-ceph/blob/e32f9f0f2e941422937c0a6c4f0a61b8f0c82995/rados/ioctx.go#L673-L718 |
150,599 | ceph/go-ceph | rados/ioctx.go | Unlock | func (ioctx *IOContext) Unlock(oid, name, cookie string) (int, error) {
c_oid := C.CString(oid)
c_name := C.CString(name)
c_cookie := C.CString(cookie)
defer C.free(unsafe.Pointer(c_oid))
defer C.free(unsafe.Pointer(c_name))
defer C.free(unsafe.Pointer(c_cookie))
// 0 on success, negative error code on failure
// -ENOENT if the lock is not held by the specified (client, cookie) pair
ret := C.rados_unlock(
ioctx.ioctx,
c_oid,
c_name,
c_cookie)
switch ret {
case 0:
return int(ret), nil
case -C.ENOENT:
return int(ret), nil
default:
return int(ret), RadosError(int(ret))
}
} | go | func (ioctx *IOContext) Unlock(oid, name, cookie string) (int, error) {
c_oid := C.CString(oid)
c_name := C.CString(name)
c_cookie := C.CString(cookie)
defer C.free(unsafe.Pointer(c_oid))
defer C.free(unsafe.Pointer(c_name))
defer C.free(unsafe.Pointer(c_cookie))
// 0 on success, negative error code on failure
// -ENOENT if the lock is not held by the specified (client, cookie) pair
ret := C.rados_unlock(
ioctx.ioctx,
c_oid,
c_name,
c_cookie)
switch ret {
case 0:
return int(ret), nil
case -C.ENOENT:
return int(ret), nil
default:
return int(ret), RadosError(int(ret))
}
} | [
"func",
"(",
"ioctx",
"*",
"IOContext",
")",
"Unlock",
"(",
"oid",
",",
"name",
",",
"cookie",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"c_oid",
":=",
"C",
".",
"CString",
"(",
"oid",
")",
"\n",
"c_name",
":=",
"C",
".",
"CString",
"(",
"name",
")",
"\n",
"c_cookie",
":=",
"C",
".",
"CString",
"(",
"cookie",
")",
"\n\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"c_oid",
")",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"c_name",
")",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"c_cookie",
")",
")",
"\n\n",
"// 0 on success, negative error code on failure",
"// -ENOENT if the lock is not held by the specified (client, cookie) pair",
"ret",
":=",
"C",
".",
"rados_unlock",
"(",
"ioctx",
".",
"ioctx",
",",
"c_oid",
",",
"c_name",
",",
"c_cookie",
")",
"\n\n",
"switch",
"ret",
"{",
"case",
"0",
":",
"return",
"int",
"(",
"ret",
")",
",",
"nil",
"\n",
"case",
"-",
"C",
".",
"ENOENT",
":",
"return",
"int",
"(",
"ret",
")",
",",
"nil",
"\n",
"default",
":",
"return",
"int",
"(",
"ret",
")",
",",
"RadosError",
"(",
"int",
"(",
"ret",
")",
")",
"\n",
"}",
"\n",
"}"
] | // Release a shared or exclusive lock on an object. | [
"Release",
"a",
"shared",
"or",
"exclusive",
"lock",
"on",
"an",
"object",
"."
] | e32f9f0f2e941422937c0a6c4f0a61b8f0c82995 | https://github.com/ceph/go-ceph/blob/e32f9f0f2e941422937c0a6c4f0a61b8f0c82995/rados/ioctx.go#L772-L798 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.