Python 控制下一步的数据结构

Python 控制下一步的数据结构,python,algorithm,Python,Algorithm,我正在学习协同程序 class Scheduler: def __init__(self): self.ready = Queue() # a queue of tasks that are ready to run. self.taskmap = {} #dictionary that keeps track of all active tasks (each task has a unique integer task ID) def new

我正在学习协同程序

class Scheduler:
    def __init__(self):
        self.ready = Queue() # a queue of tasks that are ready to run.
        self.taskmap = {} #dictionary that keeps track of all active tasks (each task has a unique integer task ID)

    def new(self, target): #introduce a new task to the scheduler
        newtask = Task(target)
        self.taskmap[newtask.tid] = newtask
        self.schedule(newtask)
        return newtask.tid

    def schedule(self, task):
        self.ready.put(task)

    def mainloop(self):
        while self.taskmap: #does not remove element from taskmap
            task = self.ready.get() self.ready
            result = task.run()
            self.schedule(task)
在阅读schedule中的
task=self.ready.get()
时,我突然意识到数据结构的本质是控制,控制下一步,而算法的本质也是控制,控制所有步骤


理解有意义吗?

队列对象定义了下一步的控制,是的。正如所描述的,这是FIFO

在这里,看起来您只是试图跟踪任务,是否还有剩余任务,哪些任务正在执行,等等。这是“控制所有步骤”。是的


不清楚的是目的。数据结构和算法应该适合您的目的<例如,代码>异步IO可以帮助您实现并行性和事件驱动设计。有时,目标是快速有效地将数据从源渲染到数据结构中。在最终目标的背景下,你所得到的更有意义(至少对我而言)。

你的问题(或你想表达的任何问题)不清楚。我非常感谢你的指导。你能(非常害羞)介绍一本你读过的学习算法和数据结构的书吗?没什么好害羞的。Goodrich等人的Python中的数据结构和算法是我个人最喜欢的Python教科书(无附属关系)。谢谢。我正在读上周六的那本书,哈哈。我很高兴知道数据结构和算法只是一个相同对象的两面。我不确定你是指上周六的那本书,但我为你和你的新学习感到兴奋。祝你好运