paleolimbot commented on code in PR #10: URL: https://github.com/apache/arrow-nanoarrow/pull/10#discussion_r938864854
########## src/nanoarrow/bitmap_inline.h: ########## @@ -0,0 +1,131 @@ +// 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. + +#ifndef NANOARROW_BITMAP_INLINE_H_INCLUDED +#define NANOARROW_BITMAP_INLINE_H_INCLUDED + +#include <stdlib.h> +#include <string.h> + +#include "buffer_inline.h" +#include "typedefs_inline.h" + +static inline int8_t ArrowBitmapElement(const void* bitmap, int64_t i) { + const int8_t* bitmap_char = (const int8_t*)bitmap; + return 0 != (bitmap_char[i / 8] & ((int8_t)0x01) << (i % 8)); +} + +static inline void ArrowBitmapSetElement(void* bitmap, int64_t i, int8_t value) { + int8_t* bitmap_char = (int8_t*)bitmap; + int8_t mask = 0x01 << (i % 8); + if (value) { + bitmap_char[i / 8] |= mask; + } else { + bitmap_char[i / 8] &= ~mask; + } +} + +static inline int64_t ArrowBitmapCountTrue(const void* bitmap, int64_t i_from, + int64_t i_to) { + int64_t count = 0; + for (int64_t i = i_from; i < i_to; i++) { + count += ArrowBitmapElement(bitmap, i); Review Comment: I passed on the compiler intrinsics for now because I don't have CI to test multiple compilers and make sure that they work or benchmarks set up to make sure they're worth it...I used the pre-computed `kpopcount` array which is much better than the previous version. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
