| 1 | package multichoosescip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/ |
| 2 | |
| 3 | type MultiChoosescip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose# struct { |
| 4 | selectedscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#selected. []uint64 |
| 5 | lengthscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#length. int |
| 6 | limitscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#limit. int |
| 7 | } |
| 8 | |
| 9 | func (mc *MultiChoosescip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#) getSelectedscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#getSelected().(index int) bool { |
| 10 | if index < 0 || index > mc.lengthscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#length. { |
| 11 | return false |
| 12 | } |
| 13 | i := uint64(index) >> 6 |
| 14 | j := uint64(index) & 0x3F |
| 15 | return (mc.selectedscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#selected.[i] & (1 << j)) != 0 |
| 16 | } |
| 17 | |
| 18 | func (mc *MultiChoosescip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#) setSelectedscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#setSelected().(index int, value bool) { |
| 19 | if index < 0 || index > mc.lengthscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#length. { |
| 20 | return |
| 21 | } |
| 22 | i := uint64(index) >> 6 |
| 23 | j := uint64(index) & 0x3F |
| 24 | if value { |
| 25 | mc.selectedscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#selected.[i] |= (1 << j) |
| 26 | } else { |
| 27 | mc.selectedscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#selected.[i] &^= (1 << j) |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | func Newscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/New().(length int) *MultiChoosescip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose# { |
| 32 | return &MultiChoosescip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#{ |
| 33 | selectedscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#selected.: make([]uint64, (length>>6)+1), |
| 34 | lengthscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#length.: length, |
| 35 | limitscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#limit.: -1, |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | func (mc MultiChoosescip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#) Countscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#Count().() int { |
| 40 | count := 0 |
| 41 | for i := 0; i <= mc.lengthscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#length.; i++ { |
| 42 | if mc.getSelectedscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#getSelected().(i) { |
| 43 | count++ |
| 44 | } |
| 45 | } |
| 46 | return count |
| 47 | } |
| 48 | |
| 49 | func (mc *MultiChoosescip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#) Selectscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#Select().(index int) { |
| 50 | if mc.limitscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#limit. >= 0 && mc.Countscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#Count().() >= mc.limitscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#limit. { |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | mc.setSelectedscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#setSelected().(index, true) |
| 55 | } |
| 56 | |
| 57 | func (mc *MultiChoosescip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#) Deselectscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#Deselect().(index int) { |
| 58 | mc.setSelectedscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#setSelected().(index, false) |
| 59 | } |
| 60 | |
| 61 | func (mc MultiChoosescip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#) IsSelectedscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#IsSelected().(index int) bool { |
| 62 | return mc.getSelectedscip-go gomod github.com/cqroot/multichoose . `github.com/cqroot/multichoose`/MultiChoose#getSelected().(index) |
| 63 | } |