my_bool test_intersect(MY_BITMAP *map, uint bitsize) { uint bitsize2 = 1 + get_rand_bit(MAX_TESTED_BITMAP_SIZE - 1); MY_BITMAP map2; uint32 map2buf[MAX_TESTED_BITMAP_SIZE]; uint i, test_bit1, test_bit2, test_bit3; if (bitmap_init(&map2, map2buf, bitsize2, FALSE)) { diag("init error for bitsize %d", bitsize2); return TRUE; } test_bit1= get_rand_bit(bitsize); test_bit2= get_rand_bit(bitsize); bitmap_set_bit(map, test_bit1); bitmap_set_bit(map, test_bit2); test_bit3= get_rand_bit(bitsize2); bitmap_set_bit(&map2, test_bit3); if (test_bit2 < bitsize2) bitmap_set_bit(&map2, test_bit2); bitmap_intersect(map, &map2); if (test_bit2 < bitsize2) { if (!bitmap_is_set(map, test_bit2)) goto error; bitmap_clear_bit(map, test_bit2); } if (test_bit1 == test_bit3) { if (!bitmap_is_set(map, test_bit1)) goto error; bitmap_clear_bit(map, test_bit1); } if (!bitmap_is_clear_all(map)) goto error; bitmap_set_all(map); bitmap_set_all(&map2); for (i=0; i < bitsize2; i++) bitmap_clear_bit(&map2, i); bitmap_intersect(map, &map2); if (!bitmap_is_clear_all(map)) goto error; return FALSE; error: diag("intersect error bitsize = %u, bit1 = %u, bit2 = %u, bit3 = %u", bitsize, test_bit1, test_bit2, test_bit3); return TRUE; }
/* Compares the 'n' bits in bitmaps 'a' and 'b'. Returns true if all bits are * equal, false otherwise. */ bool bitmap_equal(const unsigned long *a, const unsigned long *b, size_t n) { size_t i; if (memcmp(a, b, n / BITMAP_ULONG_BITS * sizeof(unsigned long))) { return false; } for (i = ROUND_DOWN(n, BITMAP_ULONG_BITS); i < n; i++) { if (bitmap_is_set(a, i) != bitmap_is_set(b, i)) { return false; } } return true; }
size_t pack_row_old(TABLE *table, MY_BITMAP const* cols, uchar *row_data, const uchar *record) { Field **p_field= table->field, *field; int n_null_bytes= table->s->null_bytes; uchar *ptr; uint i; my_ptrdiff_t const rec_offset= record - table->record[0]; my_ptrdiff_t const def_offset= table->s->default_values - table->record[0]; memcpy(row_data, record, n_null_bytes); ptr= row_data+n_null_bytes; for (i= 0 ; (field= *p_field) ; i++, p_field++) { if (bitmap_is_set(cols,i)) { my_ptrdiff_t const offset= field->is_null(rec_offset) ? def_offset : rec_offset; field->move_field_offset(offset); ptr= field->pack(ptr, field->ptr); field->move_field_offset(-offset); } } return (static_cast<size_t>(ptr - row_data)); }
my_bool test_count_bits_set(MY_BITMAP *map, uint bitsize) { uint i, bit_count=0, test_bit; uint no_loops= bitsize > 128 ? 128 : bitsize; for (i=0; i < no_loops; i++) { test_bit=get_rand_bit(bitsize); if (!bitmap_is_set(map, test_bit)) { bitmap_set_bit(map, test_bit); bit_count++; } } if (bit_count==0 && bitsize > 0) goto error1; if (bitmap_bits_set(map) != bit_count) goto error2; return FALSE; error1: diag("No bits set bitsize = %u", bitsize); return TRUE; error2: diag("Wrong count of bits set, bitsize = %u", bitsize); return TRUE; }
int bitmap_get_bit(struct vbfs_bitmap *bitmap, size_t bit, int *result) { if (bitmap->max_bit <= bit) return -1; *result = bitmap_is_set(bitmap, bit); return 0; }
/***************************************************************************** 函 数 名 : vlan_bitmap_to_string 功能描述 : 将vlan位图由数组转化为字符串型 输入参数 : u8* bitmap : vlan位图数组 输出参数 : s8* string : 转化成的位图字符串 返 回 值 : 无 ----------------------------------------------------------------------------- 最近一次修改记录: 修改作者: wuyang 修改目的: 生成新函数 修改日期: 2011年09月17日 *****************************************************************************/ void vlan_bitmap_to_string(u8* bitmap, s8* string) { u32 i; u32 start_id = U32_MAX, end_id = U32_MAX; s32 len = 0; for(i = 1; i < VLAN_MAX_ID; i++) { if (bitmap_is_set(bitmap, i)) { if (VLAN_MIN_ID == i || !bitmap_is_set(bitmap, i-1)) { start_id = i; } if (VLAN_MAX_ID == i || !bitmap_is_set(bitmap, i+1)) { end_id = i; if (end_id == start_id) { len += sprintf(string+len, "%d", end_id); len += sprintf(string+len, ","); } else { len += sprintf(string+len, "%d", start_id); len += sprintf(string+len, "-"); len += sprintf(string+len, "%d", end_id); len += sprintf(string+len, ","); } } } } if (',' == *(string+len-1)) { *(string+len-1) = '\0'; } return ; }
/* * Unsets a given bit in the bitmap * Returns -1 if the bit was already unset, 0 otherwise */ int bitmap_unset(bitmap_t bitmap, uint32_t bit) { if(!bitmap_is_set(bitmap, bit)) return -1; bitmap[bit/BITMAP_BITS_PER_ENTRY] &= ~BITMAP_MASK(BITMAP_REMAINING_BITS(bit)); return 0; }
my_bool test_flip_bit(MY_BITMAP *map, uint bitsize) { uint i, test_bit; uint no_loops= bitsize > 128 ? 128 : bitsize; for (i=0; i < no_loops; i++) { test_bit= get_rand_bit(bitsize); bitmap_flip_bit(map, test_bit); if (!bitmap_is_set(map, test_bit)) goto error1; bitmap_flip_bit(map, test_bit); if (bitmap_is_set(map, test_bit)) goto error2; } return FALSE; error1: printf("Error in flip bit 1, bit %u, bitsize = %u", test_bit, bitsize); return TRUE; error2: printf("Error in flip bit 2, bit %u, bitsize = %u", test_bit, bitsize); return TRUE; }
int bitmap_next_zero(bitmap_t bitmap, size_t size, size_t offset) { int i; for(i = offset; i < size; i++) { if(bitmap_is_set(bitmap, i) == 0) return i; } return -1; }
/* Scans 'bitmap' from bit offset 'start' to 'end', excluding 'end' itself. * Returns the bit offset of the lowest-numbered bit set to 'target', or 'end' * if all of the bits are set to '!target'. */ size_t bitmap_scan(const unsigned long int *bitmap, bool target, size_t start, size_t end) { /* XXX slow */ size_t i; for (i = start; i < end; i++) { if (bitmap_is_set(bitmap, i) == target) { break; } } return i; }
/* Adds to 4096-bit VLAN bitmap 'b' a 1-bit in each position in the 'n_vlans' * bits indicated in 'vlans'. Returns the number of 1-bits added to 'b'. */ int vlan_bitmap_from_array__(const int64_t *vlans, size_t n_vlans, unsigned long int *b) { size_t i; int n; n = 0; for (i = 0; i < n_vlans; i++) { int64_t vlan = vlans[i]; if (vlan >= 0 && vlan < 4096 && !bitmap_is_set(b, vlan)) { bitmap_set1(b, vlan); n++; } } return n; }
int unpack_row_old(Relay_log_info *rli, TABLE *table, uint const colcnt, uchar *record, uchar const *row, MY_BITMAP const *cols, uchar const **row_end, ulong *master_reclength, MY_BITMAP* const rw_set, Log_event_type const event_type) { DBUG_ASSERT(record && row); my_ptrdiff_t const offset= record - (uchar*) table->record[0]; size_t master_null_bytes= table->s->null_bytes; if (colcnt != table->s->fields) { Field **fptr= &table->field[colcnt-1]; do master_null_bytes= (*fptr)->last_null_byte(); while (master_null_bytes == Field::LAST_NULL_BYTE_UNDEF && fptr-- > table->field); /* If master_null_bytes is LAST_NULL_BYTE_UNDEF (0) at this time, there were no nullable fields nor BIT fields at all in the columns that are common to the master and the slave. In that case, there is only one null byte holding the X bit. OBSERVE! There might still be nullable columns following the common columns, so table->s->null_bytes might be greater than 1. */ if (master_null_bytes == Field::LAST_NULL_BYTE_UNDEF) master_null_bytes= 1; } DBUG_ASSERT(master_null_bytes <= table->s->null_bytes); memcpy(record, row, master_null_bytes); // [1] int error= 0; bitmap_set_all(rw_set); Field **const begin_ptr = table->field; Field **field_ptr; uchar const *ptr= row + master_null_bytes; Field **const end_ptr= begin_ptr + colcnt; for (field_ptr= begin_ptr ; field_ptr < end_ptr ; ++field_ptr) { Field *const f= *field_ptr; if (bitmap_is_set(cols, field_ptr - begin_ptr)) { f->move_field_offset(offset); ptr= f->unpack(f->ptr, ptr); f->move_field_offset(-offset); /* Field...::unpack() cannot return 0 */ DBUG_ASSERT(ptr != NULL); } else bitmap_clear_bit(rw_set, field_ptr - begin_ptr); } *row_end = ptr; if (master_reclength) { if (*field_ptr) *master_reclength = (*field_ptr)->ptr - table->record[0]; else *master_reclength = table->s->reclength; } /* Set properties for remaining columns, if there are any. We let the corresponding bit in the write_set be set, to write the value if it was not there already. We iterate over all remaining columns, even if there were an error, to get as many error messages as possible. We are still able to return a pointer to the next row, so redo that. This generation of error messages is only relevant when inserting new rows. */ for ( ; *field_ptr ; ++field_ptr) { uint32 const mask= NOT_NULL_FLAG | NO_DEFAULT_VALUE_FLAG; DBUG_PRINT("debug", ("flags = 0x%x, mask = 0x%x, flags & mask = 0x%x", (*field_ptr)->flags, mask, (*field_ptr)->flags & mask)); if (event_type == WRITE_ROWS_EVENT && ((*field_ptr)->flags & mask) == mask) { rli->report(ERROR_LEVEL, ER_NO_DEFAULT_FOR_FIELD, "Field `%s` of table `%s`.`%s` " "has no default value and cannot be NULL", (*field_ptr)->field_name, table->s->db.str, table->s->table_name.str); error = ER_NO_DEFAULT_FOR_FIELD; } else (*field_ptr)->set_default(); } return error; }
static bool is_learning_vlan(const struct mac_learning *ml, uint16_t vlan) { return !(ml->flood_vlans && bitmap_is_set(ml->flood_vlans, vlan)); }