aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2022-03-31 14:04:51 -0500
committerAnthony Wang2022-03-31 14:04:51 -0500
commitaa1f53c83e4fbccde7f21555a9e5230a8652309a (patch)
tree56732df7dbf1c6bb2b705d07f0a351aaddccfe4d
parentd39bb36216ba896096cc1a9f61f09b14002b59e5 (diff)
Use pointers for struct functions to avoid copies
-rw-r--r--segmenttree.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/segmenttree.go b/segmenttree.go
index edda5c0..066c1f1 100644
--- a/segmenttree.go
+++ b/segmenttree.go
@@ -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
}