divviup_client::task::Histogram should have `length()` and `chunk_length()` methods
Closed this issue · 1 comments
inahga commented
Suppose a collector is using Divvi Up for task discovery. It needs to make Vdaf
instantiations which require the length and chunk_length. To get these values, it needs to match each variant of Histogram to extract these values, something like this:
DivviupVdaf::Histogram(histogram) => match histogram {
Histogram::Categorical {
buckets,
chunk_length,
} => Self::Prio3Histogram {
length: buckets.len(),
chunk_length: chunk_length
.ok_or_else(|| anyhow!("chunk_length must be provided for DAP-09 tasks"))?
.try_into()?,
},
Histogram::Continuous {
buckets,
chunk_length,
} => Self::Prio3Histogram {
length: buckets
.len()
.checked_add(1)
.ok_or_else(|| anyhow!("overflow when calculating histogram length"))?,
chunk_length: chunk_length
.ok_or_else(|| anyhow!("chunk_length must be provided for DAP-09 tasks"))?
.try_into()?,
},
Histogram::Length {
length,
chunk_length,
} => Self::Prio3Histogram {
length: length.try_into()?,
chunk_length: chunk_length
.ok_or_else(|| anyhow!("chunk_length must be provided for DAP-09 tasks"))?
.try_into()?,
},
},
It would be better if these were methods on Histogram instead, to avoid having to avoid the user needing to do the non-obvious matching logic themselves.
tgeoghegan commented
I believe I went and did this in #1019