Multiset Stable Occurrence Allocation
Allocate typed occurrences stably against explicit per-key count budgets; earliest matching occurrences consume slots and all rejections remain indexed.
Description
Allocate typed occurrences stably against explicit per-key count budgets; earliest matching occurrences consume slots and all rejections remain indexed.
A multiset budget can admit only a limited number of occurrences of each value. Stable allocation gives earlier occurrences first access.
When to use this tool
Allocate typed occurrences stably against explicit per-key count budgets; earliest matching occurrences consume slots and all rejections remain indexed.
- Prepare the supplied valuesJson, budgetJson fields for this operation.
- Compare the complete example with the representation used by your own input before carrying the result into another step.
How to use the tool and how it works
- Enter valuesJson, budgetJson. Use the exact text syntax, units and index conventions explained below.
- Run the tool. If input validation fails, correct the supplied fields before interpreting any result.
- Read result.admitted, result.rejected, result.remaining. Interpret false, null and empty lists using the distinctions below; they can be valid outputs.
Parse valuesJson as scalar JSON values and budgetJson as value/count records. Aggregate positive counts by typed JSON value, scan occurrences in order and decrement the matching budget for each admitted index. Return admitted, rejected and positive remaining counts.1
| Input field | Meaning and representation | Accepted input |
|---|---|---|
| valuesJson | JSON text, entered as one text field. The decoded structure is illustrated below; it is not a separate file. | Text |
| budgetJson | JSON text, entered as one text field. The decoded structure is illustrated below; it is not a separate file. | Text |
For the JSON text fields, the following decoded structures show the example records before they are serialized into input strings. Keep field names, list nesting and value types as shown.
[
{
"field": "valuesJson",
"decoded": [
"a",
"b",
"a"
]
},
{
"field": "budgetJson",
"decoded": [
{
"value": "a",
"count": 1
}
]
}
] | Output field | Interpretation |
|---|---|
| result | Object containing the named outputs below. |
| result.admitted | The admitted list in the ordering and representation described above. |
| result.rejected | The rejected list in the ordering and representation described above. |
| result.remaining | The remaining list in the ordering and representation described above. |
{
"input": {
"valuesJson": "[\"a\",\"b\",\"a\"]",
"budgetJson": "[{\"value\":\"a\",\"count\":1}]"
},
"output": {
"result": {
"admitted": [
0
],
"rejected": [
1,
2
],
"remaining": []
}
}
} Limitations and assumptions
- String one and numeric one are distinct. No reordering, substitution or optimization is attempted; the budget is a supplied snapshot.
- All declared input fields are required and unexpected top-level fields are rejected. Numbers must be finite; lists are limited to 128 entries and ordinary text fields to 8,192 UTF-16 code units, with tighter limits where stated.
- JSON text inputs must parse within bounded nesting and size limits. Numeric outputs outside the safe finite range are rejected; large exact integer results use decimal strings. Indexes and half-open spans are zero-based unless a rank is explicitly described as one-based.
Alternative or Complementary methods
Keep occurrence sequences separate from count tables. Choose maximum union, additive concatenation or allocation deliberately, and apply any real inventory changes through a system that controls concurrent updates.
References
Similar or alternative tools
- Multiset Capped Count Table
Cap each normalized typed multiplicity at an explicit nonnegative integer and omit resulting zeros; no proportional redistribution.
- Multiset Complete Kit Count
Count complete typed kits consumable from an explicit inventory using the limiting required multiplicity; empty kit requirements are rejected.