Skip to content

Commit

Permalink
feat: data/table: add TableSet.LensOrdered()
Browse files Browse the repository at this point in the history
  • Loading branch information
grokify committed Dec 25, 2024
1 parent bbe5f73 commit e98784d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions data/table/table_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ func (ts *TableSet) Add(tbl ...*Table) error {
return nil
}

// LensOrdered returns a slice of table row counts.
func (ts *TableSet) LensOrdered() []int {
var lens []int
for _, ord := range ts.Order {
if tbl, ok := ts.TableMap[ord]; ok {
if tbl != nil {
lens = append(lens, len(tbl.Rows))
} else {
lens = append(lens, 0)
}
} else {
lens = append(lens, 0)
}
}
if len(lens) != len(ts.Order) {
panic("internal mismatch in `TableSet.LensOrdered(), calculated length vs. `TableSet.Order`")
}
return lens
}

func (ts *TableSet) TableNames() []string {
return maputil.Keys(ts.TableMap)
}
Expand Down

0 comments on commit e98784d

Please sign in to comment.