Skip to content

Commit f7598b0

Browse files
committed
Replaced slice pointer arguments with slice arguments where slice modification is not required
1 parent 7c4d5bf commit f7598b0

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

dbscan.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type dbscanClusterer struct {
1919
j chan *rangeJob
2020
m *sync.Mutex
2121
w *sync.WaitGroup
22-
p *[]float64
22+
p []float64
2323
r *[]int
2424

2525
// visited points
@@ -194,7 +194,7 @@ func (c *dbscanClusterer) nearest(p int, l *int, r *[]int) {
194194

195195
*r = (*r)[:0]
196196

197-
c.p = &c.d[p]
197+
c.p = c.d[p]
198198
c.r = r
199199

200200
c.w.Add(c.s)
@@ -240,7 +240,7 @@ func (c *dbscanClusterer) endNearestWorkers() {
240240
func (c *dbscanClusterer) nearestWorker() {
241241
for j := range c.j {
242242
for i := j.a; i < j.b; i++ {
243-
if c.distance(*c.p, c.d[i]) < c.eps {
243+
if c.distance(c.p, c.d[i]) < c.eps {
244244
c.m.Lock()
245245
*c.r = append(*c.r, i)
246246
c.m.Unlock()

optics.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type opticsClusterer struct {
3030
c chan *clusterJob
3131
m *sync.Mutex
3232
w *sync.WaitGroup
33-
p *[]float64
33+
p []float64
3434
r *[]int
3535

3636
// visited points
@@ -190,10 +190,10 @@ func (c *opticsClusterer) run() {
190190

191191
c.so = append(c.so, i)
192192

193-
if d = c.coreDistance(i, l, &ns); d != 0 {
193+
if d = c.coreDistance(i, l, ns); d != 0 {
194194
q = newPriorityQueue(l)
195195

196-
c.update(i, d, l, &ns, &q)
196+
c.update(i, d, l, ns, &q)
197197

198198
for q.NotEmpty() {
199199
p = q.Pop().(*pItem)
@@ -204,46 +204,46 @@ func (c *opticsClusterer) run() {
204204

205205
c.so = append(c.so, p.v)
206206

207-
if d = c.coreDistance(p.v, l, &nss); d != 0 {
208-
c.update(p.v, d, l, &nss, &q)
207+
if d = c.coreDistance(p.v, l, nss); d != 0 {
208+
c.update(p.v, d, l, nss, &q)
209209
}
210210
}
211211
}
212212
}
213213
}
214214

215-
func (c *opticsClusterer) coreDistance(p int, l int, r *[]int) float64 {
215+
func (c *opticsClusterer) coreDistance(p int, l int, r []int) float64 {
216216
if l < c.minpts {
217217
return 0
218218
}
219219

220-
var d, m float64 = 0, c.distance(c.d[p], c.d[(*r)[0]])
220+
var d, m float64 = 0, c.distance(c.d[p], c.d[r[0]])
221221

222222
for i := 1; i < l; i++ {
223-
if d = c.distance(c.d[p], c.d[(*r)[i]]); d > m {
223+
if d = c.distance(c.d[p], c.d[r[i]]); d > m {
224224
m = d
225225
}
226226
}
227227

228228
return m
229229
}
230230

231-
func (c *opticsClusterer) update(p int, d float64, l int, r *[]int, q *priorityQueue) {
231+
func (c *opticsClusterer) update(p int, d float64, l int, r []int, q *priorityQueue) {
232232
for i := 0; i < l; i++ {
233-
if !c.v[(*r)[i]] {
234-
m := math.Max(d, c.distance(c.d[p], c.d[(*r)[i]]))
233+
if !c.v[r[i]] {
234+
m := math.Max(d, c.distance(c.d[p], c.d[r[i]]))
235235

236-
if c.re[(*r)[i]] == nil {
236+
if c.re[r[i]] == nil {
237237
item := &pItem{
238-
v: (*r)[i],
238+
v: r[i],
239239
p: m,
240240
}
241241

242-
c.re[(*r)[i]] = item
242+
c.re[r[i]] = item
243243

244244
q.Push(item)
245-
} else if m < c.re[(*r)[i]].p {
246-
q.Update(c.re[(*r)[i]], c.re[(*r)[i]].v, m)
245+
} else if m < c.re[r[i]].p {
246+
q.Update(c.re[r[i]], c.re[r[i]].v, m)
247247
}
248248
}
249249
}
@@ -474,7 +474,7 @@ func (c *opticsClusterer) nearest(p int, l *int, r *[]int) {
474474

475475
*r = (*r)[:0]
476476

477-
c.p = &c.d[p]
477+
c.p = c.d[p]
478478
c.r = r
479479

480480
c.w.Add(c.s)
@@ -520,7 +520,7 @@ func (c *opticsClusterer) endNearestWorkers() {
520520
func (c *opticsClusterer) nearestWorker() {
521521
for j := range c.j {
522522
for i := j.a; i < j.b; i++ {
523-
if c.distance(*c.p, c.d[i]) < c.eps {
523+
if c.distance(c.p, c.d[i]) < c.eps {
524524
c.m.Lock()
525525
*c.r = append(*c.r, i)
526526
c.m.Unlock()

0 commit comments

Comments
 (0)