【发布时间】:2017-03-21 05:45:06
【问题描述】:
我将如何检查位集向量中的给定“项目”是否超出范围
例如:
struct bitset {
unsigned char*vector;
int byteSize;
int bitSize;
};
// create a new, empty bit vector set of 'size' items
struct bitset * bitset_new(int size) {
struct bitset * theSet;
theSet = malloc(sizeof(struct bitset));
theSet->vector = calloc(size, sizeof(char));
theSet->bitSize = size;
theSet->byteSize= ((size / 8) + 1);
return theSet;
}
int bitset_find(struct bitset * this, int k)
{
int arrayIndex = k/8;
int indexPosition = k%8;
unsigned int flag = 1; // flag = 0000.....00001
flag = flag << indexPosition; // flag = 0000...010...000 (shifted k positions)
if()
{
}
}
我的 if 语句中究竟应该包含什么来查看 k 是否不在我的向量中?
【问题讨论】:
-
struct bitset 是什么样子的
-
struct bitset { unsigned char*vector;整数字节大小;整数位大小; };
-
请将该代码添加到您的问题中。
-
对我来说,
byteSize和bitSize字段似乎应该总是分别等于8和1。对吗?