Esempio n. 1
0
func (c *PagingC) remove(info *ads.Info) {
	a, b := info.Prev, info.Next

	a.Next = b
	b.Prev = a

	info.Next = nil
	info.Prev = nil

	c.Count--
}
Esempio n. 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
}
Esempio n. 3
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)
}