Skip to content

Commit

Permalink
Revert "Simplified rowutil.ToVersionedRows, made faster"
Browse files Browse the repository at this point in the history
This reverts commit cd793fd.
  • Loading branch information
elimisteve committed Jan 8, 2017
1 parent cd793fd commit b020738
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions rowutil/version.go
Expand Up @@ -26,9 +26,6 @@ func ToVersionedRows(origRows types.Rows, rowLess func(r1, r2 *types.Row) bool)

ORIG_VERSION_ROW_PREFIX := "origversionrow:"

var firsts types.Rows
firstToRows := map[*types.Row]types.Rows{}

// Create map[groupTag]Rows to group the rows together by the
// ID-tag of the original Row that has since been versioned
mRows := make(map[string]types.Rows, len(rows))
Expand All @@ -42,24 +39,25 @@ func ToVersionedRows(origRows types.Rows, rowLess func(r1, r2 *types.Row) bool)
// origversionrow:id:... -> id:...
tag = tag[len(ORIG_VERSION_ROW_PREFIX):]
}

// assert: tag is of the form id:..., where this tag is the
// ID-tag of the original version of every Row in rows
mRows[tag] = append(mRows[tag], r)
}

// Record the first member of each version slice so we can
// order the outer slice by them
if len(mRows[tag]) == 0 {
firsts = append(firsts, r)
}
// Each version slice is now individually ordered, but we need to
// return them in a [][]*Row. What should the ordering of this
// slice of slices be? Answer: ordered by the first member of each
// version slice.

// Each version slice itself is implicitly ordered, but we
// need to return a slice of slices -- a [][]*Row. What should
// the ordering of this slice of slices be? Answer: ordered by
// the first member of each version slice.
firsts := make(types.Rows, 0, len(mRows))
firstToRows := make(map[*types.Row]types.Rows, len(firsts))

mRows[tag] = append(mRows[tag], r)
firstToRows[mRows[tag][0]] = mRows[tag]
for _, rowGroup := range mRows {
firsts = append(firsts, rowGroup[0])
// Map the first element of each slice to its containing slice
firstToRows[rowGroup[0]] = rowGroup
}
firsts.Sort(rowLess)

for _, fr := range firsts {
rrows = append(rrows, firstToRows[fr])
Expand Down

0 comments on commit b020738

Please sign in to comment.