Add hash() member functions
Signed-off-by: gatecat <gatecat@ds0.me>
This commit is contained in:
parent
76ef768864
commit
ff72454f83
@ -56,6 +56,8 @@ struct IdString
|
||||
bool operator!=(const IdString &other) const { return index != other.index; }
|
||||
|
||||
bool empty() const { return index == 0; }
|
||||
|
||||
unsigned int hash() const { return index; }
|
||||
};
|
||||
|
||||
NEXTPNR_NAMESPACE_END
|
||||
|
@ -22,6 +22,7 @@
|
||||
#define IDSTRING_LIST_H
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include "hashlib.h"
|
||||
#include "idstring.h"
|
||||
#include "nextpnr_namespaces.h"
|
||||
#include "sso_array.h"
|
||||
@ -67,6 +68,14 @@ struct IdStringList
|
||||
|
||||
static IdStringList concat(IdStringList a, IdStringList b);
|
||||
IdStringList slice(size_t s, size_t e) const;
|
||||
|
||||
unsigned int hash() const
|
||||
{
|
||||
unsigned int h = mkhash_init;
|
||||
for (const auto &val : ids)
|
||||
h = mkhash(h, val.hash());
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
||||
NEXTPNR_NAMESPACE_END
|
||||
|
@ -45,31 +45,31 @@ A scalar type that is used to represent delays. May be an integer or float type
|
||||
|
||||
### BelId
|
||||
|
||||
A type representing a bel name. `BelId()` must construct a unique null-value. Must provide `==`, `!=`, and `<` operators and a specialization for `std::hash<BelId>`.
|
||||
A type representing a bel name. `BelId()` must construct a unique null-value. Must provide `==`, `!=`, and `<` operators and a `unsigned int hash() const` member function.
|
||||
|
||||
### WireId
|
||||
|
||||
A type representing a wire name. `WireId()` must construct a unique null-value. Must provide `==`, `!=`, and `<` operators and a specialization for `std::hash<WireId>`.
|
||||
A type representing a wire name. `WireId()` must construct a unique null-value. Must provide `==`, `!=`, and `<` operators and a `unsigned int hash() const` member function.
|
||||
|
||||
### PipId
|
||||
|
||||
A type representing a pip name. `PipId()` must construct a unique null-value. Must provide `==`, `!=`, and `<` operators and a specialization for `std::hash<PipId>`.
|
||||
A type representing a pip name. `PipId()` must construct a unique null-value. Must provide `==`, `!=`, and `<` operators and a `unsigned int hash() const` member function.
|
||||
|
||||
### BelBucketId
|
||||
|
||||
A type representing a bel bucket. `BelBucketId()` must construct a unique null-value. Must provide `==`, `!=`, and `<` operators and a specialization for `std::hash<BelBucketId>`.
|
||||
A type representing a bel bucket. `BelBucketId()` must construct a unique null-value. Must provide `==`, `!=`, and `<` operators and a `unsigned int hash() const` member function.
|
||||
|
||||
### GroupId
|
||||
|
||||
A type representing a group name. `GroupId()` must construct a unique null-value. Must provide `==` and `!=` operators and a specialization for `std::hash<GroupId>`.
|
||||
A type representing a group name. `GroupId()` must construct a unique null-value. Must provide `==` and `!=` operators and a `unsigned int hash() const` member function.
|
||||
|
||||
### DecalId
|
||||
|
||||
A type representing a reference to a graphical decal. `DecalId()` must construct a unique null-value. Must provide `==` and `!=` operators and a specialization for `std::hash<DecalId>`.
|
||||
A type representing a reference to a graphical decal. `DecalId()` must construct a unique null-value. Must provide `==` and `!=` operators and a `unsigned int hash() const` member function.
|
||||
|
||||
### ClusterId
|
||||
|
||||
A type representing a reference to a constrained cluster of cells. `ClusterId()` must construct a unique null-value. Must provide `==` and `!=` operators and a specialization for `std::hash<ClusterId>`.
|
||||
A type representing a reference to a constrained cluster of cells. `ClusterId()` must construct a unique null-value. Must provide `==` and `!=` operators and `unsigned int hash() const` member function.
|
||||
|
||||
### ArchNetInfo
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
#include "base_clusterinfo.h"
|
||||
#include "hashlib.h"
|
||||
#include "idstring.h"
|
||||
#include "nextpnr_namespaces.h"
|
||||
|
||||
@ -63,6 +64,7 @@ struct Location
|
||||
bool operator==(const Location &other) const { return x == other.x && y == other.y; }
|
||||
bool operator!=(const Location &other) const { return x != other.x || y != other.y; }
|
||||
bool operator<(const Location &other) const { return y == other.y ? x < other.x : y < other.y; }
|
||||
unsigned int hash() const { return mkhash(x, y); }
|
||||
};
|
||||
|
||||
inline Location operator+(const Location &a, const Location &b) { return Location(a.x + b.x, a.y + b.y); }
|
||||
@ -78,6 +80,7 @@ struct BelId
|
||||
{
|
||||
return location == other.location ? index < other.index : location < other.location;
|
||||
}
|
||||
unsigned int hash() const { return mkhash(location.hash(), index); }
|
||||
};
|
||||
|
||||
struct WireId
|
||||
@ -91,6 +94,7 @@ struct WireId
|
||||
{
|
||||
return location == other.location ? index < other.index : location < other.location;
|
||||
}
|
||||
unsigned int hash() const { return mkhash(location.hash(), index); }
|
||||
};
|
||||
|
||||
struct PipId
|
||||
@ -104,6 +108,7 @@ struct PipId
|
||||
{
|
||||
return location == other.location ? index < other.index : location < other.location;
|
||||
}
|
||||
unsigned int hash() const { return mkhash(location.hash(), index); }
|
||||
};
|
||||
|
||||
typedef IdString BelBucketId;
|
||||
@ -119,6 +124,7 @@ struct GroupId
|
||||
|
||||
bool operator==(const GroupId &other) const { return (type == other.type) && (location == other.location); }
|
||||
bool operator!=(const GroupId &other) const { return (type != other.type) || (location != other.location); }
|
||||
unsigned int hash() const { return mkhash(location.hash(), int(type)); }
|
||||
};
|
||||
|
||||
struct DecalId
|
||||
@ -142,6 +148,7 @@ struct DecalId
|
||||
{
|
||||
return type != other.type || location != other.location || z != other.z || active != other.active;
|
||||
}
|
||||
unsigned int hash() const { return mkhash(location.hash(), mkhash(z, int(type))); }
|
||||
};
|
||||
|
||||
struct ArchNetInfo
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include "hash_table.h"
|
||||
#include "hashlib.h"
|
||||
#include "luts.h"
|
||||
#include "nextpnr_namespaces.h"
|
||||
|
||||
@ -48,6 +49,7 @@ struct BelId
|
||||
{
|
||||
return tile < other.tile || (tile == other.tile && index < other.index);
|
||||
}
|
||||
unsigned int hash() const { return mkhash(tile, index); }
|
||||
};
|
||||
|
||||
struct WireId
|
||||
@ -62,6 +64,7 @@ struct WireId
|
||||
{
|
||||
return tile < other.tile || (tile == other.tile && index < other.index);
|
||||
}
|
||||
unsigned int hash() const { return mkhash(tile, index); }
|
||||
};
|
||||
|
||||
struct PipId
|
||||
@ -75,6 +78,7 @@ struct PipId
|
||||
{
|
||||
return tile < other.tile || (tile == other.tile && index < other.index);
|
||||
}
|
||||
unsigned int hash() const { return mkhash(tile, index); }
|
||||
};
|
||||
|
||||
struct GroupId
|
||||
@ -96,6 +100,7 @@ struct BelBucketId
|
||||
bool operator==(const BelBucketId &other) const { return (name == other.name); }
|
||||
bool operator!=(const BelBucketId &other) const { return (name != other.name); }
|
||||
bool operator<(const BelBucketId &other) const { return name < other.name; }
|
||||
unsigned int hash() const { return name.hash(); }
|
||||
};
|
||||
|
||||
typedef IdString ClusterId;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
#include "base_clusterinfo.h"
|
||||
#include "hashlib.h"
|
||||
#include "idstring.h"
|
||||
#include "nextpnr_namespaces.h"
|
||||
|
||||
@ -55,6 +56,7 @@ struct BelId
|
||||
bool operator==(const BelId &other) const { return index == other.index; }
|
||||
bool operator!=(const BelId &other) const { return index != other.index; }
|
||||
bool operator<(const BelId &other) const { return index < other.index; }
|
||||
unsigned int hash() const { return index; }
|
||||
};
|
||||
|
||||
struct WireId
|
||||
@ -64,6 +66,7 @@ struct WireId
|
||||
bool operator==(const WireId &other) const { return index == other.index; }
|
||||
bool operator!=(const WireId &other) const { return index != other.index; }
|
||||
bool operator<(const WireId &other) const { return index < other.index; }
|
||||
unsigned int hash() const { return index; }
|
||||
};
|
||||
|
||||
struct PipId
|
||||
@ -73,6 +76,7 @@ struct PipId
|
||||
bool operator==(const PipId &other) const { return index == other.index; }
|
||||
bool operator!=(const PipId &other) const { return index != other.index; }
|
||||
bool operator<(const PipId &other) const { return index < other.index; }
|
||||
unsigned int hash() const { return index; }
|
||||
};
|
||||
|
||||
struct GroupId
|
||||
@ -96,6 +100,7 @@ struct GroupId
|
||||
|
||||
bool operator==(const GroupId &other) const { return (type == other.type) && (x == other.x) && (y == other.y); }
|
||||
bool operator!=(const GroupId &other) const { return (type != other.type) || (x != other.x) || (y == other.y); }
|
||||
unsigned int hash() const { return mkhash(mkhash(x, y), int(type)); }
|
||||
};
|
||||
|
||||
struct DecalId
|
||||
@ -113,6 +118,7 @@ struct DecalId
|
||||
|
||||
bool operator==(const DecalId &other) const { return (type == other.type) && (index == other.index); }
|
||||
bool operator!=(const DecalId &other) const { return (type != other.type) || (index != other.index); }
|
||||
unsigned int hash() const { return mkhash(index, int(type)); }
|
||||
};
|
||||
|
||||
struct ArchNetInfo
|
||||
|
@ -22,6 +22,7 @@
|
||||
#define MACHXO2_ARCHDEFS_H
|
||||
|
||||
#include "base_clusterinfo.h"
|
||||
#include "hashlib.h"
|
||||
#include "idstring.h"
|
||||
#include "nextpnr_namespaces.h"
|
||||
|
||||
@ -59,6 +60,7 @@ struct Location
|
||||
bool operator==(const Location &other) const { return x == other.x && y == other.y; }
|
||||
bool operator!=(const Location &other) const { return x != other.x || y != other.y; }
|
||||
bool operator<(const Location &other) const { return y == other.y ? x < other.x : y < other.y; }
|
||||
unsigned int hash() const { return mkhash(x, y); }
|
||||
};
|
||||
|
||||
inline Location operator+(const Location &a, const Location &b) { return Location(a.x + b.x, a.y + b.y); }
|
||||
@ -74,6 +76,7 @@ struct BelId
|
||||
{
|
||||
return location == other.location ? index < other.index : location < other.location;
|
||||
}
|
||||
unsigned int hash() const { return mkhash(location.hash(), index); }
|
||||
};
|
||||
|
||||
struct WireId
|
||||
@ -87,6 +90,7 @@ struct WireId
|
||||
{
|
||||
return location == other.location ? index < other.index : location < other.location;
|
||||
}
|
||||
unsigned int hash() const { return mkhash(location.hash(), index); }
|
||||
};
|
||||
|
||||
struct PipId
|
||||
@ -100,6 +104,7 @@ struct PipId
|
||||
{
|
||||
return location == other.location ? index < other.index : location < other.location;
|
||||
}
|
||||
unsigned int hash() const { return mkhash(location.hash(), index); }
|
||||
};
|
||||
|
||||
typedef IdString GroupId;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "base_clusterinfo.h"
|
||||
#include "cyclonev.h"
|
||||
|
||||
#include "hashlib.h"
|
||||
#include "idstring.h"
|
||||
#include "nextpnr_assertions.h"
|
||||
#include "nextpnr_namespaces.h"
|
||||
@ -84,6 +85,7 @@ struct BelId
|
||||
bool operator==(const BelId &other) const { return pos == other.pos && z == other.z; }
|
||||
bool operator!=(const BelId &other) const { return pos != other.pos || z != other.z; }
|
||||
bool operator<(const BelId &other) const { return pos < other.pos || (pos == other.pos && z < other.z); }
|
||||
unsigned int hash() const { return mkhash(pos, z); }
|
||||
};
|
||||
|
||||
static constexpr auto invalid_rnode = std::numeric_limits<CycloneV::rnode_t>::max();
|
||||
@ -104,6 +106,7 @@ struct WireId
|
||||
bool operator==(const WireId &other) const { return node == other.node; }
|
||||
bool operator!=(const WireId &other) const { return node != other.node; }
|
||||
bool operator<(const WireId &other) const { return node < other.node; }
|
||||
unsigned int hash() const { return unsigned(node); }
|
||||
};
|
||||
|
||||
struct PipId
|
||||
@ -115,6 +118,7 @@ struct PipId
|
||||
bool operator==(const PipId &other) const { return src == other.src && dst == other.dst; }
|
||||
bool operator!=(const PipId &other) const { return src != other.src || dst != other.dst; }
|
||||
bool operator<(const PipId &other) const { return dst < other.dst || (dst == other.dst && src < other.src); }
|
||||
unsigned int hash() const { return mkhash(src, dst); }
|
||||
};
|
||||
|
||||
typedef IdString DecalId;
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include "base_clusterinfo.h"
|
||||
#include "hashlib.h"
|
||||
#include "idstring.h"
|
||||
#include "nextpnr_namespaces.h"
|
||||
|
||||
@ -62,6 +63,7 @@ struct BelId
|
||||
{
|
||||
return tile < other.tile || (tile == other.tile && index < other.index);
|
||||
}
|
||||
unsigned int hash() const { return mkhash(tile, index); }
|
||||
};
|
||||
|
||||
struct WireId
|
||||
@ -80,6 +82,7 @@ struct WireId
|
||||
{
|
||||
return tile < other.tile || (tile == other.tile && index < other.index);
|
||||
}
|
||||
unsigned int hash() const { return mkhash(tile, index); }
|
||||
};
|
||||
|
||||
struct PipId
|
||||
@ -97,6 +100,7 @@ struct PipId
|
||||
{
|
||||
return tile < other.tile || (tile == other.tile && index < other.index);
|
||||
}
|
||||
unsigned int hash() const { return mkhash(tile, index); }
|
||||
};
|
||||
|
||||
typedef IdString BelBucketId;
|
||||
@ -111,6 +115,7 @@ struct GroupId
|
||||
|
||||
bool operator==(const GroupId &other) const { return (type == other.type) && (x == other.x) && (y == other.y); }
|
||||
bool operator!=(const GroupId &other) const { return (type != other.type) || (x != other.x) || (y == other.y); }
|
||||
unsigned int hash() const { return mkhash(mkhash(x, y), int(type)); }
|
||||
};
|
||||
|
||||
struct DecalId
|
||||
@ -134,6 +139,7 @@ struct DecalId
|
||||
{
|
||||
return (type != other.type) || (index != other.index) || (active != other.active);
|
||||
}
|
||||
unsigned int hash() const { return mkhash(index, int(type)); }
|
||||
};
|
||||
|
||||
struct ArchNetInfo
|
||||
|
Loading…
Reference in New Issue
Block a user