需要关于定制数据结构和使用inmemory数据库的建议吗?

2024-04-25 23:19:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用Python2.6+编写一个类似网络调度的程序,其中我有一个复杂的队列要求:队列应该存储数据包,应该通过时间戳或O(1)中的数据包ID进行检索,应该能够检索到低于某个阈值的所有数据包,按优先级等对数据包进行排序。它应该以合理的复杂性插入和删除数据包。你知道吗

现在我有两个选择:

  1. 组合一些数据结构并适当地同步它们以满足我的需求。你知道吗
  2. 使用一些内存数据库,这样我就可以轻松地执行各种操作。你知道吗

有什么建议吗?你知道吗


Tags: 内存程序网络id数据库数据结构排序队列
2条回答

一个数据库只是围绕着一个单一的数据结构一个表的一些索引和花哨的算法。你无法控制引擎盖下发生的事情。你知道吗

我会尝试使用内置的Python数据结构。你知道吗

一个Fibonacci Heap可能是有益的,因为(引用文章):

Operations insert, find minimum, decrease key, and merge (union) work in constant amortized time. Operations delete and delete minimum work in O(log n) amortized time. This means that starting from an empty data structure, any sequence of a operations from the first group and b operations from the second group would take O(a + b log n) time. In a binomial heap such a sequence of operations would take O((a + b)log (n)) time. A Fibonacci heap is thus better than a binomial heap when b is asymptotically smaller than a.

相关问题 更多 >