1
1
import ArbitrarySizeDeque from './ArbitrarySizeDeque.js' ;
2
2
3
3
export default function UnboundedDeque ( iterable ) {
4
- this . growth = 2 ;
4
+ this . _growth = 2 ;
5
5
6
- this . minsize = 10 ;
6
+ this . _minsize = 10 ;
7
7
8
- this . currentsize = this . minsize ;
8
+ this . _currentsize = this . _minsize ;
9
9
10
10
// eslint-disable-next-line unicorn/no-new-array
11
- this . container = new Array ( this . currentsize ) ;
11
+ this . _container = new Array ( this . _currentsize ) ;
12
12
13
- this . center = 0 ;
13
+ this . _center = 0 ;
14
14
15
15
this . length = 0 ;
16
16
@@ -35,44 +35,44 @@ UnboundedDeque.prototype._realloc = function (newsize) {
35
35
36
36
this . _copy ( container ) ;
37
37
38
- this . container = container ;
38
+ this . _container = container ;
39
39
40
- this . center = 0 ;
40
+ this . _center = 0 ;
41
41
42
- this . currentsize = newsize ;
42
+ this . _currentsize = newsize ;
43
43
} ;
44
44
45
45
UnboundedDeque . prototype . _shrink = function ( ) {
46
- const newsize = Math . max ( this . minsize , this . length * this . growth ) ;
46
+ const newsize = Math . max ( this . _minsize , this . length * this . _growth ) ;
47
47
48
- if ( newsize * this . growth >= this . currentsize ) {
48
+ if ( newsize * this . _growth >= this . _currentsize ) {
49
49
return ;
50
50
}
51
51
52
52
this . _realloc ( newsize ) ;
53
53
} ;
54
54
55
55
UnboundedDeque . prototype . _grow = function ( newlen ) {
56
- if ( newlen <= this . currentsize ) {
56
+ if ( newlen <= this . _currentsize ) {
57
57
return ;
58
58
}
59
59
60
- this . _realloc ( newlen * this . growth ) ;
60
+ this . _realloc ( newlen * this . _growth ) ;
61
61
} ;
62
62
63
63
UnboundedDeque . prototype . len = function ( ) {
64
64
return this . length ;
65
65
} ;
66
66
67
67
UnboundedDeque . prototype . capacity = function ( ) {
68
- return this . currentsize ;
68
+ return this . _currentsize ;
69
69
} ;
70
70
71
71
UnboundedDeque . prototype . append = function ( x ) {
72
72
this . _grow ( this . length + 1 ) ;
73
73
74
- const i = ( this . center + this . length ) % this . currentsize ;
75
- this . container [ i ] = x ;
74
+ const i = ( this . _center + this . length ) % this . _currentsize ;
75
+ this . _container [ i ] = x ;
76
76
++ this . length ;
77
77
78
78
return this ;
@@ -81,23 +81,23 @@ UnboundedDeque.prototype.append = function (x) {
81
81
UnboundedDeque . prototype . appendleft = function ( x ) {
82
82
this . _grow ( this . length + 1 ) ;
83
83
84
- -- this . center ;
85
- this . center += this . currentsize ;
86
- this . center %= this . currentsize ;
87
- this . container [ this . center ] = x ;
84
+ -- this . _center ;
85
+ this . _center += this . _currentsize ;
86
+ this . _center %= this . _currentsize ;
87
+ this . _container [ this . _center ] = x ;
88
88
89
89
++ this . length ;
90
90
91
91
return this ;
92
92
} ;
93
93
94
94
UnboundedDeque . prototype . clear = function ( ) {
95
- this . currentsize = this . minsize ;
95
+ this . _currentsize = this . _minsize ;
96
96
97
97
// eslint-disable-next-line unicorn/no-new-array
98
- this . container = new Array ( this . currentsize ) ;
98
+ this . _container = new Array ( this . _currentsize ) ;
99
99
100
- this . center = 0 ;
100
+ this . _center = 0 ;
101
101
102
102
this . length = 0 ;
103
103
@@ -111,7 +111,7 @@ UnboundedDeque.prototype.copy = function () {
111
111
UnboundedDeque . prototype . _where = function ( i ) {
112
112
this . _checkbounds ( i ) ;
113
113
114
- return [ this . container , ( this . center + i ) % this . currentsize ] ;
114
+ return [ this . _container , ( this . _center + i ) % this . _currentsize ] ;
115
115
} ;
116
116
117
117
UnboundedDeque . prototype . _popindex = function ( container , index ) {
0 commit comments