@@ -1110,38 +1110,41 @@ export function resizeUint8Array(array, byteSize) {
1110
1110
return newArray ;
1111
1111
}
1112
1112
1113
- export function Fifo ( capacity ) {
1114
- this . buffer = new Uint8Array ( capacity ) ;
1115
- this . size = 0 ;
1116
- this . wPtr = 0 ;
1117
- this . rPtr = 0 ;
1113
+ export class Fifo {
1114
+ constructor ( capacity ) {
1115
+ this . _buffer = new Uint8Array ( capacity ) ;
1116
+ this . _size = 0 ;
1117
+ this . _wPtr = 0 ;
1118
+ this . _rPtr = 0 ;
1119
+ }
1120
+ /** @returns {number } */
1121
+ get size ( ) { return this . _size ; }
1122
+ /** @returns {boolean } */
1123
+ get full ( ) {
1124
+ return this . _size === this . _buffer . length ;
1125
+ }
1126
+ /** @returns {boolean } */
1127
+ get empty ( ) {
1128
+ return this . _size === 0 ;
1129
+ }
1130
+ clear ( ) {
1131
+ this . _size = 0 ;
1132
+ this . _wPtr = 0 ;
1133
+ this . _rPtr = 0 ;
1134
+ }
1135
+ /** @type {Number } b */
1136
+ put ( b ) {
1137
+ if ( this . full ) return ;
1138
+ this . _buffer [ this . _wPtr % this . _buffer . length ] = b ;
1139
+ this . _wPtr ++ ;
1140
+ this . _size ++ ;
1141
+ }
1142
+ /** @returns {Number } */
1143
+ get ( ) {
1144
+ if ( this . empty ) return ;
1145
+ const res = this . _buffer [ this . _rPtr % this . _buffer . length ] ;
1146
+ this . _rPtr ++ ;
1147
+ this . _size -- ;
1148
+ return res ;
1149
+ }
1118
1150
}
1119
-
1120
- Fifo . prototype . full = function ( ) {
1121
- return this . size === this . buffer . length ;
1122
- } ;
1123
-
1124
- Fifo . prototype . empty = function ( ) {
1125
- return this . size === 0 ;
1126
- } ;
1127
-
1128
- Fifo . prototype . clear = function ( ) {
1129
- this . size = 0 ;
1130
- this . wPtr = 0 ;
1131
- this . rPtr = 0 ;
1132
- } ;
1133
-
1134
- Fifo . prototype . put = function ( b ) {
1135
- if ( this . full ( ) ) return ;
1136
- this . buffer [ this . wPtr % this . buffer . length ] = b ;
1137
- this . wPtr ++ ;
1138
- this . size ++ ;
1139
- } ;
1140
-
1141
- Fifo . prototype . get = function ( ) {
1142
- if ( this . empty ( ) ) return ;
1143
- const res = this . buffer [ this . rPtr % this . buffer . length ] ;
1144
- this . rPtr ++ ;
1145
- this . size -- ;
1146
- return res ;
1147
- } ;
0 commit comments