feature. See also
. The project being documented here (as the example) is the Zig library itself.
Builder.debugEnumeratorAssumeCapacity
fn debugEnumeratorAssumeCapacity(
self: *Builder,
name: ?Metadata.String,
unsigned: bool,
bit_width: u32,
value: std.math.big.int.Const,
) Metadata
File
Code
fn debugEnumeratorAssumeCapacity(
self: *Builder,
name: ?Metadata.String,
unsigned: bool,
bit_width: u32,
value: std.math.big.int.Const,
) Metadata {
assert(!self.strip);
const Key = struct {
tag: Metadata.Tag,
name: Metadata.String.Optional,
bit_width: u32,
value: std.math.big.int.Const,
};
const Adapter = struct {
builder: *const Builder,
pub fn hash(_: @This(), key: Key) u32 {
var hasher = std.hash.Wyhash.init(std.hash.int(@backingInt(key.tag)));
hasher.update(std.mem.asBytes(&key.name));
hasher.update(std.mem.asBytes(&key.bit_width));
hasher.update(std.mem.sliceAsBytes(key.value.limbs));
return @truncate(hasher.final());
}
pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
if (lhs_key.tag != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false;
const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];
const rhs_extra = ctx.builder.metadataExtraData(Metadata.Enumerator, rhs_data);
const limbs = ctx.builder.metadata_limbs
.items[rhs_extra.limbs_index..][0..rhs_extra.limbs_len];
const rhs_value = std.math.big.int.Const{
.limbs = limbs,
.positive = lhs_key.value.positive,
};
return lhs_key.name == rhs_extra.name and
lhs_key.bit_width == rhs_extra.bit_width and
lhs_key.value.eql(rhs_value);
}
};
const tag: Metadata.Tag = if (unsigned)
.enumerator_unsigned
else if (value.positive)
.enumerator_signed_positive
else
.enumerator_signed_negative;
assert(!(tag == .enumerator_unsigned and !value.positive));
const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(Key{
.tag = tag,
.name = .wrap(name),
.bit_width = bit_width,
.value = value,
}, Adapter{ .builder = self });
if (!gop.found_existing) {
gop.key_ptr.* = {};
gop.value_ptr.* = {};
self.metadata_items.appendAssumeCapacity(.{
.tag = tag,
.data = self.addMetadataExtraAssumeCapacity(Metadata.Enumerator{
.name = .wrap(name),
.bit_width = bit_width,
.limbs_index = @intCast(self.metadata_limbs.items.len),
.limbs_len = @intCast(value.limbs.len),
}),
});
self.metadata_limbs.appendSliceAssumeCapacity(value.limbs);
}
return .{ .index = @intCast(gop.index), .kind = .node };
}