Skip to content
Snippets Groups Projects
Select Git revision
  • 7f4f1727389b04c0e7eca481d8a206d34f6b2b23
  • develop default protected
  • congestioncontrol
  • merge-v-data-collection-spammer-0.8.2
  • WIP-merge-v-data-collection-spammer-0.8.2
  • merge-v-data-collection-spammer-0.7.7
  • tmp
  • test-masterpow-fixing
  • test-masterpow
  • test-echo
  • v-data-collection
  • v-data-collection-spammer
  • tmp-dump-spam-info
  • dump-msg-info-0.3.1
  • test-dump-message-info
  • spammer-exprandom
  • extra/tutorial
  • without_tipselection
  • hacking-docker-network
  • hacking-docker-network-0.2.3
  • master
  • v0.2.3
22 results

signature.go

Blame
  • bc_ternary_multiplexer.go 1.20 KiB
    package ternary
    
    import (
    	"errors"
    	"strconv"
    
    	. "github.com/iotaledger/iota.go/trinary"
    )
    
    type BCTernaryMultiplexer struct {
    	trinaries []Trits
    }
    
    func NewBCTernaryMultiplexer() *BCTernaryMultiplexer {
    	this := &BCTernaryMultiplexer{make([]Trits, 0)}
    
    	return this
    }
    
    func (this *BCTernaryMultiplexer) Add(trits Trits) int {
    	this.trinaries = append(this.trinaries, trits)
    
    	return len(this.trinaries) - 1
    }
    
    func (this *BCTernaryMultiplexer) Get(index int) Trits {
    	return this.trinaries[index]
    }
    
    func (this *BCTernaryMultiplexer) Extract() (BCTrits, error) {
    	trinariesCount := len(this.trinaries)
    	tritsCount := len(this.trinaries[0])
    
    	result := BCTrits{
    		Lo: make([]uint, tritsCount),
    		Hi: make([]uint, tritsCount),
    	}
    
    	for i := 0; i < tritsCount; i++ {
    		bcTrit := &BCTrit{0, 0}
    
    		for j := 0; j < trinariesCount; j++ {
    			switch this.trinaries[j][i] {
    			case -1:
    				bcTrit.Lo |= 1 << uint(j)
    
    			case 1:
    				bcTrit.Hi |= 1 << uint(j)
    
    			case 0:
    				bcTrit.Lo |= 1 << uint(j)
    				bcTrit.Hi |= 1 << uint(j)
    
    			default:
    				return result, errors.New("Invalid trit #" + strconv.Itoa(i) + " in trits #" + strconv.Itoa(j))
    			}
    		}
    
    		result.Lo[i] = bcTrit.Lo
    		result.Hi[i] = bcTrit.Hi
    	}
    
    	return result, nil
    }