isar / hive

Lightweight and blazing fast key-value database written in pure Dart.
Apache License 2.0
4.01k stars 398 forks source link

integer key max value #1204

Open javierfjc opened 1 year ago

javierfjc commented 1 year ago

Hi, Why exists a max limit to integer key value of 0xFFFFFFFF ?

I have greaters keys values that I can´t use. With string keys is allowed lenght until 255 characters

thanks

Quantam-Studios commented 1 year ago

"The supported integer values include all integers between -2^53 and 2^53, and some integers with larger magnitude" - https://docs.hivedb.dev/#/more/limitations is all I can find on this. It probably has something to do with the limits of integer and double types across all programming languages. A good explanation I found is in the Safe Integers section of this page: https://exploringjs.com/es5/ch11.html

javierfjc commented 1 year ago

In file frame.dart there is a control about key valid. The key can be integer between 0 and 0xFFFFFFFF. Why the top limit ? I have custom keys that are integers but highest than 0xFFFFFFFF.

myBox.put(500000000581, ItemObject); -> thrown Exception Integer keys need to be in the range 0 - 0xFFFFFFFF

frame.dart

  /// Not part of public API
  static bool assertKey(dynamic key) {
    if (key is int) {
      if (key < 0 || key > 0xFFFFFFFF) {
        throw HiveError('Integer keys need to be in the range 0 - 0xFFFFFFFF');
      }
    } else if (key is String) {
      if (key.length > 0xFF || !key.isAscii) {
        throw HiveError(
            'String keys need to be ASCII Strings with a max length of 255');
      }
    } else {
      throw HiveError('Keys need to be Strings or integers');
    }

    return true;
  }
Quantam-Studios commented 1 year ago

Is it not between -0xFFFFFFFF - 0xFFFFFFFF

javierfjc commented 1 year ago

The assertKey() function prevent using integer keys grether than 0xFFFFFFFF. Is that correct ? It has a reason?.

Thanks

Quantam-Studios commented 1 year ago

Yes you are correct, and it has a reason beyond the creators of Hive's control.

Quantam-Studios commented 1 year ago

Strings can have a lot more information in them because they are essentially arrays characters.