Example #1
0
func (m *Sorted) UnsafeParseBinary(raw []byte) error {
	bs := byteblock.NewByteBlockSlicer(raw)

	magic, err := bs.Slice()
	if err != nil {
		return err
	}
	if string(magic) != MAGIC_SORTED {
		return errors.New("not a FSLM binary file")
	}

	header, err := bs.Slice()
	if err != nil {
		return err
	}

	numTransitions, err := m.parseHeader(header)
	if err != nil {
		return err
	}

	entryBytes, err := bs.Slice()
	if err != nil {
		return err
	}
	var entrySlice []WordStateWeight
	entryBytesHeader := (*reflect.SliceHeader)(unsafe.Pointer(&entryBytes))
	entrySliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&entrySlice))
	entrySliceHeader.Data = entryBytesHeader.Data
	entrySliceHeader.Len = entryBytesHeader.Len / int(unsafe.Sizeof(WordStateWeight{}))
	entrySliceHeader.Cap = entrySliceHeader.Len
	m.transitions = make([][]WordStateWeight, len(numTransitions))
	low := 0
	for i, n := range numTransitions {
		m.transitions[i] = entrySlice[low : low+n+1]
		low += n + 1
	}
	return nil
}
Example #2
0
func (m *Hashed) UnsafeParseBinary(raw []byte) error {
	bs := byteblock.NewByteBlockSlicer(raw)

	magic, err := bs.Slice()
	if err != nil {
		return err
	}
	if string(magic) != MAGIC_HASHED {
		return errors.New("not a FSLM binary file")
	}

	header, err := bs.Slice()
	if err != nil {
		return err
	}

	numBuckets, err := m.parseHeader(header)
	if err != nil {
		return err
	}

	entryBytes, err := bs.Slice()
	if err != nil {
		return err
	}
	var entrySlice []xqwEntry
	entryBytesHeader := (*reflect.SliceHeader)(unsafe.Pointer(&entryBytes))
	entrySliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&entrySlice))
	entrySliceHeader.Data = entryBytesHeader.Data
	entrySliceHeader.Len = entryBytesHeader.Len / int(unsafe.Sizeof(xqwEntry{}))
	entrySliceHeader.Cap = entrySliceHeader.Len
	m.transitions = make([]xqwBuckets, len(numBuckets))
	low := 0
	for i, n := range numBuckets {
		m.transitions[i] = xqwBuckets(entrySlice[low : low+n])
		low += n
	}
	return nil
}
Example #3
0
func IsSortedBinary(raw []byte) bool {
	bs := byteblock.NewByteBlockSlicer(raw)
	magic, err := bs.Slice()
	return err == nil && string(magic) == MAGIC_SORTED
}