Use pointers for struct functions to avoid copies
This commit is contained in:
parent
d39bb36216
commit
aa1f53c83e
|
@ -10,7 +10,7 @@ type segmentTree struct {
|
|||
}
|
||||
|
||||
// Build segment tree
|
||||
func (s segmentTree) Build(a *sql.Rows, l, r, n int) {
|
||||
func (s *segmentTree) Build(a *sql.Rows, l, r, n int) {
|
||||
if l == r {
|
||||
a.Next()
|
||||
a.Scan(&s.seg[n])
|
||||
|
@ -23,7 +23,7 @@ func (s segmentTree) Build(a *sql.Rows, l, r, n int) {
|
|||
}
|
||||
|
||||
// Update value at index x
|
||||
func (s segmentTree) Update(x, v, l, r, n int) {
|
||||
func (s *segmentTree) Update(x, v, l, r, n int) {
|
||||
if l == r {
|
||||
s.seg[n] = v
|
||||
return
|
||||
|
@ -38,7 +38,7 @@ func (s segmentTree) Update(x, v, l, r, n int) {
|
|||
}
|
||||
|
||||
// Find element with prefix sum v
|
||||
func (s segmentTree) Query(v, l, r, n int) (int, int) {
|
||||
func (s *segmentTree) Query(v, l, r, n int) (int, int) {
|
||||
if l == r {
|
||||
return s.seg[n], l
|
||||
}
|
||||
|
|
Reference in New Issue