无隐含结构的无序集合项的变量名

发布于 2024-08-22 08:30:03 字数 599 浏览 3 评论 0原文

这个问题将以特定的形式提出,但适用于更一般的问题,即如何命名无序集合项而不暗示任何类型的结构。

根据图论,连通的无向图将包含通过边连接的顶点。

当创建一个带有两个成员变量的边类时,这两个成员变量代表边连接的两个顶点,在描述这两个不包含某种形式的隐含结构的变量时存在困难。

考虑 边缘类{ 顶点 v1; 顶点 v2; } 或者 边缘类{ 顶点向左; 顶点向右; } 或者 边缘类{ 顶点a; 顶点b; }

{v1, v2} 意味着顺序和比二更大的可能大小,尽管一条边只有两端。

{a,b}与{v1,v2}类似,只是替换了不同的符号。

{左,右}或{上,下}意味着方向,当图表不一定有任何空间参考时,这可能是违反直觉的,因为原始图表是纯粹的抽象。

{start, end} 适用于有向图,但在无向图中似乎是任意的。

我能考虑的最接近的是: 边缘类{ 顶点一端; 顶点另一端; } 但这感觉很糟糕。

什么名称符合此类变量的良好实践,而不暗示任何形式的方向、顺序或结构?

This question will be asked in a specific form, but applies to a more general question, how to name unordered set items without implying any sort of structure.

In terms of graph theory, a connected, undirected graph will contain vertices that are connected via edges.

When creating an edge class with two member variables that are vertices, representing the two vertices that the edge connects, there was a difficulty in describing the two variables that did not include some form of implied structure.

Consider
class Edge{
Vertex v1;
Vertex v2;
}

or
class Edge{
Vertex left;
Vertex right;
}

or
class Edge{
Vertex a;
Vertex b;
}

{v1, v2} implies order and a larger possible size than two, though an edge only has two ends.

{a, b} is similar to {v1,v2}, only substiting different symbols.

{left, right} or {up, down} imply direction, which may be counter-intuitive when there is not necessarily any spatial reference to the graph, since raw graphs are pure abstractions.

{start, end} would work for a directed graph but seems arbitrary in an undirected graph.

The closest that I can consider is:
class Edge{
Vertex oneEnd;
Vertex otherEnd;
}

but that feels kludgey.

What name complies with good practice for such variables without implying any form of direction, ordering, or structure?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江南月 2024-08-29 08:30:03

我会选择 Edge { Vertex v1;顶点 v2; }。我认为代码的用户不会将数字后缀解释为顺序,而只是将其解释为区分符。如果您的无序集合包含 10 或 100 个项目(例如多边形结构的情况),该怎么办?我确信最直观的解决方案是在命名项目时使用数字索引/后缀。

I'd go with Edge { Vertex v1; Vertex v2; }. I don't think that the user of your code will interpret the numerical suffixes as the order, but simply as differentiators. What if your unordered set contained 10 or 100 items, as could be the case with for example a polygon structure? I'm sure the most intuitive solution would be to use numerical indices/suffixes when naming the items.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文