package bucket // Bucket to store volume type Bucket struct { // Capacity amount the bucket can store Capacity uint64 // Volume is the current volume of the bucket Volume uint64 } // Fill sets the volume to the capacity to fill bucket func (b *Bucket) Fill() { b.Volume = b.Capacity } // Empty sets the volume to 0 func (b *Bucket) Empty() { b.Volume = 0 } // Pour fills the target bucket to the top func (b *Bucket) Pour(target *Bucket) { availableVolume := target.Capacity - target.Volume if availableVolume > b.Volume { target.Volume += b.Volume b.Volume = 0 } else { b.Volume -= availableVolume target.Volume += availableVolume } }