github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/col/coldata/native_types.go (about)

     1  // Copyright 2020 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package coldata
    12  
    13  import (
    14  	"time"
    15  
    16  	"github.com/cockroachdb/apd/v3"
    17  	"github.com/cockroachdb/cockroachdb-parser/pkg/util/duration"
    18  )
    19  
    20  // Bools is a slice of bool.
    21  type Bools []bool
    22  
    23  // Int16s is a slice of int16.
    24  type Int16s []int16
    25  
    26  // Int32s is a slice of int32.
    27  type Int32s []int32
    28  
    29  // Int64s is a slice of int64.
    30  type Int64s []int64
    31  
    32  // Float64s is a slice of float64.
    33  type Float64s []float64
    34  
    35  // Decimals is a slice of apd.Decimal.
    36  type Decimals []apd.Decimal
    37  
    38  // Times is a slice of time.Time.
    39  type Times []time.Time
    40  
    41  // Durations is a slice of duration.Duration.
    42  type Durations []duration.Duration
    43  
    44  // Get returns the element at index idx of the vector. The element cannot be
    45  // used anymore once the vector is modified.
    46  //
    47  //gcassert:inline
    48  func (c Bools) Get(idx int) bool { return c[idx] }
    49  
    50  // Get returns the element at index idx of the vector. The element cannot be
    51  // used anymore once the vector is modified.
    52  //
    53  //gcassert:inline
    54  func (c Int16s) Get(idx int) int16 { return c[idx] }
    55  
    56  // Get returns the element at index idx of the vector. The element cannot be
    57  // used anymore once the vector is modified.
    58  //
    59  //gcassert:inline
    60  func (c Int32s) Get(idx int) int32 { return c[idx] }
    61  
    62  // Get returns the element at index idx of the vector. The element cannot be
    63  // used anymore once the vector is modified.
    64  //
    65  //gcassert:inline
    66  func (c Int64s) Get(idx int) int64 { return c[idx] }
    67  
    68  // Get returns the element at index idx of the vector. The element cannot be
    69  // used anymore once the vector is modified.
    70  //
    71  //gcassert:inline
    72  func (c Float64s) Get(idx int) float64 { return c[idx] }
    73  
    74  // Get returns the element at index idx of the vector. The element cannot be
    75  // used anymore once the vector is modified.
    76  //
    77  //gcassert:inline
    78  func (c Decimals) Get(idx int) apd.Decimal { return c[idx] }
    79  
    80  // Get returns the element at index idx of the vector. The element cannot be
    81  // used anymore once the vector is modified.
    82  //
    83  //gcassert:inline
    84  func (c Times) Get(idx int) time.Time { return c[idx] }
    85  
    86  // Get returns the element at index idx of the vector. The element cannot be
    87  // used anymore once the vector is modified.
    88  //
    89  //gcassert:inline
    90  func (c Durations) Get(idx int) duration.Duration { return c[idx] }
    91  
    92  // Set sets the element at index idx of the vector to val.
    93  //
    94  //gcassert:inline
    95  func (c Bools) Set(idx int, val bool) { c[idx] = val }
    96  
    97  // Set sets the element at index idx of the vector to val.
    98  //
    99  //gcassert:inline
   100  func (c Int16s) Set(idx int, val int16) { c[idx] = val }
   101  
   102  // Set sets the element at index idx of the vector to val.
   103  //
   104  //gcassert:inline
   105  func (c Int32s) Set(idx int, val int32) { c[idx] = val }
   106  
   107  // Set sets the element at index idx of the vector to val.
   108  //
   109  //gcassert:inline
   110  func (c Int64s) Set(idx int, val int64) { c[idx] = val }
   111  
   112  // Set sets the element at index idx of the vector to val.
   113  //
   114  //gcassert:inline
   115  func (c Float64s) Set(idx int, val float64) { c[idx] = val }
   116  
   117  // Set sets the element at index idx of the vector to val.
   118  //
   119  // Note that this method is usually inlined, but it isn't in case of the merge
   120  // joiner generated code (probably because of the size of the functions), so we
   121  // don't assert the inlining with the GCAssert linter.
   122  func (c Decimals) Set(idx int, val apd.Decimal) { c[idx].Set(&val) }
   123  
   124  // Set sets the element at index idx of the vector to val.
   125  //
   126  //gcassert:inline
   127  func (c Times) Set(idx int, val time.Time) { c[idx] = val }
   128  
   129  // Set sets the element at index idx of the vector to val.
   130  //
   131  //gcassert:inline
   132  func (c Durations) Set(idx int, val duration.Duration) { c[idx] = val }
   133  
   134  // Len returns the length of the vector.
   135  //
   136  //gcassert:inline
   137  func (c Bools) Len() int { return len(c) }
   138  
   139  // Len returns the length of the vector.
   140  //
   141  //gcassert:inline
   142  func (c Int16s) Len() int { return len(c) }
   143  
   144  // Len returns the length of the vector.
   145  //
   146  //gcassert:inline
   147  func (c Int32s) Len() int { return len(c) }
   148  
   149  // Len returns the length of the vector.
   150  //
   151  //gcassert:inline
   152  func (c Int64s) Len() int { return len(c) }
   153  
   154  // Len returns the length of the vector.
   155  //
   156  //gcassert:inline
   157  func (c Float64s) Len() int { return len(c) }
   158  
   159  // Len returns the length of the vector.
   160  //
   161  //gcassert:inline
   162  func (c Decimals) Len() int { return len(c) }
   163  
   164  // Len returns the length of the vector.
   165  //
   166  //gcassert:inline
   167  func (c Times) Len() int { return len(c) }
   168  
   169  // Len returns the length of the vector.
   170  //
   171  //gcassert:inline
   172  func (c Durations) Len() int { return len(c) }
   173  
   174  // CopySlice copies src[srcStartIdx:srcEndIdx] into c starting at position
   175  // destIdx.
   176  //
   177  //gcassert:inline
   178  func (c Bools) CopySlice(src Bools, destIdx, srcStartIdx, srcEndIdx int) {
   179  	copy(c[destIdx:], src[srcStartIdx:srcEndIdx])
   180  }
   181  
   182  // CopySlice copies src[srcStartIdx:srcEndIdx] into c starting at position
   183  // destIdx.
   184  //
   185  //gcassert:inline
   186  func (c Int16s) CopySlice(src Int16s, destIdx, srcStartIdx, srcEndIdx int) {
   187  	copy(c[destIdx:], src[srcStartIdx:srcEndIdx])
   188  }
   189  
   190  // CopySlice copies src[srcStartIdx:srcEndIdx] into c starting at position
   191  // destIdx.
   192  //
   193  //gcassert:inline
   194  func (c Int32s) CopySlice(src Int32s, destIdx, srcStartIdx, srcEndIdx int) {
   195  	copy(c[destIdx:], src[srcStartIdx:srcEndIdx])
   196  }
   197  
   198  // CopySlice copies src[srcStartIdx:srcEndIdx] into c starting at position
   199  // destIdx.
   200  //
   201  //gcassert:inline
   202  func (c Int64s) CopySlice(src Int64s, destIdx, srcStartIdx, srcEndIdx int) {
   203  	copy(c[destIdx:], src[srcStartIdx:srcEndIdx])
   204  }
   205  
   206  // CopySlice copies src[srcStartIdx:srcEndIdx] into c starting at position
   207  // destIdx.
   208  //
   209  //gcassert:inline
   210  func (c Float64s) CopySlice(src Float64s, destIdx, srcStartIdx, srcEndIdx int) {
   211  	copy(c[destIdx:], src[srcStartIdx:srcEndIdx])
   212  }
   213  
   214  // CopySlice copies src[srcStartIdx:srcEndIdx] into c starting at position
   215  // destIdx.
   216  //
   217  // Note that this method is usually inlined, but it isn't in case of the
   218  // memColumn.Copy generated code (probably because of the size of that
   219  // function), so we don't assert the inlining with the GCAssert linter.
   220  func (c Decimals) CopySlice(src Decimals, destIdx, srcStartIdx, srcEndIdx int) {
   221  	srcSlice := src[srcStartIdx:srcEndIdx]
   222  	for i := range srcSlice {
   223  		c[destIdx+i].Set(&srcSlice[i])
   224  	}
   225  }
   226  
   227  // CopySlice copies src[srcStartIdx:srcEndIdx] into c starting at position
   228  // destIdx.
   229  //
   230  //gcassert:inline
   231  func (c Times) CopySlice(src Times, destIdx, srcStartIdx, srcEndIdx int) {
   232  	copy(c[destIdx:], src[srcStartIdx:srcEndIdx])
   233  }
   234  
   235  // CopySlice copies src[srcStartIdx:srcEndIdx] into c starting at position
   236  // destIdx.
   237  //
   238  //gcassert:inline
   239  func (c Durations) CopySlice(src Durations, destIdx, srcStartIdx, srcEndIdx int) {
   240  	copy(c[destIdx:], src[srcStartIdx:srcEndIdx])
   241  }
   242  
   243  // Window returns the window into the vector.
   244  //
   245  //gcassert:inline
   246  func (c Bools) Window(start, end int) Bools { return c[start:end] }
   247  
   248  // Window returns the window into the vector.
   249  //
   250  //gcassert:inline
   251  func (c Int16s) Window(start, end int) Int16s { return c[start:end] }
   252  
   253  // Window returns the window into the vector.
   254  //
   255  //gcassert:inline
   256  func (c Int32s) Window(start, end int) Int32s { return c[start:end] }
   257  
   258  // Window returns the window into the vector.
   259  //
   260  //gcassert:inline
   261  func (c Int64s) Window(start, end int) Int64s { return c[start:end] }
   262  
   263  // Window returns the window into the vector.
   264  //
   265  //gcassert:inline
   266  func (c Float64s) Window(start, end int) Float64s { return c[start:end] }
   267  
   268  // Window returns the window into the vector.
   269  //
   270  //gcassert:inline
   271  func (c Decimals) Window(start, end int) Decimals { return c[start:end] }
   272  
   273  // Window returns the window into the vector.
   274  //
   275  //gcassert:inline
   276  func (c Times) Window(start, end int) Times { return c[start:end] }
   277  
   278  // Window returns the window into the vector.
   279  //
   280  //gcassert:inline
   281  func (c Durations) Window(start, end int) Durations { return c[start:end] }