This repository has been archived by the owner on Apr 26, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from gonum/clean-up
{search,traverse}: clean up after recent changes
- Loading branch information
Showing
9 changed files
with
218 additions
and
475 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright ©2015 The gonum Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package internal | ||
|
||
// IntSet is a set of integer identifiers. | ||
type IntSet map[int]struct{} | ||
|
||
// The simple accessor methods for Set are provided to allow ease of | ||
// implementation change should the need arise. | ||
|
||
// Add inserts an element into the set. | ||
func (s IntSet) Add(e int) { | ||
s[e] = struct{}{} | ||
} | ||
|
||
// Has reports the existence of the element in the set. | ||
func (s IntSet) Has(e int) bool { | ||
_, ok := s[e] | ||
return ok | ||
} | ||
|
||
// Remove deletes the specified element from the set. | ||
func (s IntSet) Remove(e int) { | ||
delete(s, e) | ||
} | ||
|
||
// Count reports the number of elements stored in the set. | ||
func (s IntSet) Count() int { | ||
return len(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright ©2015 The gonum Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package internal | ||
|
||
// BySliceValues implements the sort.Interface sorting a slice of | ||
// []int lexically by the values of the []int. | ||
type BySliceValues [][]int | ||
|
||
func (c BySliceValues) Len() int { return len(c) } | ||
func (c BySliceValues) Less(i, j int) bool { | ||
a, b := c[i], c[j] | ||
l := len(a) | ||
if len(b) < l { | ||
l = len(b) | ||
} | ||
for k, v := range a[:l] { | ||
if v < b[k] { | ||
return true | ||
} | ||
if v > b[k] { | ||
return false | ||
} | ||
} | ||
return len(a) < len(b) | ||
} | ||
func (c BySliceValues) Swap(i, j int) { c[i], c[j] = c[j], c[i] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.