GithubHelp home page GithubHelp logo

バイト列の自動拡張 about bitset HOT 4 CLOSED

kawasin73 avatar kawasin73 commented on August 26, 2024
バイト列の自動拡張

from bitset.

Comments (4)

kawasin73 avatar kawasin73 commented on August 26, 2024

ビットベクトルの拡張には対応しない。

zcbit は syscall.Mmap() でファイルにマッピングされたバイト列に対するビットベクトルの操作を考慮して作られている。
スライスの自動拡張は、スライスのキャパシティ(cap())が拡張後のサイズよりも小さい場合に、倍のサイズのメモリを新しく確保し、古いメモリのデータをコピーしてバイト列の参照を切り替えるという処理を行う。
mmap されたメモリから別のメモリに参照先が切り替えるとビットベクトルの操作による変更内容がファイルに反映されないバグにつながる。

そのためスライスサイズの拡張はユーザーが行い、拡張を行う場合は再度 zcbit.BitVec を作成し直すことで対応し、zcbit 単体ではスライスの自動拡張には対応しない。

from bitset.

kawasin73 avatar kawasin73 commented on August 26, 2024

バイト列の拡張に対応したい。

ただし、拡張してはいけない場合もあるので引数で拡張可能であるかどうかを渡す

from bitset.

kawasin73 avatar kawasin73 commented on August 26, 2024

Go のスライスは 1024 要素までは倍のサイズに拡張し、それ以上の場合は、1.25 倍に拡張する。

https://golang.org/src/runtime/slice.go#L121

If the slice does not have sufficient capacity, append will need to allocate new memory and copy the old one over. For slices with <1024 elements, it will double the capacity, for slices with >1024 elements it will increase it by factor 1.25.
https://stackoverflow.com/questions/17332227/big-o-of-append-in-golang

Go のスライスの実装に習い、1024 個より小さい要素の場合は倍のサイズにして、それ以上の場合は 1.25 倍のサイズにする

また、新しいサイズがオーバーフローする場合はエラーとする

from bitset.

kawasin73 avatar kawasin73 commented on August 26, 2024

対応した。

f69014b

from bitset.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.