@@ -15,15 +15,12 @@ type clusterJob struct {
1515}
1616
1717type opticsClusterer struct {
18- minpts int
19- workers int
20- eps float64
21-
22- xi , x float64
18+ minpts , workers int
19+ eps , xi , x float64
2320
2421 distance DistanceFunc
2522
26- // slices holding the cluster mapping and sizes
23+ // slices holding the cluster mapping and sizes. Access is synchronized to avoid read during computation.
2724 mu sync.RWMutex
2825 a , b []int
2926
@@ -254,18 +251,13 @@ func (c *opticsClusterer) update(p int, d float64, l *int, r *[]int, q *priority
254251
255252func (c * opticsClusterer ) extract () {
256253 var (
257- i , e , us , ue , cs , ce , s , k int
258- mib , d float64
259- areas []* steepDownArea = make ([]* steepDownArea , 0 )
260- clusters map [int ]bool = make (map [int ]bool )
254+ i , k , e , ue , cs , ce , s , p int = 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0
255+ mib , d float64
256+ areas []* steepDownArea = make ([]* steepDownArea , 0 )
257+ clusters map [int ]bool = make (map [int ]bool )
261258 )
262259
263- for i < c .l - 1 {
264- if c.re [c.so [i ]] == nil || c .re [c .so [i + 1 ]] == nil {
265- i ++
266- continue
267- }
268-
260+ for i < c .l - 2 {
269261 mib = math .Max (mib , c.re [c.so [i ]].p )
270262
271263 if c .isSteepDown (i , & e ) {
@@ -291,7 +283,6 @@ func (c *opticsClusterer) extract() {
291283 i = e + 1
292284 mib = c.re [c.so [i ]].p
293285 } else if c .isSteepUp (i , & e ) {
294- us = i
295286 ue = e + 1
296287
297288 as := areas [:0 ]
@@ -308,9 +299,6 @@ func (c *opticsClusterer) extract() {
308299 }
309300 areas = as
310301
311- i = e + 1
312- mib = c.re [c.so [i ]].p
313-
314302 for j := 0 ; j < len (areas ); j ++ {
315303 if c.re [c.so [ue ]].p * c .x < areas [j ].mib {
316304 continue
@@ -331,24 +319,27 @@ func (c *opticsClusterer) extract() {
331319 ce = ue
332320 } else {
333321 cs = areas [j ].start
334- for k := us ; k < ue - 1 ; k ++ {
335- if math .Abs ((c.re [c.so [k ]].p - c.re [c.so [us ]].p )/ c.re [c.so [k ]].p ) <= c .xi {
322+ for k := i ; k < e ; k ++ {
323+ if math .Abs ((c.re [c.so [k ]].p - c.re [c.so [i ]].p )/ c.re [c.so [k ]].p ) <= c .xi {
336324 ce = k
337325 break
338326 }
339327 }
340328 }
341329
342- if ce - cs < c .minpts {
330+ p = ce - cs
331+
332+ if p < c .minpts {
343333 continue
344334 }
345335
346- s = cs + ce
336+ s = ce + cs
347337
348338 if ! clusters [s ] {
349339 clusters [s ] = true
350340
351- c .b [k ] = ce - cs
341+ c .b = append (c .b , 0 )
342+ c .b [k ] = p
352343
353344 c .w .Add (1 )
354345
@@ -361,6 +352,9 @@ func (c *opticsClusterer) extract() {
361352 k ++
362353 }
363354 }
355+
356+ i = ue
357+ mib = c.re [c.so [i ]].p
364358 } else {
365359 i ++
366360 }
0 commit comments