| 1315 | } |
| 1316 | |
| 1317 | func hashTerm(s string, args []BaseTerm) uint64 { |
| 1318 | h := fnv.New64() |
| 1319 | h.Write([]byte(s)) |
| 1320 | for _, arg := range args { |
| 1321 | switch c := arg.(type) { |
| 1322 | case Constant: |
| 1323 | b := make([]byte, 8) |
| 1324 | binary.LittleEndian.PutUint64(b, c.Hash()) |
| 1325 | h.Write(b) |
| 1326 | case Variable: |
| 1327 | h.Write([]byte(c.String())) |
| 1328 | case ApplyFn: |
| 1329 | b := make([]byte, 8) |
| 1330 | binary.LittleEndian.PutUint64(b, c.Hash()) |
| 1331 | h.Write(b) |
| 1332 | } |
| 1333 | } |
| 1334 | return h.Sum64() |
| 1335 | } |
| 1336 | |
| 1337 | // FreshVariable returns a variable different from the ones in used. |
| 1338 | func FreshVariable(used map[Variable]bool) Variable { |