semiotproject / semiot-platform

SemIoT Platform
http://semiot.ru
MIT License
8 stars 1 forks source link

Revisit the design of system URIs #94

Closed KMax closed 9 years ago

KMax commented 9 years ago

Currently we don't use dereferenceable URIs for the systems (aka devices), because we don't have an API which could provide such a capability. But since we're working on such an API (#93) when we need to think about it.

An obvious option is http://[domain]/systems/[System ID], but how to generate the [System ID]?

I think it should be generated by a hash function which will work like this:

There is a good overview and comparison of existing hash function.

Amberdr0p commented 9 years ago

I chose fnv1 hashing. Here's the code implementation with unsigned int:

private static final int FNV_32_INIT = 0x811c9dc5;
private static final int FNV_32_PRIME = 0x01000193;

int h = FNV_32_INIT;
final int len = name.length();
for(int i = 0; i < len; i++) {
        h ^= name.charAt(i);
        h *= FNV_32_PRIME;
}
long longHash = h & 0xffffffffl;