type Set map[MyType]struct{}type Hash int
type Set map[Hash]MySliceType--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi folks,Looking for an ideal way to represent a set (unordered collection) of slices.From what I can tell this is the standard approach for sets:type Set map[MyType]struct{}But since slices are not comparable they cannot be used for map keys. One solution I've seen is a hash as the key:type Hash int
type Set map[Hash]MySliceTypeBut I'd prefer not to manage the hashing.
Looking to define these sets pre-compile in source and dynamically generate them at runtime in the clearest way possible, without performance sacrifices. "Write that hash-based library" is a solution (or submit that patch to golang-set), but would prefer to use simple language features if possible to keep those static definitions clean and simple.
Hi folks,Looking for an ideal way to represent a set (unordered collection) of slices.From what I can tell this is the standard approach for sets:type Set map[MyType]struct{}But since slices are not comparable they cannot be used for map keys. One solution I've seen is a hash as the key:type Hash int
type Set map[Hash]MySliceTypeBut I'd prefer not to manage the hashing.
Can you specify what MyType is?
How many items do you expect to be in the set?
What are the performance requirements?
How often will you put things in / take out?
If _your_ notion of slice equality is coincident with equality of pointer-to-slice than you may just use map[*MySliceType].
Can you specify what MyType is?An ordered set of int8 pairs each representing a relative coordinate, combined to represent a path on a chess-like board (square grid). The set I am looking to represent is a set of these paths, representing the base moveset for a given piece.
On Friday, 28 November 2014 19:20:34 UTC+2, Matt Juran wrote:Can you specify what MyType is?An ordered set of int8 pairs each representing a relative coordinate, combined to represent a path on a chess-like board (square grid). The set I am looking to represent is a set of these paths, representing the base moveset for a given piece.How large is the maximum board?How large is the maximum relative coordinate?
type Point struct {
X int8
Y int8
}
type Path []Point
type PathSet map[*Path]struct{}
var MySet = PathSet{
&Path{{0, 1}, {0, 2}}: {},
&Path{{0, -1}, {0, -2}}: {},
}
...
for point,_ := range MySet {
// need to dereference point here
}--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/xNChXkrru9E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
You can encode each location on the board as a single integer. Then for each type of piece you precompute a vector of a set of valid moves. Then i-th entry is a set of locations this kind of piece can be moved to. This valid moves set can be represented as a 100 element vector of booleans or a string (if you further convert 0..99 to a char range). A particular path is just a slice of ints or a string. If you're doing alpha-beta pruning, you will be constructing a number of such candidate paths. If you also want to compare a candidate path against a set of "known to be better" paths, you will likely want a prefix tree. (Ignore the previous sentence if it doesn't make sense!)
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
type map[*MySliceType]struct{}type map[MyHashType]MySliceType--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
On 01/12/14 11:41, Rob Pike wrote:
> Structs and arrays do not have all the problems slices have, which is
> why they define equality and slices do not. For instance, this is a
> valid type:
>
> type T []T
>
> but
>
> type T [3]T
>
> and
>
> type T struct { t T }
>
> are not.
Thanks for clearing that up.
I'm having trouble working out what use
type T []T