title: Double-ended queue - mask integer
body: <p>I'm having a hard time understanding what the mask integer is for (<strong>2nd line</strong>). I get that it regulates where values are placed in a double-ended queue, but I don't get how exactly. This is part of the code from a double-ended queue just to have some context.</p>
  <pre class="lang-java prettyprint-override"><code>public class DEQueue {
      private int mask = (1 &lt;&lt; 3) - 1;
      private String[] es = new String[mask + 1];
      private int head, tail;
  
  
      public void addFirst(String e) {
          es[head = (head - 1) &amp; mask] = e;
          if (tail == head) {
              doubleCapacity();
          }
      }
  
      public String pollFirst() {
          String result = es[head];
          es[head] = null;
          if (tail != head) {
              head = (head + 1) &amp; mask;
          }
          return result;
      }
  
      public String peekFirst() {
          return es[head];
      }
  
      public void addLast(String e) {
          es[tail] = e;
          tail = (tail + 1) &amp; mask;
          if (tail == head) {
              doubleCapacity();
          }
      }
  </code></pre>