circular-buffer

Must Clojure circular data structures involve constructs like ref?

谁说胖子不能爱 提交于 2019-12-19 07:38:14
问题 Today I've seen some references to tying the knot and circular data structures. I've been out reading some answers, and the solutions seem to involve using a ref to point back to the head of the list. One particular SO question showed a Haskell example, but I don't know Haskell well enough to know if the example was using a the Haskell equivalent of a ref. Is there a way to make a Clojure data structure circular without using a ref or similar construct? Thanks. 回答1: I straightforwardly

How to access array in circular manner in JavaScript

自闭症网瘾萝莉.ら 提交于 2019-12-17 18:29:19
问题 I have an array like [A,B,C,D] . I want to access that array within a for loop like as var arr = [A,B,C,D]; var len = arr.len; for(var i = 0;i<arr.len;i++){ 0 - A,B,C 1 - B,C,D 2 - C,D,A 3 - D,A,B } I want to access that like in JavaScript, any ideas? 回答1: Try this: var arr = ["A","B","C","D"]; for (var i=0, len=arr.length; i<len; i++) { alert(arr.slice(0, 3).join(",")); arr.push(arr.shift()); } Without mutating the array, it would be for (var i=0, len=arr.length; i<len; i++) { var str = arr

How to use a ring data structure in window functions

半城伤御伤魂 提交于 2019-12-17 14:01:28
问题 I have data that is arranged in a ring structure (or circular buffer), that is it can be expressed as sequences that cycle: ...-1-2-3-4-5-1-2-3-.... See this picture to get an idea of a 5-part ring: I'd like to create a window query that can combine the lag and lead items into a three point array, but I can't figure it out. For example at part 1 of a 5-part ring, the lag/lead sequence is 5-1-2, or at part 4 is 3-4-5. Here is an example table of two rings with different numbers of parts

efficient circular buffer?

人走茶凉 提交于 2019-12-17 05:38:49
问题 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)? 回答1: 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

ring buffer with numpy/ctypes

我怕爱的太早我们不能终老 提交于 2019-12-14 03:42:11
问题 I'm developing a client which will receive the [EEG] data over tcp and write it to the ring buffer. I thought it can be very convenient to have the buffer as a ctypes or numpy array because it's possible to create a numpy 'view' to any location of such buffer and read/write/process the data without any copying operations. Or is it a bad idea in general? However, I don't see how to implement a circular buffer of a fixed size this way. Suppose I have created a buffer object which is contiguous

iOS UI are causing a glitch in my audio stream

点点圈 提交于 2019-12-13 21:40:51
问题 I'm writing a VOIP based app for the iPhone. I'm having a strange issue where when the user presses the screen there is a glitch in the audio, this happens also when you press the volume up / down buttons on the phone itself. After days of debugging I've found its something to do with my circular buffer. I swapped mine for the one here: http://atastypixel.com/blog/a-simple-fast-circular-buffer-implementation-for-audio-processing/ this one doesn't cause a glitch but the latency is nearly 4

How to play pcm audio buffer from a socket server using audio unit circular buffer

旧城冷巷雨未停 提交于 2019-12-13 18:23:40
问题 I hope someone can help me. I am new to Objective-c and OSX and I am trying to play audio data I am receiving via socket into my audio queue. I found out this link https://stackoverflow.com/a/30318859/4274654 which in away address my issue with circular buffer. However when I try to run my project it returns It returns an error (OSStatus) -10865. That is why the code logs " Error enabling AudioUnit output bus". status = AudioUnitSetProperty(_audioUnit, kAudioOutputUnitProperty_EnableIO,

Possibility of using circular buffer in a single thread

帅比萌擦擦* 提交于 2019-12-13 05:36:20
问题 I have a single UDP thread which reads multiple datagrams through recvmmsg system call from different multiplexed streams and pushes them in different circular/ring buffers. These ring buffers are part of Stream structures. Each stream is sending a speech frame every 20ms. So the UDP packets might look like this: F1S1 F1S2 F1S3 F2S1 and so on OR in case of a burst it might look like this: F1S1 F2S1 F3S1 F1S2 and so on. After the reception, these packets will be processed in parallel by a

Producer/consumer seems to be in deadlock when buffer is smaller than input from producer

纵饮孤独 提交于 2019-12-13 04:39:58
问题 I made a circular buffer with multiple clients writing (in the end I want them to write messages of different size) into a buffer. The server reads them out. It's based on the code in a consumer/producer problem: #include <stdio.h> #include <malloc.h> #include <string.h> #include <pthread.h> #include <unistd.h> #define BUFFER_SIZE 10 struct cBuf{ char *buf; int size; int start; int end; pthread_mutex_t mutex; pthread_cond_t buffer_full; pthread_cond_t buffer_empty; }; struct cBuf cb; void buf

Simplified algorithm for calculating remaining space in a circular buffer?

人盡茶涼 提交于 2019-12-12 09:38:58
问题 I was wonder if there is a simpler (single) way to calculate the remaining space in a circular buffer than this? int remaining = (end > start) ? end-start : bufferSize - start + end; 回答1: If you're worried about poorly-predicted conditionals slowing down your CPU's pipeline, you could use this: int remaining = (end - start) + (-((int) (end <= start)) & bufferSize); But that's likely to be premature optimisation (unless you have really identified this as a hotspot). Stick with your current