C# 嵌套私有类

发布于 2024-11-17 18:15:44 字数 533 浏览 3 评论 0原文

我正在创建自己的优先级队列。它不是典型的优先级队列,因为项目是以给定优先级插入的。相反,可以将项目添加到队列中,并且它们以最高优先级开始(假设我们有 5 个队列,队列 1=最高优先级,队列 5=最低优先级)),因此该项目最初添加到队列 1 中。

该数据结构的用户可以获得 next() 元素,该元素根据我感兴趣的一些因素(即优先级)返回一个元素,但它不会从整个数据结构中出列。用户对从先前调用 next() 返回的项目的有效性提供一些反馈(例如,通过/失败结果),并基于该反馈,将项目的优先级向上或向下移动。基本上,失败的元素的使用频率较低,并且我有机制最终删除经常失败的元素。

1)有什么改进界面的建议吗?我不喜欢必须从 next() 调用中检索元素,然后通过另一个函数调用提供反馈。当状态变得混乱时,犯错的空间太大了。 (即用户在获取下一个元素之前不报告结果......等等)。另外,希望允许它是线程安全的。

2)我正在使用一个私有嵌套类,它包装了我感兴趣的元素以及与每个元素关联的一些属性来跟踪元素的统计信息(例如通过/失败计数等...),并且想知道是否有是一种从内部类访问外部类成员的方法吗?

I am creating my own priority queue of sorts. It is not a typical priority queue in that items are inserted with a given priority. Rather items can be added to the queue and they begin at the highest priority(let say we have 5 queues, queue 1=highest priority, queue5=lowest)), so the item is added to queue 1 initially.

The user of this data structure can get the next() element, which returns an element based on some factors that I am interested in, namely the priority, but it is not dequeued from the entire data structure. The user provides some feedback to the validity of the item returned from the previous call to next()(eg. a pass/fail result), and based on that, the item is moved up or down in priority. Basically, elements that fail get used less often and I have mechanisms to eventually remove elements that fail too often.

1)Any suggestions to improve the interface? I do not like having to retrieve an element from the next() call and then provide feedback with another function call. There is too much room for error where the state gets messed up. (ie user does not report result before getting next element..etc...). Also, it would be desireable to allow this to be thread safe.

2)I am using a private nested class that wraps the elements I am interested in along with some attributes associated with each element to track statistics on the element(eg pass/fail counts etc...), and would like to know if there was a way to access the outer class members from the inner class?

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

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

发布评论

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

评论(1

贱人配狗天长地久 2024-11-24 18:15:44

不确定我是否完全理解这个问题,但是 next() 不等待返回的反馈有什么问题?该结构的用户将 next() 元素从队列中拉出,然后在准备好时对该元素进行 SubmitFeedback() 。同时,其他用户也可以异步提取 next() 元素。队列会处理传入的呼叫。如果这没有帮助,您能否更详细地解释处理状态的问题?

Not sure I understand the question exactly, but what is wrong with the next() not waiting for the returned feedback? Users of the structure pull the next() element out of the queue and then submitFeedback() on the element when they are ready. Meanwhile, other users can pull out the next() elements as well, asynchronously. The queue handles calls as they come in. If this doesn't help, could you explain the problem with handling state in more detail?

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