Java BitSet,可轻松串联BitSet [英] Java BitSet which allows easy Concatenation of BitSets

查看:173
本文介绍了Java BitSet,可轻松串联BitSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个BitSet,它允许轻松地将多个BitSet串联以创建一个新的BitSet。 默认实现没有这种方法。

I have a need for a BitSet which allows easy concatenation of multiple BitSets create a new BitSet. The default implementation doesn't have such a method.

某些外部库中是否有任何实现都可以轻松连接的实现?

Is there any an implementation in some external library that any of you know which allows easy concatenation?

例如,可以说我有一个位数组11111和另一个位数组010101。我想要附加功能。因此,连接后将得到11111010101。

For example lets say I have a bitarray 11111 and another bit array 010101. I want functionality like appending. So after concatenating it would result in 11111010101.

推荐答案

好了,没有办法实现这种极其有效的(性能内存,因为没有左移方法。

Well there's no way to implement this terribly efficient (performance and memory that is) since there's no leftshift method.

您可以使用明显的 nextSetBit for循环-缓慢,但内存效率高。

What you can do is either use the obvious nextSetBit for loop - slow, but memory efficient.

大概更快的方法是在一个上使用 toLongArray ,复制正确移位到足够大的数组,然后从中创建一个位集,或与另一个创建位集。这样一来,您无需对单个位进行任何移位,而可以处理字化的块。

The presumably faster method would be to use toLongArray on one, copy that correctly shifted into a large enough array, create a bitset from that and or it with the other. That way you don't do any bitshifting on single bits but instead work on wordsized chunks.

这篇关于Java BitSet,可轻松串联BitSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆