/ blog

# Arrays

An array is a contiguous memory space that contains a certain amount of bytes.

a = int[3]

a[1] <- go to memory address of a and add how big my type is * the index (in this case 4 bytes (32 bit int) * 1)

TIP: In JS, use an ArrayBuffer to replicate true arrays.

# Array List

An array list gives you a push operation on top of an array (like a vec)

  1. Create initial capacity and track length
  2. If length is inside capacity, add or remove at index of length in constant time
  3. If length is at capacity, create a new array with more capacity, copy over all elements in order, continue with step two
  4. If you want to enqueue/dequeue at the front or middle, you have to move each item over one

# Array Buffer (Ring Buffer)

Aka VecDequeue in rust

  1. Create initial capacity and track index based head and length (index based tail)
  2. Head and tail can circle around to the other side. If the tail tries to insert off the array, take this.tail % len to get your tail's index in the front
  3. If your tail exceeds your head, you need to resize
  4. Start head at zero and rewrite in a larger capacity array