tiny.pluck.bdd.LimitConfig
Defined in bdd.
API (20)
Actions
Public operations.
boundedAllocationFailedcheckIteLimitcheckNodeGrowthcheckTimeLimitinitreleaseIteCacheGrowthreserveIteCacheGrowthstartIteLimitstartTimeLimitstopIteLimitstopTimeLimit
Fields and members
Public fields and members.
ite_cache_reservationsite_limitite_limit_exceededstart_ite_cache_countstart_ite_countstart_node_countstart_timetime_limittime_limit_exceeded
Source
Source: lib/pluck/src/bdd.zig:279
zig
pub const LimitConfig = struct { time_limit: ?f64, ite_limit: ?u64, start_time: ?i64, start_ite_count: u64, start_node_count: usize, start_ite_cache_count: usize, ite_cache_reservations: usize, time_limit_exceeded: bool, ite_limit_exceeded: bool, pub fn init() LimitConfig { return LimitConfig{ .time_limit = null, .ite_limit = null, .start_time = null, .start_ite_count = 0, .start_node_count = 0, .start_ite_cache_count = 0, .ite_cache_reservations = 0, .time_limit_exceeded = false, .ite_limit_exceeded = false, }; } pub fn startTimeLimit(self: *LimitConfig, limit: f64) void { self.time_limit = limit; self.start_time = time.milliTimestamp(); self.time_limit_exceeded = false; } pub fn stopTimeLimit(self: *LimitConfig) void { self.time_limit = null; self.start_time = null; } pub fn startIteLimit( self: *LimitConfig, limit: u64, current_count: u64, node_count: usize, ite_cache_count: usize, ) void { std.debug.assert(self.ite_cache_reservations == 0); self.ite_limit = limit; self.start_ite_count = current_count; self.start_node_count = node_count; self.start_ite_cache_count = ite_cache_count; self.ite_cache_reservations = 0; self.ite_limit_exceeded = false; } pub fn stopIteLimit(self: *LimitConfig) void { std.debug.assert(self.ite_cache_reservations == 0); self.ite_limit = null; } pub fn checkTimeLimit(self: *LimitConfig) bool { if (self.time_limit) |limit| { if (self.start_time) |start| { const now = time.milliTimestamp(); const elapsed_seconds = @as(f64, @floatFromInt(now - start)) / 1000.0; if (elapsed_seconds >= limit) { self.time_limit_exceeded = true; return true; } } } return false; } pub fn checkIteLimit(self: *LimitConfig, current_count: u64) bool { if (self.ite_limit) |limit| { if (current_count -| self.start_ite_count >= limit) { self.ite_limit_exceeded = true; return true; } } return false; } pub fn checkNodeGrowth(self: *LimitConfig, current_count: usize) bool { if (self.ite_limit) |limit| { const growth: u64 = @intCast(current_count -| self.start_node_count); if (growth >= limit) { self.ite_limit_exceeded = true; return true; } } return false; } pub fn reserveIteCacheGrowth(self: *LimitConfig, current_count: usize) bool { if (self.ite_limit) |limit| { const growth: u64 = @intCast(current_count -| self.start_ite_cache_count); const reserved: u64 = @intCast(self.ite_cache_reservations); if (growth +| reserved >= limit) { self.ite_limit_exceeded = true; return true; } if (self.ite_cache_reservations == std.math.maxInt(usize)) { self.ite_limit_exceeded = true; return true; } self.ite_cache_reservations += 1; } return false; } pub fn releaseIteCacheGrowth(self: *LimitConfig) void { if (self.ite_limit == null) return; std.debug.assert(self.ite_cache_reservations > 0); self.ite_cache_reservations -= 1; } pub fn boundedAllocationFailed(self: *LimitConfig) bool { if (self.ite_limit == null) return false; self.ite_limit_exceeded = true; return true; }};Audit
| Definitions | 12 |
|---|---|
| Public names | 12 |
| Members | 9 |
| Version | 26.7.0 |
| Revision | daab053ee433 |