Skip to content

Commit

Permalink
util: correct comments mistake (pingcap#3121)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhexuany authored and shenli committed Apr 25, 2017
1 parent 2fcd97f commit 5494a54
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 45 deletions.
2 changes: 1 addition & 1 deletion util/codec/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func reverseBytes(b []byte) {
safeReverseBytes(b)
}

// like realloc.
// reallocBytes is like realloc.
func reallocBytes(b []byte, n int) []byte {
newSize := len(b) + n
if cap(b) < newSize {
Expand Down
2 changes: 1 addition & 1 deletion util/codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func SetRawValues(data []byte, values []types.Datum) error {
return nil
}

// peeks the first encoded value from b and returns its length.
// peek peeks the first encoded value from b and returns its length.
func peek(b []byte) (length int, err error) {
if len(b) < 1 {
return 0, errors.New("invalid encoded key")
Expand Down
4 changes: 2 additions & 2 deletions util/encrypt/aes.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func newECBDecrypter(b cipher.Block) cipher.BlockMode {
return (*ecbDecrypter)(newECB(b))
}

// Padding using PKCS7
// pkcs7Padding pads data using PKCS7.
// See https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7
func pkcs7Padding(ciphertext []byte, blockSize int) []byte {
// The bytes need to padding.
Expand All @@ -94,7 +94,7 @@ func pkcs7Padding(ciphertext []byte, blockSize int) []byte {
return append(ciphertext, padtext...)
}

// UnPadding using PKCS7
// pkcs5UnPadding unPads data using PKCS7.
// See https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7
func pkcs5UnPadding(origData []byte) []byte {
length := len(origData)
Expand Down
14 changes: 7 additions & 7 deletions util/filesort/filesort.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type item struct {
value *comparableRow
}

// Min-heap of comparableRows
// rowHeap maintains a min-heap property of comparableRows.
type rowHeap struct {
sc *variable.StatementContext
ims []*item
Expand Down Expand Up @@ -92,12 +92,12 @@ func (rh *rowHeap) Less(i, j int) bool {
return ret
}

// Push implements heap.Interface Push interface.
// Push pushes an element into rowHeap.
func (rh *rowHeap) Push(x interface{}) {
rh.ims = append(rh.ims, x.(*item))
}

// Push implements heap.Interface Pop interface.
// Pop pops the last element from rowHeap.
func (rh *rowHeap) Pop() interface{} {
old := rh.ims
n := len(old)
Expand Down Expand Up @@ -295,7 +295,7 @@ func (fs *FileSorter) closeAllFiles() error {
return nil
}

// Perform full in-memory sort.
// internalSort performs full in-memory sort.
func (fs *FileSorter) internalSort() (*comparableRow, error) {
w := fs.workers[fs.cWorker]

Expand All @@ -314,7 +314,7 @@ func (fs *FileSorter) internalSort() (*comparableRow, error) {
return nil, nil
}

// Perform external file sort.
// externalSort performs external file sort.
func (fs *FileSorter) externalSort() (*comparableRow, error) {
if !fs.fetched {
// flush all remaining content to file (if any)
Expand Down Expand Up @@ -412,7 +412,7 @@ func (fs *FileSorter) openAllFiles() error {
return nil
}

// Fetch the next row given the source file index.
// fetchNextRow fetches the next row given the source file index.
func (fs *FileSorter) fetchNextRow(index int) (*comparableRow, error) {
n, err := fs.fds[index].Read(fs.head)
if err == io.EOF {
Expand Down Expand Up @@ -559,7 +559,7 @@ func (w *Worker) input(row *comparableRow) {
}
}

// Flush the buffer to file if it is full.
// flushToFile flushes the buffer to file if it is full.
func (w *Worker) flushToFile() {
defer w.ctx.wg.Done()
var (
Expand Down
10 changes: 4 additions & 6 deletions util/mock/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ var _ context.Context = (*Context)(nil)

// Context represents mocked context.Context.
type Context struct {
values map[fmt.Stringer]interface{}
// mock global variable
txn kv.Transaction
Store kv.Storage
values map[fmt.Stringer]interface{}
txn kv.Transaction // mock global variable
Store kv.Storage // mock global variable
sessionVars *variable.SessionVars
// Fix data race in ddl test.
mux sync.Mutex
mux sync.Mutex // fix data race in ddl test.
}

// SetValue implements context.Context SetValue interface.
Expand Down
2 changes: 1 addition & 1 deletion util/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func CompareUnorderedStringSlice(a []string, b []string) bool {
return len(m) == 0
}

// DatumEquals checker.
// datumEqualsChecker is a checker for DatumEquals.
type datumEqualsChecker struct {
*check.CheckerInfo
}
Expand Down
2 changes: 1 addition & 1 deletion util/types/datum_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ func ComputeRightShift(sc *variable.StatementContext, a, b Datum) (d Datum, err
return d, nil
}

// covertNonIntegerToUint64 coverts a non-integer to an uint64
// convertNonInt2RoundUint64 converts a non-integer to an uint64
func convertNonInt2RoundUint64(sc *variable.StatementContext, x Datum) (d uint64, err error) {
decimalX, err := x.ToDecimal(sc)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion util/types/etc.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func InvOp2(x, y interface{}, o opcode.Op) (interface{}, error) {
return nil, errors.Errorf("Invalid operation: %v %v %v (mismatched types %T and %T)", x, o, y, x, y)
}

// Overflow returns an overflowed error.
// overflow returns an overflowed error.
func overflow(v interface{}, tp byte) error {
return ErrOverflow.Gen("constant %v overflows %s", v, TypeStr(tp))
}
21 changes: 9 additions & 12 deletions util/types/mydecimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,15 @@ func digitsToWords(digits int) int {

// MyDecimal represents a decimal value.
type MyDecimal struct {
// The number of *decimal* digits before the point.
digitsInt int8
digitsInt int8 // the number of *decimal* digits before the point.

// The number of decimal digits after the point.
digitsFrac int8
digitsFrac int8 // the number of decimal digits after the point.

// result fraction digits.
resultFrac int8
resultFrac int8 // result fraction digits.

negative bool

// An array of int32 words.
// wordBuf is an array of int32 words.
// A word is an int32 value can hold 9 digits.(0 <= word < wordBase)
wordBuf [maxWordBufLen]int32
}
Expand Down Expand Up @@ -419,15 +416,15 @@ func (d *MyDecimal) Shift(shift int) error {
return nil
}
var (
/* index of first non zero digit (all indexes from 0) */
// digitBegin is index of first non zero digit (all indexes from 0).
digitBegin int
/* index of position after last decimal digit */
// digitEnd is index of position after last decimal digit.
digitEnd int
/* index of digit position just after point */
// point is index of digit position just after point.
point = digitsToWords(int(d.digitsInt)) * digitsPerWord
/* new point position */
// new point position.
newPoint = point + shift
/* number of digits in result */
// number of digits in result.
digitsInt, digitsFrac int
newFront int
)
Expand Down
2 changes: 1 addition & 1 deletion util/types/mytime.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func calcWeekday(daynr int, sundayFirstDayOfWeek bool) int {
type weekBehaviour uint

const (
// If set, Sunday is first day of week, otherwise Monday is first day of week.
// weekBehaviourMondayFirst set Monday as first day of week; otherwise Sunday is first day of week
weekBehaviourMondayFirst weekBehaviour = 1 << iota
// If set, Week is in range 1-53, otherwise Week is in range 0-53.
// Note that this flag is only relevant if WEEK_JANUARY is not set.
Expand Down
1 change: 1 addition & 0 deletions util/types/mytime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package types

import (
Expand Down
26 changes: 14 additions & 12 deletions util/types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ func ParseYear(str string) (int16, error) {
return y, nil
}

// adjustYear adjusts year according to y.
// See https://dev.mysql.com/doc/refman/5.7/en/two-digit-years.html
func adjustYear(y int) int {
if y >= 0 && y <= 69 {
Expand Down Expand Up @@ -986,6 +987,7 @@ func getTime(num int64, tp byte) (Time, error) {
return t, errors.Trace(err)
}

// parseDateTimeFromNum parses date time from num.
// See number_to_datetime function.
// https://github.com/mysql/mysql-server/blob/5.7/sql-common/my_time.c
func parseDateTimeFromNum(num int64) (Time, error) {
Expand Down Expand Up @@ -1354,7 +1356,7 @@ func extractSingleTimeValue(unit string, format string) (int64, int64, int64, go
return 0, 0, 0, 0, errors.Errorf("invalid singel timeunit - %s", unit)
}

// Format is `SS.FFFFFF`.
// extractSecondMicrosecond extracts second and microsecond from a string and its format is `SS.FFFFFF`.
func extractSecondMicrosecond(format string) (int64, int64, int64, gotime.Duration, error) {
fields := strings.Split(format, ".")
if len(fields) != 2 {
Expand All @@ -1374,7 +1376,7 @@ func extractSecondMicrosecond(format string) (int64, int64, int64, gotime.Durati
return 0, 0, 0, gotime.Duration(seconds)*gotime.Second + gotime.Duration(microseconds)*gotime.Microsecond, nil
}

// Format is `MM:SS.FFFFFF`.
// extractMinuteMicrosecond extracts minutes and microsecond from a string and its format is `MM:SS.FFFFFF`.
func extractMinuteMicrosecond(format string) (int64, int64, int64, gotime.Duration, error) {
fields := strings.Split(format, ":")
if len(fields) != 2 {
Expand All @@ -1394,7 +1396,7 @@ func extractMinuteMicrosecond(format string) (int64, int64, int64, gotime.Durati
return 0, 0, 0, gotime.Duration(minutes)*gotime.Minute + value, nil
}

// Format is `MM:SS`.
// extractMinuteSecond extracts minutes and second from a string and its format is `MM:SS`.
func extractMinuteSecond(format string) (int64, int64, int64, gotime.Duration, error) {
fields := strings.Split(format, ":")
if len(fields) != 2 {
Expand All @@ -1414,7 +1416,7 @@ func extractMinuteSecond(format string) (int64, int64, int64, gotime.Duration, e
return 0, 0, 0, gotime.Duration(minutes)*gotime.Minute + gotime.Duration(seconds)*gotime.Second, nil
}

// Format is `HH:MM:SS.FFFFFF`.
// extractHourMicrosecond extracts hour and microsecond from a string and its format is `HH:MM:SS.FFFFFF`.
func extractHourMicrosecond(format string) (int64, int64, int64, gotime.Duration, error) {
fields := strings.Split(format, ":")
if len(fields) != 3 {
Expand All @@ -1439,7 +1441,7 @@ func extractHourMicrosecond(format string) (int64, int64, int64, gotime.Duration
return 0, 0, 0, gotime.Duration(hours)*gotime.Hour + gotime.Duration(minutes)*gotime.Minute + value, nil
}

// Format is `HH:MM:SS`.
// extractHourSecond extracts hour and second from a string and its format is `HH:MM:SS`.
func extractHourSecond(format string) (int64, int64, int64, gotime.Duration, error) {
fields := strings.Split(format, ":")
if len(fields) != 3 {
Expand All @@ -1464,7 +1466,7 @@ func extractHourSecond(format string) (int64, int64, int64, gotime.Duration, err
return 0, 0, 0, gotime.Duration(hours)*gotime.Hour + gotime.Duration(minutes)*gotime.Minute + gotime.Duration(seconds)*gotime.Second, nil
}

// Format is `HH:MM`.
// extractHourMinute extracts hour and minute from a string and its format is `HH:MM`.
func extractHourMinute(format string) (int64, int64, int64, gotime.Duration, error) {
fields := strings.Split(format, ":")
if len(fields) != 2 {
Expand All @@ -1484,7 +1486,7 @@ func extractHourMinute(format string) (int64, int64, int64, gotime.Duration, err
return 0, 0, 0, gotime.Duration(hours)*gotime.Hour + gotime.Duration(minutes)*gotime.Minute, nil
}

// Format is `DD HH:MM:SS.FFFFFF`.
// extractDayMicrosecond extracts day and microsecond from a string and its format is `DD HH:MM:SS.FFFFFF`.
func extractDayMicrosecond(format string) (int64, int64, int64, gotime.Duration, error) {
fields := strings.Split(format, " ")
if len(fields) != 2 {
Expand All @@ -1504,7 +1506,7 @@ func extractDayMicrosecond(format string) (int64, int64, int64, gotime.Duration,
return 0, 0, days, value, nil
}

// Format is `DD HH:MM:SS`.
// extractDaySecond extracts day and hour from a string and its format is `DD HH:MM:SS`.
func extractDaySecond(format string) (int64, int64, int64, gotime.Duration, error) {
fields := strings.Split(format, " ")
if len(fields) != 2 {
Expand All @@ -1524,7 +1526,7 @@ func extractDaySecond(format string) (int64, int64, int64, gotime.Duration, erro
return 0, 0, days, value, nil
}

// Format is `DD HH:MM`.
// extractDayMinute extracts day and minute from a string and its format is `DD HH:MM`.
func extractDayMinute(format string) (int64, int64, int64, gotime.Duration, error) {
fields := strings.Split(format, " ")
if len(fields) != 2 {
Expand All @@ -1544,7 +1546,7 @@ func extractDayMinute(format string) (int64, int64, int64, gotime.Duration, erro
return 0, 0, days, value, nil
}

// Format is `DD HH`.
// extractDayHour extracts day and hour from a string and its format is `DD HH`.
func extractDayHour(format string) (int64, int64, int64, gotime.Duration, error) {
fields := strings.Split(format, " ")
if len(fields) != 2 {
Expand All @@ -1564,7 +1566,7 @@ func extractDayHour(format string) (int64, int64, int64, gotime.Duration, error)
return 0, 0, days, gotime.Duration(hours) * gotime.Hour, nil
}

// Format is `YYYY-MM`.
// extractYearMonth extracts year and month from a string and its format is `YYYY-MM`.
func extractYearMonth(format string) (int64, int64, int64, gotime.Duration, error) {
fields := strings.Split(format, "-")
if len(fields) != 2 {
Expand Down Expand Up @@ -2252,7 +2254,7 @@ func monthNumeric(t *mysqlTime, input string, ctx map[string]int) (string, bool)
return rem, false
}

// 0th 1st 2nd 3rd ...
// dayOfMonthWithSuffix returns different suffix according t being which day. i.e. 0 return th. 1 return st.
func dayOfMonthWithSuffix(t *mysqlTime, input string, ctx map[string]int) (string, bool) {
month, remain := parseOrdinalNumbers(input)
if month >= 0 {
Expand Down

0 comments on commit 5494a54

Please sign in to comment.