这种物体有什么好名字呢?
我有一个元素 ID 与每个元素计数的关联数组。 例如(在Python中):
myObject = { 'a': 5, 'b': 3 }
它应该支持加法和减法。例如:
myObject - { 'a': 3 }
应评估为:
{ 'a': 2, 'b': 3 }
对于上下文,这是支持成本系统。每个元素都是一种资源类型,数量是实体拥有该资源的数量。用户可以将其中一个对象作为某种库存,但是一个项目可能将其中之一作为其成本。结果,用户对象可以简单地从他们的库存中减去该物品的成本。
我只是想为这种物体想一个好的术语。
I have an associative array of element IDs to counts of each element.
e.g. (in python):
myObject = { 'a': 5, 'b': 3 }
It should support addition and subtraction. For example:
myObject - { 'a': 3 }
Should evaluate to:
{ 'a': 2, 'b': 3 }
For context, this is supporting a costs system. Each element is a resource type, and the quantity is how much of that resource the entity owns. A user would have one of these objects as an inventory of some kind, but then an item might have one of these as its cost. As a result, the user object can simply subtract the item's cost from their inventory.
I'm just trying to think of a good term for this kind of object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这种集合类型已经存在于 Python 2.7 和 3.1 中。它称为计数器。
This collection type is already in Python 2.7 and 3.1. It's called a Counter.
我猜我会选择
ResourceVector
或ResourceTuple
。I'd go for
ResourceVector
orResourceTuple
I guess.我将其称为矩阵,而不知道您想要做什么的程度。
I would call that a Matrix, without knowing the extent of what you want to do.