Skip to content

Commit

Permalink
Changed otherHashCode to Long.
Browse files Browse the repository at this point in the history
  • Loading branch information
daheise committed Aug 13, 2014
1 parent 1510315 commit d18a123
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 40 deletions.
16 changes: 8 additions & 8 deletions Elision/src/ornl/elision/core/AlgProp.scala
Expand Up @@ -114,20 +114,20 @@ class AlgProp(
case None => None.hashCode
case Some(atom) => atom.hashCode
}

override lazy val otherHashCode: Int =
(((((_codify(associative) * 8191) +
_codify(identity) * 8191) +
_codify(idempotent) * 8191) +
_codify(commutative) * 8191) +
_codify(absorber) * 8191)


override lazy val hashCode =
(((((_codify(associative) * 12289) +
_codify(commutative) * 12289) +
_codify(idempotent) * 12289) +
_codify(absorber) * 12289) +
_codify(identity) * 12289)

override lazy val otherHashCode: Long =
(((((_codify(associative) * 8191) +
_codify(identity) * 8191) +
_codify(idempotent) * 8191) +
_codify(commutative) * 8191) +
_codify(absorber) * 8191)

// Type check the Boolean properties.
private def _isNotBool(opt: Option[BasicAtom]) = opt match {
Expand Down
11 changes: 9 additions & 2 deletions Elision/src/ornl/elision/core/BasicAtom.scala
Expand Up @@ -52,7 +52,6 @@ import ornl.elision.util.Debugger
import ornl.elision.util.Loc
import scala.language.existentials
import ornl.elision.context.TimedOut
import ornl.elision.util.FastLinkedList

/**
* This marker trait is used to frighten developers and strike fear into
Expand Down Expand Up @@ -240,7 +239,7 @@ abstract class BasicAtom(val loc: Loc = Loc.internal) extends HasOtherHash {
* lower the chances of a hash collision (both different hash codes
* will need to collide for a hash collision to occur).
*/
val otherHashCode: Int
val otherHashCode: Long

/** YOU MUST OVERRIDE THIS IN INHERITED CLASSES! */
override lazy val hashCode = {
Expand Down Expand Up @@ -302,6 +301,14 @@ abstract class BasicAtom(val loc: Loc = Loc.internal) extends HasOtherHash {
*/
lazy val spouse = BasicAtom.buildSpouse(this)

override def equals(other: Any): Boolean =
other match {
case that: BasicAtom =>
BasicAtomComparator.feq(this, that)

case _ => false
}

/**
* Get all the variables referenced in an atom. Override this if the
* atom can actually contain variables.
Expand Down
2 changes: 1 addition & 1 deletion Elision/src/ornl/elision/core/BindingsAtom.scala
Expand Up @@ -75,7 +75,7 @@ import ornl.elision.core.matcher.SequenceMatcher
case class BindingsAtom(mybinds: Bindings) extends BasicAtom with Applicable {
require(mybinds != null, "Bindings are null.")

override lazy val otherHashCode = (this.mybinds).foldLeft(0)(other_hashify)
override lazy val otherHashCode = (this.mybinds).foldLeft(0L)(other_hashify)
override lazy val hashCode = 12289 * mybinds.hashCode

/** The type of a bindings atom is the special bindings type. */
Expand Down
14 changes: 7 additions & 7 deletions Elision/src/ornl/elision/core/Literal.scala
Expand Up @@ -135,7 +135,7 @@ extends BasicAtom {
*/
override lazy val hashCode = theType.hashCode * 12289 + value.hashCode
override lazy val otherHashCode = theType.otherHashCode +
8191*(value.toString).foldLeft(0)(other_hashify)
8191*(value.toString).foldLeft(0L)(other_hashify)

/**
* Two literals are equal iff their types are equal and their values are
Expand Down Expand Up @@ -226,7 +226,7 @@ case class IntegerLiteral(typ: BasicAtom, value: BigInt)
extends Literal[BigInt](typ) {

override lazy val hashCode = theType.hashCode * 12289 + value.hashCode
override lazy val otherHashCode = typ.otherHashCode + 8191*(value.toString).foldLeft(0)(other_hashify)
override lazy val otherHashCode = typ.otherHashCode + 8191*(value.toString).foldLeft(0L)(other_hashify)

/**
* Alternate constructor with default `INTEGER` type.
Expand Down Expand Up @@ -273,7 +273,7 @@ case class BitStringLiteral(typ: BasicAtom, var bits: BigInt, len: Int)
extends Literal[(BigInt, Int)](typ) {

override lazy val hashCode = theType.hashCode * 12289 + value.hashCode
override lazy val otherHashCode = typ.otherHashCode + 8191*(value.toString).foldLeft(0)(other_hashify)
override lazy val otherHashCode = typ.otherHashCode + 8191*(value.toString).foldLeft(0L)(other_hashify)

/** If true, prefer to display this as a signed value. If false, do not. */
val neghint = (bits < 0)
Expand Down Expand Up @@ -373,7 +373,7 @@ case class StringLiteral(typ: BasicAtom, value: String)
extends Literal[String](typ) {

override lazy val hashCode = theType.hashCode * 12289 + value.hashCode
override lazy val otherHashCode = typ.otherHashCode + 8191*(value.toString).foldLeft(0)(other_hashify)
override lazy val otherHashCode = typ.otherHashCode + 8191*(value.toString).foldLeft(0L)(other_hashify)

/**
* Alternate constructor with default `STRING` type.
Expand Down Expand Up @@ -420,7 +420,7 @@ extends Literal[Symbol](typ) {
*/
def this(value: Symbol) = this(SYMBOL, value, true)

override lazy val otherHashCode = (value.toString).foldLeft(0)(other_hashify)
override lazy val otherHashCode = (value.toString).foldLeft(0L)(other_hashify)
override lazy val hashCode = theType.hashCode * 12289 + value.toString.hashCode

def rewrite(binds: Bindings) = {
Expand Down Expand Up @@ -460,7 +460,7 @@ case class BooleanLiteral(typ: BasicAtom, value: Boolean)
extends Literal[Boolean](typ) {

override lazy val hashCode = theType.hashCode * 12289 + value.hashCode
override lazy val otherHashCode = typ.otherHashCode + 8191*(value.toString).foldLeft(0)(other_hashify)
override lazy val otherHashCode = typ.otherHashCode + 8191*(value.toString).foldLeft(0L)(other_hashify)

override val isTrue = value == true
override val isFalse = value == false
Expand Down Expand Up @@ -583,7 +583,7 @@ case class FloatLiteral(typ: BasicAtom, significand: BigInt, exponent: Int,
radix: Int) extends Literal[(BigInt, Int, Int)](typ) {

override lazy val hashCode = theType.hashCode * 12289 + value.hashCode
override lazy val otherHashCode = typ.otherHashCode + 8191*(value.toString).foldLeft(0)(other_hashify)
override lazy val otherHashCode = typ.otherHashCode + 8191*(value.toString).foldLeft(0L)(other_hashify)

// Validate the radix and compute the prefix string.
private lazy val _prefix = radix match {
Expand Down
24 changes: 12 additions & 12 deletions Elision/src/ornl/elision/core/Memo.scala
Expand Up @@ -155,38 +155,38 @@ object Memo {
* rewrite limit is stored!
*/
private var _cache =
new HashMap[((Int,Int),BitSet),(BasicAtom,Int)]()
new HashMap[((Int,Long),BitSet),(BasicAtom,Int)]()

/**
* Keeps a count of how many times things in _cache have been accessed since
* the last iteration of the replacement policy algorithm.
*/
private var _cacheCounter =
new HashMap[((Int,Int),BitSet), Long]()
new HashMap[((Int,Long),BitSet), Long]()

/**
* Queue for implementing a FIFO replacement policy.
*/
private var _cacheFIFO = new Queue[((Int,Int),BitSet)]
private var _cacheFIFO = new Queue[((Int,Long),BitSet)]

/**
* This set holds atoms that are in their "normal form" state and do not
* get rewritten.
*/
private var _normal =
new HashMap[((Int,Int),BitSet),Unit]()
new HashMap[((Int,Long),BitSet),Unit]()

/**
* Keeps a count of how many times things in _normal have been accessed
* since the last iteration of the replacement policy algorithm.
*/
private var _normalCounter =
new HashMap[((Int,Int),BitSet), Long]()
new HashMap[((Int,Long),BitSet), Long]()

/**
* Queue for implementing a FIFO replacement policy.
*/
private var _normalFIFO = new Queue[((Int,Int),BitSet)]
private var _normalFIFO = new Queue[((Int,Long),BitSet)]


/**
Expand Down Expand Up @@ -524,7 +524,7 @@ object Memo {

// I haz a buckit. This will keep track of the items that haven't been
// accessed since the last checkup.
var bucket = new ListBuffer[((Int,Int),BitSet)]
var bucket = new ListBuffer[((Int,Long),BitSet)]

val keyIterator = _cache.keySet.iterator
while(keyIterator.hasNext) {
Expand Down Expand Up @@ -560,7 +560,7 @@ object Memo {
var lowestCount = Long.MaxValue

// I haz a buckit. This will keep track of the items with the lowest count.
var bucket = new ListBuffer[((Int,Int),BitSet)]
var bucket = new ListBuffer[((Int,Long),BitSet)]

// find the items with the lowest count and put their keys in the bucket.
// An iterator was used here because there wasn't a very convenient way to
Expand Down Expand Up @@ -622,7 +622,7 @@ object Memo {

// I haz a buckit. This will keep track of the items that haven't been
// accessed since the last checkup.
var bucket = new ListBuffer[((Int,Int),BitSet)]
var bucket = new ListBuffer[((Int,Long),BitSet)]

val keyIterator = _normal.keySet.iterator
while(keyIterator.hasNext) {
Expand Down Expand Up @@ -659,7 +659,7 @@ object Memo {
var lowestCount = Long.MaxValue

// I haz a buckit. This will keep track of the items with the lowest count.
var bucket = new ListBuffer[((Int,Int),BitSet)]
var bucket = new ListBuffer[((Int,Long),BitSet)]

// find the items with the lowest count and put their keys in the bucket.
// An iterator was used here because there wasn't a very convenient way to
Expand Down Expand Up @@ -695,7 +695,7 @@ object Memo {
}

/** safely increments the counter for a key in _cacheCounter. */
def _incCacheCounter(key : ((Int,Int),BitSet)) {
def _incCacheCounter(key : ((Int,Long),BitSet)) {
val counterHasKey = _cacheCounter.containsKey(key)

val curCount = if(counterHasKey) {
Expand All @@ -708,7 +708,7 @@ object Memo {
}

/** safely increments the counter for a key in _normalCounter. */
def _incNormalCounter(key : ((Int,Int),BitSet)) {
def _incNormalCounter(key : ((Int,Long),BitSet)) {
val counterHasKey = _normalCounter.containsKey(key)

val curCount = if(counterHasKey) {
Expand Down
2 changes: 1 addition & 1 deletion Elision/src/ornl/elision/core/NamedRootType.scala
Expand Up @@ -95,7 +95,7 @@ extends SymbolLiteral(TypeUniverse, Symbol(name)) {

/** Generate the hash code. */
override lazy val hashCode = 12289 * name.hashCode
override lazy val otherHashCode = (name.toString).foldLeft(0)(other_hashify)
override lazy val otherHashCode = (name.toString).foldLeft(0L)(other_hashify)

/**
* Because of careful use of names, two named root types are equal
Expand Down
2 changes: 1 addition & 1 deletion Elision/src/ornl/elision/core/RulesetRef.scala
Expand Up @@ -80,7 +80,7 @@ abstract class RulesetRef extends BasicAtom with Rewriter {
}

override lazy val hashCode = 12289*name.hashCode
override lazy val otherHashCode = (name.toString).foldLeft(0)(other_hashify)
override lazy val otherHashCode = (name.toString).foldLeft(0L)(other_hashify)

override def equals(other: Any) =
(other match {
Expand Down
2 changes: 1 addition & 1 deletion Elision/src/ornl/elision/core/TypeUniverse.scala
Expand Up @@ -90,6 +90,6 @@ object TypeUniverse extends SymbolLiteral(null, Symbol("^TYPE")) {

/** Compute the hash code. */
override lazy val hashCode = 12289 * value.hashCode
override lazy val otherHashCode = (value.toString).foldLeft(0)(other_hashify)
override lazy val otherHashCode = (value.toString).foldLeft(0L)(other_hashify)
override def equals(other: Any) = TypeUniverse eq other.asInstanceOf[AnyRef]
}
4 changes: 2 additions & 2 deletions Elision/src/ornl/elision/core/Variable.scala
Expand Up @@ -264,7 +264,7 @@ class Variable(typ: BasicAtom, val name: String,

override lazy val hashCode = typ.hashCode * 12289 + name.hashCode
override lazy val otherHashCode = typ.otherHashCode +
8191 * (name.toString).foldLeft(0)(other_hashify)
8191 * (name.toString).foldLeft(0L)(other_hashify)
override def equals(varx: Any) = varx match {
case ovar: Variable =>
feq(ovar, this,
Expand Down Expand Up @@ -337,7 +337,7 @@ class MetaVariable(typ: BasicAtom, name: String,
override val prefix = "$$"
override lazy val hashCode = typ.hashCode * 12289 + name.hashCode
override lazy val otherHashCode = typ.otherHashCode +
8193 * (name.toString).foldLeft(0)(other_hashify)
8193 * (name.toString).foldLeft(0L)(other_hashify)

/**
* Make a non-meta version of this metavariable.
Expand Down
2 changes: 1 addition & 1 deletion Elision/src/ornl/elision/util/HasOtherHash.scala
Expand Up @@ -40,5 +40,5 @@ trait HasOtherHash {
* An alternate hash code. This should be computed in a different manner
* from the usual `hashCode`.
*/
val otherHashCode: Int
val otherHashCode: Long
}
2 changes: 1 addition & 1 deletion Elision/src/ornl/elision/util/OmitSeq.scala
Expand Up @@ -74,7 +74,7 @@ abstract class OmitSeq[A] extends IndexedSeq[A] with HasOtherHash {
/**
* Alternate hash code for OmitSeq
*/
override lazy val otherHashCode = foldLeft(0)(other_hashify)
override lazy val otherHashCode = foldLeft(0L)(other_hashify)
}

/**
Expand Down
5 changes: 2 additions & 3 deletions Elision/src/ornl/elision/util/package.scala
Expand Up @@ -102,11 +102,10 @@ package object util {
* @param hash The initial hash code.
* @param obj The next object whose hash should be added.
*/
@inline
def hashify(hash: Int = 0, obj: Any) = {
// Add a constant to the end so that single element collections have a
// different hashcode than the element they contain.
hash * 12289 + obj.hashCode + 31
hash * 12289 + obj.hashCode + (if (hash==0) 31 else 0)
}

/**
Expand All @@ -123,7 +122,7 @@ package object util {
* @param hash The initial hash code.
* @param obj The next object whose hash should be added.
*/
def other_hashify(hash: Int = 0, obj: Any): Int = {
def other_hashify(hash: Long = 0, obj: Any): Long = {
obj match {
case ohc: HasOtherHash => hash + 8191*ohc.otherHashCode
case _ => hash + 8191*obj.hashCode
Expand Down

0 comments on commit d18a123

Please sign in to comment.