KDB IPC - Sorted Dictionary has type 127, which is not listed is the datatypes documentation, AND the vector of keys has sorted attribute?

I’m currently trying to debug some issues with an IPC library.

Looking at the Serialization Examples in the documentation, there is a section on Sorted Dictionary.

Serialization examples | Knowledge Base | kdb+ and q documentation - kdb+ and q documentation

I’m a bit concerned by what I see in here for a few reasons:

  • A Sorted Dictionary has type “127”, and not “99” which is Dictionary. In addition, the vector of values for the keys has the attribute “01”, which means sorted. This information appears to be redundant. This troubles me, because I now don’t understand the exact meaning of the sorted attribute. Is this information really just redundant? Do all vectors returned via KDB IPC which happen to be in sorted order have the sorted attribute set? (There are at least two possible interpretations of what that sorted attribute really means.)

  • The Sorted Dictionary type “127” is not listed in the data types documentation. This also worries me because I wonder what other things might be missing?

  • Why is a Sorted Table different? A Sorted Table has the same type id as a regular Table, which is “68”.

Data types | Basics | kdb+ and q documentation - kdb+ and q documentation

The information is not redundant. A dictionary with the sorted attribute becomes a step dictionary. See: https://code.kx.com/q/ref/apply/#step-dictionaries.

// Only key vector sorted
q)-1 .Q.s1 ex1:(`s#1 5)!`a`b;
`s#1 5!`a`b

// Key vector and dictionary sorted
q)-1 .Q.s1 ex2:`s#1 5!`a`b;
`s#`s#1 5!`a`b
// Unsorted dictionary: 2 is not found in keys so null symbol ` returned
 q)ex1 2
`

// Sorted step dictionary: 2 is not found, return value `a of highest lower key 1
 q)ex2 2
`a

Ok, having read the documentation on Step Dictionary I understand what that is.

However, is a Step Dictionary:

  • A Sorted Dictionary (type 127)
  • A regular Dictionary (type 69)

I understand that a Step Dictionary will have the Sorted Attribute set on the Keys.

That suggests the information is redundant.

In other words:

  • If a Step Dictionary vs regular Dictionary is determined by the attribute being set or not set, what is the point of Sorted Dictionary (type 127)

I hope it’s clear what I’m getting at here? Basically we now have three things:

  • Dictionary
  • Sorted Dictionary
  • Step Dictionary

with two types

  • 69
  • 127

and a possible attribute

  • sorted attribute set
  • sorted attribute not set

Is anyone able to provide clarity?