OLD | NEW |
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2015, Daniel Murphy, Google | 2 * Copyright (c) 2015, Daniel Murphy, Google |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without modificati
on, | 5 * Redistribution and use in source and binary forms, with or without modificati
on, |
6 * are permitted provided that the following conditions are met: | 6 * are permitted provided that the following conditions are met: |
7 * * Redistributions of source code must retain the above copyright notice, | 7 * * Redistributions of source code must retain the above copyright notice, |
8 * this list of conditions and the following disclaimer. | 8 * this list of conditions and the following disclaimer. |
9 * * Redistributions in binary form must reproduce the above copyright notice, | 9 * * Redistributions in binary form must reproduce the above copyright notice, |
10 * this list of conditions and the following disclaimer in the documentation | 10 * this list of conditions and the following disclaimer in the documentation |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 void reset(List<T> buffer) { | 35 void reset(List<T> buffer) { |
36 _buffer = buffer; | 36 _buffer = buffer; |
37 _front = 0; | 37 _front = 0; |
38 _back = 0; | 38 _back = 0; |
39 _end = buffer.length; | 39 _end = buffer.length; |
40 } | 40 } |
41 | 41 |
42 void push(T task) { | 42 void push(T task) { |
43 if (_back >= _end) { | 43 if (_back >= _end) { |
44 BufferUtils.arraycopy( | 44 BufferUtils.arraycopy(_buffer, _front, _buffer, 0, _back - _front); |
45 _buffer, _front, _buffer, 0, _back - _front); | |
46 _back -= _front; | 45 _back -= _front; |
47 _front = 0; | 46 _front = 0; |
48 if (_back >= _end) { | 47 if (_back >= _end) { |
49 return; | 48 return; |
50 } | 49 } |
51 } | 50 } |
52 _buffer[_back++] = task; | 51 _buffer[_back++] = task; |
53 } | 52 } |
54 | 53 |
55 T pop() { | 54 T pop() { |
56 assert(_front < _back); | 55 assert(_front < _back); |
57 return _buffer[_front++]; | 56 return _buffer[_front++]; |
58 } | 57 } |
59 | 58 |
60 bool empty() { | 59 bool empty() { |
61 return _front >= _back; | 60 return _front >= _back; |
62 } | 61 } |
63 | 62 |
64 T front() { | 63 T front() { |
65 return _buffer[_front]; | 64 return _buffer[_front]; |
66 } | 65 } |
67 } | 66 } |
OLD | NEW |