@@ -142,7 +142,7 @@ func (t *Table) Rows() []Row {
142142// AddBindings add the new binings provided to the table.
143143func (t * Table ) AddBindings (bs []string ) {
144144 for _ , b := range bs {
145- if _ , ok := t .mbs [b ]; ! ok {
145+ if ! t .mbs [b ] {
146146 t .mbs [b ] = true
147147 t .bs = append (t .bs , b )
148148 }
@@ -216,7 +216,7 @@ func equalBindings(b1, b2 map[string]bool) bool {
216216 return false
217217 }
218218 for k := range b1 {
219- if _ , ok := b2 [k ]; ! ok {
219+ if ! b2 [k ] {
220220 return false
221221 }
222222 }
@@ -242,22 +242,15 @@ func (t *Table) AppendTable(t2 *Table) error {
242242// disjointBinding returns true if they are not overlapping bindings, false
243243// otherwise.
244244func disjointBinding (b1 , b2 map [string ]bool ) bool {
245- m := make (map [string ]int )
246245 for k := range b1 {
247- m [k ]++
248- }
249- for k := range b2 {
250- m [k ]++
251- }
252- for _ , cnt := range m {
253- if cnt != 1 {
246+ if b2 [k ] {
254247 return false
255248 }
256249 }
257250 return true
258251}
259252
260- // MergeRows takes a list of rors and returns a new map containing both.
253+ // MergeRows takes a list of rows and returns a new map containing both.
261254func MergeRows (ms []Row ) Row {
262255 res := make (map [string ]* Cell )
263256 for _ , om := range ms {
@@ -750,13 +743,13 @@ func (t *Table) Reduce(cfg SortConfig, aaps []AliasAccPair) error {
750743 return nil
751744}
752745
753- // Filter removes all the rows were the provided function returns true.
746+ // Filter removes all the rows where the provided function returns true.
754747func (t * Table ) Filter (f func (Row ) bool ) {
755- for idx , processed := 0 , len ( t . data ); processed > 0 ; processed -- {
756- if f ( t .data [ idx ]) {
757- t . data = append ( t . data [: idx ], t . data [ idx + 1 :] ... )
758- idx --
748+ var newData [] Row
749+ for _ , r := range t .data {
750+ if ! f ( r ) {
751+ newData = append ( newData , r )
759752 }
760- idx ++
761753 }
754+ t .data = newData
762755}
0 commit comments