示例#1
0
func (c *PagingC) Load(info *ads.Info) {
	begin := time.Now()

	data := c.DB.Read(info.Token)

	c.LoadDiskTime += time.Now().Sub(begin)

	begin = time.Now()
	decoder := ads.Decoder{
		Reader: bytes.NewBuffer(data),
	}

	decoder.Decode(&info.Value)
	info.Value.MakeTransparent()

	for _, root := range ads.CollectChildren(info.Value) {
		var buffer [8]byte
		if n, err := decoder.Read(buffer[:]); n != 8 || err != nil {
			log.Panic(err)
		}

		info := root.GetInfo()
		info.Token = int64(binary.LittleEndian.Uint64(buffer[:]))
	}

	c.LoadTime += time.Now().Sub(begin)
}
示例#2
0
func (c *PagingC) Store(info *ads.Info) int64 {
	if info.Token != 0 {
		return info.Token
	}

	buffer := ads.GetFromPool()
	defer ads.ReturnToPool(buffer)

	ads.Hash(info.Value)

	buffer.Reset()
	e := ads.Encoder{
		Writer:      buffer,
		Transparent: map[ads.ADS]bool{info.Value: true},
	}
	e.Encode(&info.Value)

	for _, root := range ads.CollectChildren(info.Value) {
		info := ads.GetInfo(root)
		c.Store(info)

		var buffer [8]byte
		binary.LittleEndian.PutUint64(buffer[:], uint64(info.Token))
		if n, err := e.Write(buffer[:]); n != 8 || err != nil {
			log.Panic(err)
		}
	}

	info.Token = c.DB.Write(buffer.Bytes())
	return info.Token
}
示例#3
0
func (c *PagingC) MarkUsed(value ads.ADS, include bool) {
	if value.IsOpaque() {
		return
	}

	info := ads.GetInfo(value)

	if info.Next != nil {
		a, b := info.Prev, info.Next
		a.Next = b
		b.Prev = a
	} else {
		if !include {
			return
		} else {
			for _, child := range ads.CollectChildren(value) {
				c.MarkUsed(child, true)
			}
		}
		c.Count++
	}

	a, b := c.Tail.Prev, c.Tail
	a.Next = info
	info.Prev = a
	info.Next = b
	b.Prev = info
}