circular-buffer

efficient circular buffer?

会有一股神秘感。 提交于 2019-11-26 21:36:27
I want to create an efficient circular buffer in python (with the goal of taking averages of the integer values in the buffer). Is this an efficient way to use a list to collect values? def add_to_buffer( self, num ): self.mylist.pop( 0 ) self.mylist.append( num ) What would be more efficient (and why)? I would use collections.deque with a maxlen arg >>> import collections >>> d = collections.deque(maxlen=10) >>> d deque([], maxlen=10) >>> for i in xrange(20): ... d.append(i) ... >>> d deque([10, 11, 12, 13, 14, 15, 16, 17, 18, 19], maxlen=10) There is a recipe in the docs for deque that is

How do you implement a circular buffer in C?

荒凉一梦 提交于 2019-11-26 21:11:33
I have a need for a fixed-size (selectable at run-time when creating it, not compile-time) circular buffer which can hold objects of any type and it needs to be very high performance. I don't think there will be resource contention issues since, although it's in a multi-tasking embedded environment, it's a co-operative one so the tasks themselves can manage that. My initial thought were to store a simple struct in the buffer which would contain the type (simple enum/define) and a void pointer to the payload but I want this to be as fast as possible so I'm open to suggestions that involve

How do you implement a circular buffer in C?

十年热恋 提交于 2019-11-26 07:52:34
问题 I have a need for a fixed-size (selectable at run-time when creating it, not compile-time) circular buffer which can hold objects of any type and it needs to be very high performance. I don\'t think there will be resource contention issues since, although it\'s in a multi-tasking embedded environment, it\'s a co-operative one so the tasks themselves can manage that. My initial thought were to store a simple struct in the buffer which would contain the type (simple enum/define) and a void

How to create a closed (circular) ListView?

吃可爱长大的小学妹 提交于 2019-11-26 00:32:32
问题 I want to create a customized ListView (or similar) which will behave like a closed (circular) one: scrolling down - after the last item was reached the first begins (.., n-1, n, 1, 2, ..) scrolling upward - after the first item was reached the last begins (.., 2, 1, n, n-1, ..) It sounds simple conceptually but, apparently, there is no straightforward approach to do this. Can anyone point me to the right solution ? Thank you ! I have already received an answer (from Streets Of Boston on