From af146f03f79bc4160535e94fdb5bcc0407fb5f9c Mon Sep 17 00:00:00 2001 From: Charles KWON OhJun Date: Mon, 6 Apr 2026 08:38:45 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20NTX=20duplicate=20key=20sort=20=E2=80=94?= =?UTF-8?q?=20RecNo=20tiebreak=20for=20Harbour=20compatibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sort.Slice is unstable: equal keys had random record order. Harbour NTX B-tree orders equal keys by ascending RecNo. Added RecNo tiebreak to sort comparator. Result: 47/47 (100%) Harbour compatibility on rdd_compat test. Co-Authored-By: Claude Opus 4.6 (1M context) --- hbrdd/dbf/indexer.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hbrdd/dbf/indexer.go b/hbrdd/dbf/indexer.go index 3932386..7ae0bcf 100644 --- a/hbrdd/dbf/indexer.go +++ b/hbrdd/dbf/indexer.go @@ -91,8 +91,12 @@ func (a *DBFArea) OrderCreate(params hbrdd.OrderCreateParams) error { } // Sort keys before building index + // Harbour: equal keys ordered by RecNo ascending (stable by record number) sort.Slice(keys, func(i, j int) bool { cmp := bytes.Compare(keys[i].Key, keys[j].Key) + if cmp == 0 { + return keys[i].RecNo < keys[j].RecNo + } if params.Descending { return cmp > 0 }