Exemplo n.º 1
0
func (stack *Stack) ToArray() [][]byte {
	x := make([][]byte, 0, 4)
	list := (*list.List)(stack)
	for el := list.Back(); el != nil; el = el.Prev() {
		val, ok := el.Value.([]byte)
		if !ok {
			panic("Why is it not a byte array?")
		}
		x = append(x, val)
	}
	return x
}
Exemplo n.º 2
0
// FIXME: Update this to only overwrite if the value is different. This way the oldest stuff will have the oldest modify dates.
func (self *FileBackedMap) SaveToDisk() {
	list := self.LRUCache.expiration_list
	var key string
	var value uint64
	var entry *CacheEntry

	// Dump the cache to FS
	for node := list.Back(); node != nil; node = node.Prev() {
		entry = node.Value.(*CacheEntry)
		key = entry.Key
		value = entry.Value
		saveEntryToFile(self, key, value)
	}
}
Exemplo n.º 3
0
// GoString formats this GapSlice as a space-separated list of nodes surrounded
// by parentheses. Value nodes are represented by the GoString format of the
// value itself, while slice nodes are presented as a space-separated list of
// values in GoString format surrounded by square brackets.
func (s *GapSlice) GoString() string {
	list := s.list
	b := bytes.NewBufferString("(")
	for e := list.Front(); e != nil; e = e.Next() {
		if chunk, isChunk := e.Value.(gapSliceChunk); isChunk {
			b.WriteString(fmt.Sprintf("%v", chunk))
		} else {
			b.WriteString(fmt.Sprintf("%#v", e.Value))
		}
		if e != list.Back() {
			b.WriteRune(' ')
		}
	}
	b.WriteRune(')')
	return b.String()
}
Exemplo n.º 4
0
// String formats this GapSlice as a space-separated list of items surrounded
// by parentheses.
func (s *GapSlice) String() string {
	list := s.list
	b := bytes.NewBufferString("(")
	for e := list.Front(); e != nil; e = e.Next() {
		switch v := e.Value.(type) {
		case gapSliceChunk:
			last := len(v) - 1
			for i, item := range v {
				b.WriteString(fmt.Sprintf("%v", item))
				if i != last {
					b.WriteRune(' ')
				}
			}
		default:
			b.WriteString(fmt.Sprintf("%v", v))
		}
		if e != list.Back() {
			b.WriteRune(' ')
		}
	}
	b.WriteRune(')')
	return b.String()
}