Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › zig › llvm › Builder › getOrPutConstantAggregateAssumeCapacity Private Type Function getOrPutConstantAggregateAssumeCapacity Doc Source Private Type Function std.zig.llvm.Builder.getOrPutConstantAggregateAssumeCapacity
fn getOrPutConstantAggregateAssumeCapacity (
self : *Builder ,
tag : Constant .Tag ,
ty : Type ,
vals : []const Constant ,
) struct File zig/llvm/Builder.zig: 13097
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139 fn getOrPutConstantAggregateAssumeCapacity (
self : *Builder ,
tag : Constant .Tag ,
ty : Type ,
vals : []const Constant ,
) struct { new : bool , constant : Constant } {
switch (tag ) {
.structure , .packed_structure , .array , .vector => {},
else => unreachable ,
}
const Key = struct { tag : Constant .Tag , type : Type , vals : []const Constant };
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 .type ));
hasher .update (std .mem .sliceAsBytes (key .vals ));
return @truncate (hasher .final ());
}
pub fn eql (ctx : @This (), lhs_key : Key , _ : void , rhs_index : usize ) bool {
if (lhs_key .tag != ctx .builder .constant_items .items (.tag )[rhs_index ]) return false ;
const rhs_data = ctx .builder .constant_items .items (.data )[rhs_index ];
var rhs_extra = ctx .builder .constantExtraDataTrail (Constant .Aggregate , rhs_data );
if (lhs_key .type != rhs_extra .data .type ) return false ;
const rhs_vals = rhs_extra .trail .next (@intCast (lhs_key .vals .len ), Constant , ctx .builder );
return std .mem .eql (Constant , lhs_key .vals , rhs_vals );
}
};
const gop = self .constant_map .getOrPutAssumeCapacityAdapted (
Key { .tag = tag , .type = ty , .vals = vals },
Adapter { .builder = self },
);
if (!gop .found_existing ) {
gop .key_ptr .* = {};
gop .value_ptr .* = {};
self .constant_items .appendAssumeCapacity (.{
.tag = tag ,
.data = self .addConstantExtraAssumeCapacity (Constant .Aggregate { .type = ty }),
});
self .constant_extra .appendSliceAssumeCapacity (@ptrCast (vals ));
}
return .{ .new = !gop .found_existing , .constant = @fromBackingInt (@intCast (gop .index )) };
}