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
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
mattn/go-oci8
statement.go
ociStmtExecute
func (stmt *OCI8Stmt) ociStmtExecute(iters C.ub4, mode C.ub4) error { result := C.OCIStmtExecute( stmt.conn.svc, // Service context handle stmt.stmt, // A statement handle stmt.conn.errHandle, // An error handle iters, // For non-SELECT statements, the number of times this statement is executed equals iters - rowoff. For SELECT statements, if iters is nonzero, then defines must have been done for the statement handle. 0, // The starting index from which the data in an array bind is relevant for this multiple row execution nil, // This parameter is optional. If it is supplied, it must point to a snapshot descriptor of type OCI_DTYPE_SNAP nil, // This parameter is optional. If it is supplied, it must point to a descriptor of type OCI_DTYPE_SNAP. mode, // The mode: https://docs.oracle.com/cd/E11882_01/appdev.112/e10646/oci17msc001.htm#LNOCI17163 ) return stmt.conn.getError(result) }
go
func (stmt *OCI8Stmt) ociStmtExecute(iters C.ub4, mode C.ub4) error { result := C.OCIStmtExecute( stmt.conn.svc, // Service context handle stmt.stmt, // A statement handle stmt.conn.errHandle, // An error handle iters, // For non-SELECT statements, the number of times this statement is executed equals iters - rowoff. For SELECT statements, if iters is nonzero, then defines must have been done for the statement handle. 0, // The starting index from which the data in an array bind is relevant for this multiple row execution nil, // This parameter is optional. If it is supplied, it must point to a snapshot descriptor of type OCI_DTYPE_SNAP nil, // This parameter is optional. If it is supplied, it must point to a descriptor of type OCI_DTYPE_SNAP. mode, // The mode: https://docs.oracle.com/cd/E11882_01/appdev.112/e10646/oci17msc001.htm#LNOCI17163 ) return stmt.conn.getError(result) }
[ "func", "(", "stmt", "*", "OCI8Stmt", ")", "ociStmtExecute", "(", "iters", "C", ".", "ub4", ",", "mode", "C", ".", "ub4", ")", "error", "{", "result", ":=", "C", ".", "OCIStmtExecute", "(", "stmt", ".", "conn", ".", "svc", ",", "// Service context hand...
// ociStmtExecute calls OCIStmtExecute
[ "ociStmtExecute", "calls", "OCIStmtExecute" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/statement.go#L898-L911
train
mattn/go-oci8
statement.go
ociBreak
func (stmt *OCI8Stmt) ociBreak(ctx context.Context, done chan struct{}) { select { case <-done: case <-ctx.Done(): // select again to avoid race condition if both are done select { case <-done: default: result := C.OCIBreak( unsafe.Pointer(stmt.conn.svc), // The service context handle or the server context handle. stmt.conn.errHandle, // An error handle ) err := stmt.conn.getError(result) if err != nil { stmt.conn.logger.Print("OCIBreak error: ", err) } } } }
go
func (stmt *OCI8Stmt) ociBreak(ctx context.Context, done chan struct{}) { select { case <-done: case <-ctx.Done(): // select again to avoid race condition if both are done select { case <-done: default: result := C.OCIBreak( unsafe.Pointer(stmt.conn.svc), // The service context handle or the server context handle. stmt.conn.errHandle, // An error handle ) err := stmt.conn.getError(result) if err != nil { stmt.conn.logger.Print("OCIBreak error: ", err) } } } }
[ "func", "(", "stmt", "*", "OCI8Stmt", ")", "ociBreak", "(", "ctx", "context", ".", "Context", ",", "done", "chan", "struct", "{", "}", ")", "{", "select", "{", "case", "<-", "done", ":", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "// select a...
// ociBreak calls OCIBreak if ctx.Done is finished before done chan is closed
[ "ociBreak", "calls", "OCIBreak", "if", "ctx", ".", "Done", "is", "finished", "before", "done", "chan", "is", "closed" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/statement.go#L914-L932
train
mattn/go-oci8
connection.go
Exec
func (conn *OCI8Conn) Exec(query string, args []driver.Value) (driver.Result, error) { list := make([]namedValue, len(args)) for i, v := range args { list[i] = namedValue{ Ordinal: i + 1, Value: v, } } return conn.exec(context.Background(), query, list) }
go
func (conn *OCI8Conn) Exec(query string, args []driver.Value) (driver.Result, error) { list := make([]namedValue, len(args)) for i, v := range args { list[i] = namedValue{ Ordinal: i + 1, Value: v, } } return conn.exec(context.Background(), query, list) }
[ "func", "(", "conn", "*", "OCI8Conn", ")", "Exec", "(", "query", "string", ",", "args", "[", "]", "driver", ".", "Value", ")", "(", "driver", ".", "Result", ",", "error", ")", "{", "list", ":=", "make", "(", "[", "]", "namedValue", ",", "len", "(...
// Exec executes a query
[ "Exec", "executes", "a", "query" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/connection.go#L16-L25
train
mattn/go-oci8
connection.go
Ping
func (conn *OCI8Conn) Ping(ctx context.Context) error { result := C.OCIPing(conn.svc, conn.errHandle, C.OCI_DEFAULT) if result == C.OCI_SUCCESS || result == C.OCI_SUCCESS_WITH_INFO { return nil } errorCode, err := conn.ociGetError() if errorCode == 1010 { // Older versions of Oracle do not support ping, // but a response of "ORA-01010: invalid OCI operation" confirms connectivity. // See https://github.com/rana/ora/issues/224 return nil } conn.logger.Print("Ping error: ", err) return driver.ErrBadConn }
go
func (conn *OCI8Conn) Ping(ctx context.Context) error { result := C.OCIPing(conn.svc, conn.errHandle, C.OCI_DEFAULT) if result == C.OCI_SUCCESS || result == C.OCI_SUCCESS_WITH_INFO { return nil } errorCode, err := conn.ociGetError() if errorCode == 1010 { // Older versions of Oracle do not support ping, // but a response of "ORA-01010: invalid OCI operation" confirms connectivity. // See https://github.com/rana/ora/issues/224 return nil } conn.logger.Print("Ping error: ", err) return driver.ErrBadConn }
[ "func", "(", "conn", "*", "OCI8Conn", ")", "Ping", "(", "ctx", "context", ".", "Context", ")", "error", "{", "result", ":=", "C", ".", "OCIPing", "(", "conn", ".", "svc", ",", "conn", ".", "errHandle", ",", "C", ".", "OCI_DEFAULT", ")", "\n", "if",...
// Ping database connection
[ "Ping", "database", "connection" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/connection.go#L54-L69
train
mattn/go-oci8
connection.go
Begin
func (conn *OCI8Conn) Begin() (driver.Tx, error) { return conn.BeginTx(context.Background(), driver.TxOptions{}) }
go
func (conn *OCI8Conn) Begin() (driver.Tx, error) { return conn.BeginTx(context.Background(), driver.TxOptions{}) }
[ "func", "(", "conn", "*", "OCI8Conn", ")", "Begin", "(", ")", "(", "driver", ".", "Tx", ",", "error", ")", "{", "return", "conn", ".", "BeginTx", "(", "context", ".", "Background", "(", ")", ",", "driver", ".", "TxOptions", "{", "}", ")", "\n", "...
// Begin starts a transaction
[ "Begin", "starts", "a", "transaction" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/connection.go#L72-L74
train
mattn/go-oci8
connection.go
BeginTx
func (conn *OCI8Conn) BeginTx(ctx context.Context, txOptions driver.TxOptions) (driver.Tx, error) { if conn.transactionMode != C.OCI_TRANS_READWRITE { // transaction handle trans, _, err := conn.ociHandleAlloc(C.OCI_HTYPE_TRANS, 0) if err != nil { return nil, fmt.Errorf("allocate transaction handle error: %v", err) } // sets the transaction context attribute of the service context err = conn.ociAttrSet(unsafe.Pointer(conn.svc), C.OCI_HTYPE_SVCCTX, *trans, 0, C.OCI_ATTR_TRANS) if err != nil { C.OCIHandleFree(*trans, C.OCI_HTYPE_TRANS) return nil, err } // transaction handle should be freed by something once attached to the service context // but I cannot find anything in the documentation explicitly calling this out // going by examples: https://docs.oracle.com/cd/B28359_01/appdev.111/b28395/oci17msc006.htm#i428845 if rv := C.OCITransStart( conn.svc, conn.errHandle, 0, conn.transactionMode, // mode is: C.OCI_TRANS_SERIALIZABLE, C.OCI_TRANS_READWRITE, or C.OCI_TRANS_READONLY ); rv != C.OCI_SUCCESS { return nil, conn.getError(rv) } } conn.inTransaction = true return &OCI8Tx{conn}, nil }
go
func (conn *OCI8Conn) BeginTx(ctx context.Context, txOptions driver.TxOptions) (driver.Tx, error) { if conn.transactionMode != C.OCI_TRANS_READWRITE { // transaction handle trans, _, err := conn.ociHandleAlloc(C.OCI_HTYPE_TRANS, 0) if err != nil { return nil, fmt.Errorf("allocate transaction handle error: %v", err) } // sets the transaction context attribute of the service context err = conn.ociAttrSet(unsafe.Pointer(conn.svc), C.OCI_HTYPE_SVCCTX, *trans, 0, C.OCI_ATTR_TRANS) if err != nil { C.OCIHandleFree(*trans, C.OCI_HTYPE_TRANS) return nil, err } // transaction handle should be freed by something once attached to the service context // but I cannot find anything in the documentation explicitly calling this out // going by examples: https://docs.oracle.com/cd/B28359_01/appdev.111/b28395/oci17msc006.htm#i428845 if rv := C.OCITransStart( conn.svc, conn.errHandle, 0, conn.transactionMode, // mode is: C.OCI_TRANS_SERIALIZABLE, C.OCI_TRANS_READWRITE, or C.OCI_TRANS_READONLY ); rv != C.OCI_SUCCESS { return nil, conn.getError(rv) } } conn.inTransaction = true return &OCI8Tx{conn}, nil }
[ "func", "(", "conn", "*", "OCI8Conn", ")", "BeginTx", "(", "ctx", "context", ".", "Context", ",", "txOptions", "driver", ".", "TxOptions", ")", "(", "driver", ".", "Tx", ",", "error", ")", "{", "if", "conn", ".", "transactionMode", "!=", "C", ".", "O...
// BeginTx starts a transaction
[ "BeginTx", "starts", "a", "transaction" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/connection.go#L77-L110
train
mattn/go-oci8
connection.go
Prepare
func (conn *OCI8Conn) Prepare(query string) (driver.Stmt, error) { return conn.PrepareContext(context.Background(), query) }
go
func (conn *OCI8Conn) Prepare(query string) (driver.Stmt, error) { return conn.PrepareContext(context.Background(), query) }
[ "func", "(", "conn", "*", "OCI8Conn", ")", "Prepare", "(", "query", "string", ")", "(", "driver", ".", "Stmt", ",", "error", ")", "{", "return", "conn", ".", "PrepareContext", "(", "context", ".", "Background", "(", ")", ",", "query", ")", "\n", "}" ...
// Prepare prepares a query
[ "Prepare", "prepares", "a", "query" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/connection.go#L160-L162
train
mattn/go-oci8
connection.go
PrepareContext
func (conn *OCI8Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) { if conn.enableQMPlaceholders { query = placeholders(query) } queryP := cString(query) defer C.free(unsafe.Pointer(queryP)) // statement handle stmt, _, err := conn.ociHandleAlloc(C.OCI_HTYPE_STMT, 0) if err != nil { return nil, fmt.Errorf("allocate statement handle error: %v", err) } if rv := C.OCIStmtPrepare( (*C.OCIStmt)(*stmt), conn.errHandle, queryP, C.ub4(len(query)), C.ub4(C.OCI_NTV_SYNTAX), C.ub4(C.OCI_DEFAULT), ); rv != C.OCI_SUCCESS { C.OCIHandleFree(*stmt, C.OCI_HTYPE_STMT) return nil, conn.getError(rv) } return &OCI8Stmt{conn: conn, stmt: (*C.OCIStmt)(*stmt)}, nil }
go
func (conn *OCI8Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) { if conn.enableQMPlaceholders { query = placeholders(query) } queryP := cString(query) defer C.free(unsafe.Pointer(queryP)) // statement handle stmt, _, err := conn.ociHandleAlloc(C.OCI_HTYPE_STMT, 0) if err != nil { return nil, fmt.Errorf("allocate statement handle error: %v", err) } if rv := C.OCIStmtPrepare( (*C.OCIStmt)(*stmt), conn.errHandle, queryP, C.ub4(len(query)), C.ub4(C.OCI_NTV_SYNTAX), C.ub4(C.OCI_DEFAULT), ); rv != C.OCI_SUCCESS { C.OCIHandleFree(*stmt, C.OCI_HTYPE_STMT) return nil, conn.getError(rv) } return &OCI8Stmt{conn: conn, stmt: (*C.OCIStmt)(*stmt)}, nil }
[ "func", "(", "conn", "*", "OCI8Conn", ")", "PrepareContext", "(", "ctx", "context", ".", "Context", ",", "query", "string", ")", "(", "driver", ".", "Stmt", ",", "error", ")", "{", "if", "conn", ".", "enableQMPlaceholders", "{", "query", "=", "placeholde...
// PrepareContext prepares a query
[ "PrepareContext", "prepares", "a", "query" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/connection.go#L165-L192
train
mattn/go-oci8
connection.go
ociGetError
func (conn *OCI8Conn) ociGetError() (int, error) { var errorCode C.sb4 errorText := make([]byte, 1024) result := C.OCIErrorGet( unsafe.Pointer(conn.errHandle), // error handle 1, // status record number, starts from 1 nil, // sqlstate, not supported in release 8.x or later &errorCode, // error code (*C.OraText)(&errorText[0]), // error message text 1024, // size of the buffer provided in number of bytes C.OCI_HTYPE_ERROR, // type of the handle (OCI_HTYPE_ERR or OCI_HTYPE_ENV) ) if result != C.OCI_SUCCESS { return 3114, errors.New("OCIErrorGet failed") } index := bytes.IndexByte(errorText, 0) return int(errorCode), errors.New(string(errorText[:index])) }
go
func (conn *OCI8Conn) ociGetError() (int, error) { var errorCode C.sb4 errorText := make([]byte, 1024) result := C.OCIErrorGet( unsafe.Pointer(conn.errHandle), // error handle 1, // status record number, starts from 1 nil, // sqlstate, not supported in release 8.x or later &errorCode, // error code (*C.OraText)(&errorText[0]), // error message text 1024, // size of the buffer provided in number of bytes C.OCI_HTYPE_ERROR, // type of the handle (OCI_HTYPE_ERR or OCI_HTYPE_ENV) ) if result != C.OCI_SUCCESS { return 3114, errors.New("OCIErrorGet failed") } index := bytes.IndexByte(errorText, 0) return int(errorCode), errors.New(string(errorText[:index])) }
[ "func", "(", "conn", "*", "OCI8Conn", ")", "ociGetError", "(", ")", "(", "int", ",", "error", ")", "{", "var", "errorCode", "C", ".", "sb4", "\n", "errorText", ":=", "make", "(", "[", "]", "byte", ",", "1024", ")", "\n\n", "result", ":=", "C", "....
// ociGetError calls OCIErrorGet then returs error code and text
[ "ociGetError", "calls", "OCIErrorGet", "then", "returs", "error", "code", "and", "text" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/connection.go#L236-L256
train
mattn/go-oci8
connection.go
ociAttrGet
func (conn *OCI8Conn) ociAttrGet(paramHandle *C.OCIParam, value unsafe.Pointer, attributeType C.ub4) (C.ub4, error) { var size C.ub4 result := C.OCIAttrGet( unsafe.Pointer(paramHandle), // Pointer to a handle type C.OCI_DTYPE_PARAM, // The handle type: OCI_DTYPE_PARAM, for a parameter descriptor value, // Pointer to the storage for an attribute value &size, // The size of the attribute value attributeType, // The attribute type: https://docs.oracle.com/cd/B19306_01/appdev.102/b14250/ociaahan.htm conn.errHandle, // An error handle ) return size, conn.getError(result) }
go
func (conn *OCI8Conn) ociAttrGet(paramHandle *C.OCIParam, value unsafe.Pointer, attributeType C.ub4) (C.ub4, error) { var size C.ub4 result := C.OCIAttrGet( unsafe.Pointer(paramHandle), // Pointer to a handle type C.OCI_DTYPE_PARAM, // The handle type: OCI_DTYPE_PARAM, for a parameter descriptor value, // Pointer to the storage for an attribute value &size, // The size of the attribute value attributeType, // The attribute type: https://docs.oracle.com/cd/B19306_01/appdev.102/b14250/ociaahan.htm conn.errHandle, // An error handle ) return size, conn.getError(result) }
[ "func", "(", "conn", "*", "OCI8Conn", ")", "ociAttrGet", "(", "paramHandle", "*", "C", ".", "OCIParam", ",", "value", "unsafe", ".", "Pointer", ",", "attributeType", "C", ".", "ub4", ")", "(", "C", ".", "ub4", ",", "error", ")", "{", "var", "size", ...
// ociAttrGet calls OCIAttrGet with OCIParam then returns attribute size and error. // The attribute value is stored into passed value.
[ "ociAttrGet", "calls", "OCIAttrGet", "with", "OCIParam", "then", "returns", "attribute", "size", "and", "error", ".", "The", "attribute", "value", "is", "stored", "into", "passed", "value", "." ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/connection.go#L260-L273
train
mattn/go-oci8
connection.go
ociAttrSet
func (conn *OCI8Conn) ociAttrSet( handle unsafe.Pointer, handleType C.ub4, value unsafe.Pointer, valueSize C.ub4, attributeType C.ub4, ) error { result := C.OCIAttrSet( handle, // Pointer to a handle whose attribute gets modified handleType, // The handle type value, // Pointer to an attribute value valueSize, // The size of an attribute value attributeType, // The type of attribute being set conn.errHandle, // An error handle ) return conn.getError(result) }
go
func (conn *OCI8Conn) ociAttrSet( handle unsafe.Pointer, handleType C.ub4, value unsafe.Pointer, valueSize C.ub4, attributeType C.ub4, ) error { result := C.OCIAttrSet( handle, // Pointer to a handle whose attribute gets modified handleType, // The handle type value, // Pointer to an attribute value valueSize, // The size of an attribute value attributeType, // The type of attribute being set conn.errHandle, // An error handle ) return conn.getError(result) }
[ "func", "(", "conn", "*", "OCI8Conn", ")", "ociAttrSet", "(", "handle", "unsafe", ".", "Pointer", ",", "handleType", "C", ".", "ub4", ",", "value", "unsafe", ".", "Pointer", ",", "valueSize", "C", ".", "ub4", ",", "attributeType", "C", ".", "ub4", ",",...
// ociAttrSet calls OCIAttrSet. // Only uses errHandle from conn, so can be called in conn setup after errHandle has been set.
[ "ociAttrSet", "calls", "OCIAttrSet", ".", "Only", "uses", "errHandle", "from", "conn", "so", "can", "be", "called", "in", "conn", "setup", "after", "errHandle", "has", "been", "set", "." ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/connection.go#L277-L294
train
mattn/go-oci8
connection.go
ociHandleAlloc
func (conn *OCI8Conn) ociHandleAlloc(handleType C.ub4, size C.size_t) (*unsafe.Pointer, *unsafe.Pointer, error) { var handleTemp unsafe.Pointer handle := &handleTemp var bufferTemp unsafe.Pointer var buffer *unsafe.Pointer if size > 0 { buffer = &bufferTemp } result := C.OCIHandleAlloc( unsafe.Pointer(conn.env), // An environment handle handle, // Returns a handle handleType, // type of handle: https://docs.oracle.com/cd/B28359_01/appdev.111/b28395/oci02bas.htm#LNOCI87581 size, // amount of user memory to be allocated buffer, // Returns a pointer to the user memory ) err := conn.getError(result) if err != nil { return nil, nil, err } if size > 0 { return handle, buffer, nil } return handle, nil, nil }
go
func (conn *OCI8Conn) ociHandleAlloc(handleType C.ub4, size C.size_t) (*unsafe.Pointer, *unsafe.Pointer, error) { var handleTemp unsafe.Pointer handle := &handleTemp var bufferTemp unsafe.Pointer var buffer *unsafe.Pointer if size > 0 { buffer = &bufferTemp } result := C.OCIHandleAlloc( unsafe.Pointer(conn.env), // An environment handle handle, // Returns a handle handleType, // type of handle: https://docs.oracle.com/cd/B28359_01/appdev.111/b28395/oci02bas.htm#LNOCI87581 size, // amount of user memory to be allocated buffer, // Returns a pointer to the user memory ) err := conn.getError(result) if err != nil { return nil, nil, err } if size > 0 { return handle, buffer, nil } return handle, nil, nil }
[ "func", "(", "conn", "*", "OCI8Conn", ")", "ociHandleAlloc", "(", "handleType", "C", ".", "ub4", ",", "size", "C", ".", "size_t", ")", "(", "*", "unsafe", ".", "Pointer", ",", "*", "unsafe", ".", "Pointer", ",", "error", ")", "{", "var", "handleTemp"...
// ociHandleAlloc calls OCIHandleAlloc then returns // handle pointer to pointer, buffer pointer to pointer, and error
[ "ociHandleAlloc", "calls", "OCIHandleAlloc", "then", "returns", "handle", "pointer", "to", "pointer", "buffer", "pointer", "to", "pointer", "and", "error" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/connection.go#L298-L325
train
mattn/go-oci8
connection.go
ociDescriptorAlloc
func (conn *OCI8Conn) ociDescriptorAlloc(descriptorType C.ub4, size C.size_t) (*unsafe.Pointer, *unsafe.Pointer, error) { var descriptorTemp unsafe.Pointer descriptor := &descriptorTemp var bufferTemp unsafe.Pointer var buffer *unsafe.Pointer if size > 0 { buffer = &bufferTemp } result := C.OCIDescriptorAlloc( unsafe.Pointer(conn.env), // An environment handle descriptor, // Returns a descriptor or LOB locator of desired type descriptorType, // Specifies the type of descriptor or LOB locator to be allocated size, // Specifies an amount of user memory to be allocated for use by the application for the lifetime of the descriptor buffer, // Returns a pointer to the user memory of size xtramem_sz allocated by the call for the user for the lifetime of the descriptor ) err := conn.getError(result) if err != nil { return nil, nil, err } if size > 0 { return descriptor, buffer, nil } return descriptor, nil, nil }
go
func (conn *OCI8Conn) ociDescriptorAlloc(descriptorType C.ub4, size C.size_t) (*unsafe.Pointer, *unsafe.Pointer, error) { var descriptorTemp unsafe.Pointer descriptor := &descriptorTemp var bufferTemp unsafe.Pointer var buffer *unsafe.Pointer if size > 0 { buffer = &bufferTemp } result := C.OCIDescriptorAlloc( unsafe.Pointer(conn.env), // An environment handle descriptor, // Returns a descriptor or LOB locator of desired type descriptorType, // Specifies the type of descriptor or LOB locator to be allocated size, // Specifies an amount of user memory to be allocated for use by the application for the lifetime of the descriptor buffer, // Returns a pointer to the user memory of size xtramem_sz allocated by the call for the user for the lifetime of the descriptor ) err := conn.getError(result) if err != nil { return nil, nil, err } if size > 0 { return descriptor, buffer, nil } return descriptor, nil, nil }
[ "func", "(", "conn", "*", "OCI8Conn", ")", "ociDescriptorAlloc", "(", "descriptorType", "C", ".", "ub4", ",", "size", "C", ".", "size_t", ")", "(", "*", "unsafe", ".", "Pointer", ",", "*", "unsafe", ".", "Pointer", ",", "error", ")", "{", "var", "des...
// ociDescriptorAlloc calls OCIDescriptorAlloc then returns // descriptor pointer to pointer, buffer pointer to pointer, and error
[ "ociDescriptorAlloc", "calls", "OCIDescriptorAlloc", "then", "returns", "descriptor", "pointer", "to", "pointer", "buffer", "pointer", "to", "pointer", "and", "error" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/connection.go#L329-L356
train
mattn/go-oci8
connection.go
ociLobRead
func (conn *OCI8Conn) ociLobRead(lobLocator *C.OCILobLocator, form C.ub1) ([]byte, error) { readBuffer := make([]byte, lobBufferSize) buffer := make([]byte, 0) result := (C.sword)(C.OCI_NEED_DATA) piece := (C.ub1)(C.OCI_FIRST_PIECE) for result == C.OCI_NEED_DATA { readBytes := (C.oraub8)(0) // If both byte_amtp and char_amtp are set to point to zero and OCI_FIRST_PIECE is passed then polling mode is assumed and data is read till the end of the LOB result = C.OCILobRead2( conn.svc, // service context handle conn.errHandle, // error handle lobLocator, // LOB or BFILE locator &readBytes, // number of bytes to read. Used for BLOB and BFILE always. For CLOB and NCLOB, it is used only when char_amtp is zero. nil, // number of characters to read 1, // the offset in the first call and in subsequent polling calls the offset parameter is ignored unsafe.Pointer(&readBuffer[0]), // pointer to a buffer into which the piece will be read lobBufferSize, // length of the buffer piece, // For polling, pass OCI_FIRST_PIECE the first time and OCI_NEXT_PIECE in subsequent calls. nil, // context pointer for the callback function nil, // If this is null, then OCI_NEED_DATA will be returned for each piece. 0, // character set ID of the buffer data. If this value is 0 then csid is set to the client's NLS_LANG or NLS_CHAR value, depending on the value of csfrm. form, // character set form of the buffer data ) if piece == C.OCI_FIRST_PIECE { piece = C.OCI_NEXT_PIECE } if result == C.OCI_SUCCESS || result == C.OCI_NEED_DATA { buffer = append(buffer, readBuffer[:int(readBytes)]...) } } return buffer, conn.getError(result) }
go
func (conn *OCI8Conn) ociLobRead(lobLocator *C.OCILobLocator, form C.ub1) ([]byte, error) { readBuffer := make([]byte, lobBufferSize) buffer := make([]byte, 0) result := (C.sword)(C.OCI_NEED_DATA) piece := (C.ub1)(C.OCI_FIRST_PIECE) for result == C.OCI_NEED_DATA { readBytes := (C.oraub8)(0) // If both byte_amtp and char_amtp are set to point to zero and OCI_FIRST_PIECE is passed then polling mode is assumed and data is read till the end of the LOB result = C.OCILobRead2( conn.svc, // service context handle conn.errHandle, // error handle lobLocator, // LOB or BFILE locator &readBytes, // number of bytes to read. Used for BLOB and BFILE always. For CLOB and NCLOB, it is used only when char_amtp is zero. nil, // number of characters to read 1, // the offset in the first call and in subsequent polling calls the offset parameter is ignored unsafe.Pointer(&readBuffer[0]), // pointer to a buffer into which the piece will be read lobBufferSize, // length of the buffer piece, // For polling, pass OCI_FIRST_PIECE the first time and OCI_NEXT_PIECE in subsequent calls. nil, // context pointer for the callback function nil, // If this is null, then OCI_NEED_DATA will be returned for each piece. 0, // character set ID of the buffer data. If this value is 0 then csid is set to the client's NLS_LANG or NLS_CHAR value, depending on the value of csfrm. form, // character set form of the buffer data ) if piece == C.OCI_FIRST_PIECE { piece = C.OCI_NEXT_PIECE } if result == C.OCI_SUCCESS || result == C.OCI_NEED_DATA { buffer = append(buffer, readBuffer[:int(readBytes)]...) } } return buffer, conn.getError(result) }
[ "func", "(", "conn", "*", "OCI8Conn", ")", "ociLobRead", "(", "lobLocator", "*", "C", ".", "OCILobLocator", ",", "form", "C", ".", "ub1", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "readBuffer", ":=", "make", "(", "[", "]", "byte", ",", ...
// ociLobRead calls OCILobRead then returns lob bytes and error.
[ "ociLobRead", "calls", "OCILobRead", "then", "returns", "lob", "bytes", "and", "error", "." ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/connection.go#L359-L395
train
mattn/go-oci8
connector.go
NewConnector
func NewConnector(hosts ...string) driver.Connector { return &OCI8Connector{ Logger: log.New(ioutil.Discard, "", 0), } }
go
func NewConnector(hosts ...string) driver.Connector { return &OCI8Connector{ Logger: log.New(ioutil.Discard, "", 0), } }
[ "func", "NewConnector", "(", "hosts", "...", "string", ")", "driver", ".", "Connector", "{", "return", "&", "OCI8Connector", "{", "Logger", ":", "log", ".", "New", "(", "ioutil", ".", "Discard", ",", "\"", "\"", ",", "0", ")", ",", "}", "\n", "}" ]
// NewConnector returns a new database connector
[ "NewConnector", "returns", "a", "new", "database", "connector" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/connector.go#L13-L17
train
mattn/go-oci8
connector.go
Connect
func (oci8Connector *OCI8Connector) Connect(ctx context.Context) (driver.Conn, error) { oci8Conn := &OCI8Conn{ logger: oci8Connector.Logger, } if oci8Conn.logger == nil { oci8Conn.logger = log.New(ioutil.Discard, "", 0) } return oci8Conn, nil }
go
func (oci8Connector *OCI8Connector) Connect(ctx context.Context) (driver.Conn, error) { oci8Conn := &OCI8Conn{ logger: oci8Connector.Logger, } if oci8Conn.logger == nil { oci8Conn.logger = log.New(ioutil.Discard, "", 0) } return oci8Conn, nil }
[ "func", "(", "oci8Connector", "*", "OCI8Connector", ")", "Connect", "(", "ctx", "context", ".", "Context", ")", "(", "driver", ".", "Conn", ",", "error", ")", "{", "oci8Conn", ":=", "&", "OCI8Conn", "{", "logger", ":", "oci8Connector", ".", "Logger", ","...
// Connect returns a new database connection
[ "Connect", "returns", "a", "new", "database", "connection" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/connector.go#L25-L34
train
mattn/go-oci8
oci8.go
Commit
func (tx *OCI8Tx) Commit() error { tx.conn.inTransaction = false if rv := C.OCITransCommit( tx.conn.svc, tx.conn.errHandle, 0, ); rv != C.OCI_SUCCESS { return tx.conn.getError(rv) } return nil }
go
func (tx *OCI8Tx) Commit() error { tx.conn.inTransaction = false if rv := C.OCITransCommit( tx.conn.svc, tx.conn.errHandle, 0, ); rv != C.OCI_SUCCESS { return tx.conn.getError(rv) } return nil }
[ "func", "(", "tx", "*", "OCI8Tx", ")", "Commit", "(", ")", "error", "{", "tx", ".", "conn", ".", "inTransaction", "=", "false", "\n", "if", "rv", ":=", "C", ".", "OCITransCommit", "(", "tx", ".", "conn", ".", "svc", ",", "tx", ".", "conn", ".", ...
// Commit transaction commit
[ "Commit", "transaction", "commit" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/oci8.go#L130-L140
train
mattn/go-oci8
oci8.go
Rollback
func (tx *OCI8Tx) Rollback() error { tx.conn.inTransaction = false if rv := C.OCITransRollback( tx.conn.svc, tx.conn.errHandle, 0, ); rv != C.OCI_SUCCESS { return tx.conn.getError(rv) } return nil }
go
func (tx *OCI8Tx) Rollback() error { tx.conn.inTransaction = false if rv := C.OCITransRollback( tx.conn.svc, tx.conn.errHandle, 0, ); rv != C.OCI_SUCCESS { return tx.conn.getError(rv) } return nil }
[ "func", "(", "tx", "*", "OCI8Tx", ")", "Rollback", "(", ")", "error", "{", "tx", ".", "conn", ".", "inTransaction", "=", "false", "\n", "if", "rv", ":=", "C", ".", "OCITransRollback", "(", "tx", ".", "conn", ".", "svc", ",", "tx", ".", "conn", "....
// Rollback transaction rollback
[ "Rollback", "transaction", "rollback" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/oci8.go#L143-L153
train
mattn/go-oci8
oci8.go
LastInsertId
func (result *OCI8Result) LastInsertId() (int64, error) { return int64(uintptr(unsafe.Pointer(&result.rowid))), result.rowidErr }
go
func (result *OCI8Result) LastInsertId() (int64, error) { return int64(uintptr(unsafe.Pointer(&result.rowid))), result.rowidErr }
[ "func", "(", "result", "*", "OCI8Result", ")", "LastInsertId", "(", ")", "(", "int64", ",", "error", ")", "{", "return", "int64", "(", "uintptr", "(", "unsafe", ".", "Pointer", "(", "&", "result", ".", "rowid", ")", ")", ")", ",", "result", ".", "r...
// LastInsertId returns last inserted ID
[ "LastInsertId", "returns", "last", "inserted", "ID" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/oci8.go#L364-L366
train
mattn/go-oci8
oci8_go18.go
CheckNamedValue
func (conn *OCI8Conn) CheckNamedValue(nv *driver.NamedValue) error { switch nv.Value.(type) { default: return driver.ErrSkip case sql.Out: return nil } }
go
func (conn *OCI8Conn) CheckNamedValue(nv *driver.NamedValue) error { switch nv.Value.(type) { default: return driver.ErrSkip case sql.Out: return nil } }
[ "func", "(", "conn", "*", "OCI8Conn", ")", "CheckNamedValue", "(", "nv", "*", "driver", ".", "NamedValue", ")", "error", "{", "switch", "nv", ".", "Value", ".", "(", "type", ")", "{", "default", ":", "return", "driver", ".", "ErrSkip", "\n", "case", ...
// CheckNamedValue checks the named value
[ "CheckNamedValue", "checks", "the", "named", "value" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/oci8_go18.go#L52-L59
train
mattn/go-oci8
cHelpers.go
cByte
func cByte(b []byte) *C.OraText { p := C.malloc(C.size_t(len(b))) pp := (*[1 << 30]byte)(p) copy(pp[:], b) return (*C.OraText)(p) }
go
func cByte(b []byte) *C.OraText { p := C.malloc(C.size_t(len(b))) pp := (*[1 << 30]byte)(p) copy(pp[:], b) return (*C.OraText)(p) }
[ "func", "cByte", "(", "b", "[", "]", "byte", ")", "*", "C", ".", "OraText", "{", "p", ":=", "C", ".", "malloc", "(", "C", ".", "size_t", "(", "len", "(", "b", ")", ")", ")", "\n", "pp", ":=", "(", "*", "[", "1", "<<", "30", "]", "byte", ...
// cByte comverts byte slice to OraText. // must be freed
[ "cByte", "comverts", "byte", "slice", "to", "OraText", ".", "must", "be", "freed" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/cHelpers.go#L22-L27
train
mattn/go-oci8
cHelpers.go
cByteN
func cByteN(b []byte, size int) *C.OraText { p := C.malloc(C.size_t(size)) pp := (*[1 << 30]byte)(p) copy(pp[:], b) return (*C.OraText)(p) }
go
func cByteN(b []byte, size int) *C.OraText { p := C.malloc(C.size_t(size)) pp := (*[1 << 30]byte)(p) copy(pp[:], b) return (*C.OraText)(p) }
[ "func", "cByteN", "(", "b", "[", "]", "byte", ",", "size", "int", ")", "*", "C", ".", "OraText", "{", "p", ":=", "C", ".", "malloc", "(", "C", ".", "size_t", "(", "size", ")", ")", "\n", "pp", ":=", "(", "*", "[", "1", "<<", "30", "]", "b...
// cByteN comverts byte slice to C OraText with size. // must be freed
[ "cByteN", "comverts", "byte", "slice", "to", "C", "OraText", "with", "size", ".", "must", "be", "freed" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/cHelpers.go#L31-L36
train
mattn/go-oci8
cHelpers.go
cString
func cString(s string) *C.OraText { p := C.malloc(C.size_t(len(s) + 1)) pp := (*[1 << 30]byte)(p) copy(pp[:], s) pp[len(s)] = 0 return (*C.OraText)(p) }
go
func cString(s string) *C.OraText { p := C.malloc(C.size_t(len(s) + 1)) pp := (*[1 << 30]byte)(p) copy(pp[:], s) pp[len(s)] = 0 return (*C.OraText)(p) }
[ "func", "cString", "(", "s", "string", ")", "*", "C", ".", "OraText", "{", "p", ":=", "C", ".", "malloc", "(", "C", ".", "size_t", "(", "len", "(", "s", ")", "+", "1", ")", ")", "\n", "pp", ":=", "(", "*", "[", "1", "<<", "30", "]", "byte...
// cString coverts string to C OraText. // must be freed
[ "cString", "coverts", "string", "to", "C", "OraText", ".", "must", "be", "freed" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/cHelpers.go#L40-L46
train
mattn/go-oci8
cHelpers.go
cStringN
func cStringN(s string, size int) *C.OraText { p := C.malloc(C.size_t(size)) pp := (*[1 << 30]byte)(p) copy(pp[:], s) if len(s) < size { pp[len(s)] = 0 } else { pp[size-1] = 0 } return (*C.OraText)(p) }
go
func cStringN(s string, size int) *C.OraText { p := C.malloc(C.size_t(size)) pp := (*[1 << 30]byte)(p) copy(pp[:], s) if len(s) < size { pp[len(s)] = 0 } else { pp[size-1] = 0 } return (*C.OraText)(p) }
[ "func", "cStringN", "(", "s", "string", ",", "size", "int", ")", "*", "C", ".", "OraText", "{", "p", ":=", "C", ".", "malloc", "(", "C", ".", "size_t", "(", "size", ")", ")", "\n", "pp", ":=", "(", "*", "[", "1", "<<", "30", "]", "byte", ")...
// cStringN coverts string to C OraText with size. // must be freed
[ "cStringN", "coverts", "string", "to", "C", "OraText", "with", "size", ".", "must", "be", "freed" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/cHelpers.go#L50-L60
train
mattn/go-oci8
cHelpers.go
cGoStringN
func cGoStringN(s *C.OraText, size int) string { if size == 0 { return "" } p := (*[1 << 30]byte)(unsafe.Pointer(s)) buf := make([]byte, size) copy(buf, p[:]) return *(*string)(unsafe.Pointer(&buf)) }
go
func cGoStringN(s *C.OraText, size int) string { if size == 0 { return "" } p := (*[1 << 30]byte)(unsafe.Pointer(s)) buf := make([]byte, size) copy(buf, p[:]) return *(*string)(unsafe.Pointer(&buf)) }
[ "func", "cGoStringN", "(", "s", "*", "C", ".", "OraText", ",", "size", "int", ")", "string", "{", "if", "size", "==", "0", "{", "return", "\"", "\"", "\n", "}", "\n", "p", ":=", "(", "*", "[", "1", "<<", "30", "]", "byte", ")", "(", "unsafe",...
// CGoStringN coverts C OraText to Go string
[ "CGoStringN", "coverts", "C", "OraText", "to", "Go", "string" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/cHelpers.go#L63-L71
train
mattn/go-oci8
cHelpers.go
freeDefines
func freeDefines(defines []oci8Define) { for _, define := range defines { if define.pbuf != nil { freeBuffer(define.pbuf, define.dataType) define.pbuf = nil } if define.length != nil { C.free(unsafe.Pointer(define.length)) define.length = nil } if define.indicator != nil { C.free(unsafe.Pointer(define.indicator)) define.indicator = nil } define.defineHandle = nil // should be freed by oci statement close } }
go
func freeDefines(defines []oci8Define) { for _, define := range defines { if define.pbuf != nil { freeBuffer(define.pbuf, define.dataType) define.pbuf = nil } if define.length != nil { C.free(unsafe.Pointer(define.length)) define.length = nil } if define.indicator != nil { C.free(unsafe.Pointer(define.indicator)) define.indicator = nil } define.defineHandle = nil // should be freed by oci statement close } }
[ "func", "freeDefines", "(", "defines", "[", "]", "oci8Define", ")", "{", "for", "_", ",", "define", ":=", "range", "defines", "{", "if", "define", ".", "pbuf", "!=", "nil", "{", "freeBuffer", "(", "define", ".", "pbuf", ",", "define", ".", "dataType", ...
// freeDefines frees defines
[ "freeDefines", "frees", "defines" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/cHelpers.go#L74-L90
train
mattn/go-oci8
cHelpers.go
freeBinds
func freeBinds(binds []oci8Bind) { for _, bind := range binds { if bind.pbuf != nil { freeBuffer(bind.pbuf, bind.dataType) bind.pbuf = nil } if bind.length != nil { C.free(unsafe.Pointer(bind.length)) bind.length = nil } if bind.indicator != nil { C.free(unsafe.Pointer(bind.indicator)) bind.indicator = nil } bind.bindHandle = nil // freed by oci statement close } }
go
func freeBinds(binds []oci8Bind) { for _, bind := range binds { if bind.pbuf != nil { freeBuffer(bind.pbuf, bind.dataType) bind.pbuf = nil } if bind.length != nil { C.free(unsafe.Pointer(bind.length)) bind.length = nil } if bind.indicator != nil { C.free(unsafe.Pointer(bind.indicator)) bind.indicator = nil } bind.bindHandle = nil // freed by oci statement close } }
[ "func", "freeBinds", "(", "binds", "[", "]", "oci8Bind", ")", "{", "for", "_", ",", "bind", ":=", "range", "binds", "{", "if", "bind", ".", "pbuf", "!=", "nil", "{", "freeBuffer", "(", "bind", ".", "pbuf", ",", "bind", ".", "dataType", ")", "\n", ...
// freeBinds frees binds
[ "freeBinds", "frees", "binds" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/cHelpers.go#L93-L109
train
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", "(", "*", "(", "*", "...
// 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
train
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", "row...
// Close closes rows
[ "Close", "closes", "rows" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/rows.go#L18-L33
train
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", ...
// Columns returns column names
[ "Columns", "returns", "column", "names" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/rows.go#L36-L42
train
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"...
// ColumnTypeLength returns column length
[ "ColumnTypeLength", "returns", "column", "length" ]
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/rows.go#L350-L364
train
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", ...
b4ff95311f59786a15c0688c8beff047414c098f
https://github.com/mattn/go-oci8/blob/b4ff95311f59786a15c0688c8beff047414c098f/dsn.go#L296-L300
train
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", ".", "SetKeyPref...
// 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
train
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", "...
273175f8b6ebabab8a639a4e6260a5c50fbf016a
https://github.com/bamzi/jobrunner/blob/273175f8b6ebabab8a639a4e6260a5c50fbf016a/runjob.go#L40-L43
train
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", "}", "(", ")"...
// 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
train
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", ...
// 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", "...
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/streaming.go#L148-L158
train
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", ",", "parityS...
// 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", ...
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/streaming.go#L164-L180
train
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", "[",...
// 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
train
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...
// cReadShards reads shards concurrently
[ "cReadShards", "reads", "shards", "concurrently" ]
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/streaming.go#L319-L364
train
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", "va...
// cWriteShards writes shards concurrently
[ "cWriteShards", "writes", "shards", "concurrently" ]
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/streaming.go#L367-L400
train
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",...
// 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", "...
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/streaming.go#L512-L540
train
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"...
// 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", ...
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/streaming.go#L551-L584
train
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
train
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", ...
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/options.go#L102-L107
train
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...
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/options.go#L113-L118
train
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.", "...
// 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"...
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L133-L157
train
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"...
// 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",...
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L168-L187
train
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"...
// 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", ...
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L214-L286
train
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", ...
// 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"...
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L299-L315
train
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", ...
// 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
train
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", "(", "inp...
// 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", ".",...
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L439-L457
train
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", ":=", "byte...
// 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
train
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", ...
// 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
train
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", "_", "...
// 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", "...
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L581-L594
train
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", "}", ...
// 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
train
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", ...
// 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", ".", ...
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L809-L835
train
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", ".", "DataS...
// 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", "...
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/reedsolomon.go#L849-L887
train
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", ":=", ...
/** * Generates the inverse log table. */
[ "Generates", "the", "inverse", "log", "table", "." ]
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/gentables.go#L72-L80
train
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", ",", "errInva...
// newMatrix returns a matrix of zeros.
[ "newMatrix", "returns", "a", "matrix", "of", "zeros", "." ]
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/matrix.go#L21-L34
train
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", ...
// 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
train
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",...
// 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
train
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", "...
// 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
train
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", ")",...
// 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
train
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", "errInva...
// 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
train
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...
// 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", ...
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/matrix.go#L193-L208
train
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", "}...
// 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
train
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", ":...
// 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
train
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", ".", ...
// 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
train
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 th...
// 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",...
a373324398e4d088b67d6dd6157285b5d4e29642
https://github.com/klauspost/reedsolomon/blob/a373324398e4d088b67d6dd6157285b5d4e29642/inversion_tree.go#L66-L87
train
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"...
// 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
train
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"...
// 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
train
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", ...
// 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
train
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", ...
// 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
train
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) batche...
// 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
train
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
train
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
train
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...
// 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
train
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", ":", "...
// 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
train
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...
// GroupBy specifies columns for grouping.
[ "GroupBy", "specifies", "columns", "for", "grouping", "." ]
48a049970bd235145507f94604005bb7eb9c8bb4
https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/select.go#L239-L244
train
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
train
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"...
// 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
train
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", "...
// 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
train
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", "...
// 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
train
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", ...
// 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
train
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"...
// 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
train
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", ...
// 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
train
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
train
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
train
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", "...", "...
// 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
train
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", ".", "WriteStri...
// 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
train
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", ",", "\"", ...
// Gt is `>`.
[ "Gt", "is", ">", "." ]
48a049970bd235145507f94604005bb7eb9c8bb4
https://github.com/gocraft/dbr/blob/48a049970bd235145507f94604005bb7eb9c8bb4/condition.go#L96-L100
train
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", ...
// 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
train
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"...
// 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
train
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
train
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",...
// 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
train
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
train
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",...
// 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
train
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", ",...
// 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
train
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", ",",...
// 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
train
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", ",", ...
// 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
train