zeroshade commented on a change in pull request #9671:
URL: https://github.com/apache/arrow/pull/9671#discussion_r597112138



##########
File path: go/parquet/internal/utils/bit_reader.go
##########
@@ -0,0 +1,344 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package utils
+
+import (
+       "encoding/binary"
+       "errors"
+       "io"
+       "math"
+       "reflect"
+       "unsafe"
+
+       "github.com/apache/arrow/go/arrow"
+       "github.com/apache/arrow/go/arrow/bitutil"
+       "github.com/apache/arrow/go/arrow/memory"
+)
+
+// masks for grabbing the trailing bits based on the number of trailing bits 
desired
+var trailingMask [64]uint64
+
+func init() {
+       // generate the masks at init so we don't have to hard code them.
+       for i := 0; i < 64; i++ {
+               trailingMask[i] = (math.MaxUint64 >> (64 - i))
+       }
+}
+
+// trailingBits returns a value constructed from the bits trailing bits of
+// the value v that is passed in. If bits >= 64, then we just return v.
+func trailingBits(v uint64, bits uint) uint64 {
+       if bits >= 64 {
+               return v
+       }
+       return v & trailingMask[bits]
+}
+
+// reader is a useful interface to define the functionality we need for 
implementation
+type reader interface {
+       io.Reader
+       io.ReaderAt
+       io.Seeker
+}
+
+// default buffer length
+const buflen = 1024
+
+// BitReader implements functionality for reading bits or bytes buffering up 
to a uint64
+// at a time from the reader in order to improve efficiency. It also provides
+// methods to read multiple bytes in one read such as encoded ints/values.
+//
+// This BitReader is the basis for the other utility classes like RLE decoding
+// and such, providing the necessary functions for interpreting the values.
+type BitReader struct {
+       reader     reader
+       buffer     uint64
+       byteoffset int64
+       bitoffset  uint

Review comment:
       it's only cast to `int64` when interacting with other `int64` vars or 
being passed into functions with a signature of `int64`. It's a `uint` because 
what matters here is that it's a `uint` and not whether it's 32/64 bit 
specifically since it won't be large enough to matter.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to