From 51c403313431da2005a41793960d2c0690f69015 Mon Sep 17 00:00:00 2001 From: bibenga <{ID}+{username}@users.noreply.github.com> Date: Sat, 23 Aug 2025 14:13:33 +0000 Subject: [PATCH 1/3] adds NOTICE and update license --- NOTICE | 6 +++++ internal/hash/hash.go | 33 ++++++++++++++-------------- internal/utils/utils.go | 3 ++- intlinkedhashmap/intlinkedhashmap.go | 4 +++- linkedhashmap/linkedhashmap.go | 18 ++++++++++++++- linkedmap/linkedmap.go | 4 +++- maps.go | 2 ++ 7 files changed, 49 insertions(+), 21 deletions(-) create mode 100644 NOTICE diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..1f44c29 --- /dev/null +++ b/NOTICE @@ -0,0 +1,6 @@ +OrderedMap +Copyright 2025 bibenga + +This product includes software developed at +The Apache Software Foundation (https://www.apache.org/), +originally part of Apache Commons Collections. diff --git a/internal/hash/hash.go b/internal/hash/hash.go index f7779df..a07c086 100644 --- a/internal/hash/hash.go +++ b/internal/hash/hash.go @@ -1,30 +1,29 @@ +// Portions Copyright 2025 bibenga +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package hash import "orderedmap" -func FnvIntHash32[T orderedmap.Integer](x T) uint32 { - const ( - offset = 2166136261 - prime = 16777619 - ) - - x64 := uint64(x) - hash := uint32(offset) - for i := range 8 { - b := byte(x64 >> (i * 8)) - hash ^= uint32(b) - hash *= prime - } - return hash -} - func MapHash32(h uint32) uint32 { h += ^(h << 9) h ^= h >> 14 h += h << 4 h ^= h >> 10 return h - // return FnvIntHash32(h) } func MapHashIndex(hashCode uint32, dataSize int) int { diff --git a/internal/utils/utils.go b/internal/utils/utils.go index d4f3149..63a4628 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -1,3 +1,4 @@ +// Copyright 2025 bibenga package utils import ( @@ -5,7 +6,7 @@ import ( "orderedmap" ) -func ToString[K, V any](name string, m orderedmap.Map[K, V]) string { +func MapToString[K, V any](name string, m orderedmap.Map[K, V]) string { str := name + "[" first := true for k, v := range m.Items() { diff --git a/intlinkedhashmap/intlinkedhashmap.go b/intlinkedhashmap/intlinkedhashmap.go index d07676c..62f670a 100644 --- a/intlinkedhashmap/intlinkedhashmap.go +++ b/intlinkedhashmap/intlinkedhashmap.go @@ -1,3 +1,5 @@ +// Portions of this file are based on Apache Commons Collections, +// licensed under the Apache License, Version 2.0. package intlinkedhashmap import ( @@ -333,5 +335,5 @@ func (m *IntLinkedHashMap[K, V]) Items() iter.Seq2[K, V] { } func (m *IntLinkedHashMap[K, V]) String() string { - return utils.ToString("IntLinkedHashMap", m) + return utils.MapToString("IntLinkedHashMap", m) } diff --git a/linkedhashmap/linkedhashmap.go b/linkedhashmap/linkedhashmap.go index fa3bc82..507a946 100644 --- a/linkedhashmap/linkedhashmap.go +++ b/linkedhashmap/linkedhashmap.go @@ -1,3 +1,19 @@ +// Portions Copyright 2025 bibenga +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. package linkedhashmap import ( @@ -319,5 +335,5 @@ func (m *LinkedHashMap[K, V]) Items() iter.Seq2[K, V] { } func (m *LinkedHashMap[K, V]) String() string { - return utils.ToString("LinkedHashMap", m) + return utils.MapToString("LinkedHashMap", m) } diff --git a/linkedmap/linkedmap.go b/linkedmap/linkedmap.go index 0d5ec8f..0d06fec 100644 --- a/linkedmap/linkedmap.go +++ b/linkedmap/linkedmap.go @@ -1,3 +1,5 @@ +// Copyright 2025 bibenga +// Inspired by Apache Commons Collections (Apache License 2.0) package linkedmap import ( @@ -135,5 +137,5 @@ func (m *LinkedMap[K, V]) Items() iter.Seq2[K, V] { } func (m *LinkedMap[K, V]) String() string { - return utils.ToString("LinkedMap", m) + return utils.MapToString("LinkedMap", m) } diff --git a/maps.go b/maps.go index 607d98b..99b7964 100644 --- a/maps.go +++ b/maps.go @@ -1,3 +1,5 @@ +// This implementation is inspired by Apache Commons Collections +// (licensed under the Apache License, Version 2.0). package orderedmap import "iter" From 5e8bd64c7353e09adb6bac45bb82f55f535f6fd1 Mon Sep 17 00:00:00 2001 From: bibenga <{ID}+{username}@users.noreply.github.com> Date: Sat, 23 Aug 2025 14:13:57 +0000 Subject: [PATCH 2/3] deletes Fnv --- tests/general_test.go | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/tests/general_test.go b/tests/general_test.go index 6e24893..0f35b1b 100644 --- a/tests/general_test.go +++ b/tests/general_test.go @@ -1,8 +1,6 @@ package tests import ( - "encoding/binary" - "hash/fnv" "orderedmap" "orderedmap/internal/hash" "orderedmap/intlinkedhashmap" @@ -14,24 +12,6 @@ import ( type Factory func() orderedmap.Map[int, int] type StdFactory func() map[int]int -func TestFnvIntHash32(t *testing.T) { - values := []int64{0, 1, 42, 12345, -1, -123456789} - for _, v := range values { - // we count through native fnv.New32a() - h := fnv.New32a() - buf := make([]byte, 8) - binary.LittleEndian.PutUint64(buf, uint64(v)) - h.Write(buf) - want := h.Sum32() - - got := hash.FnvIntHash32(v) - - if got != want { - t.Errorf("fnvInt(%d) = %d, want %d", v, got, want) - } - } -} - func TestIntLinkedHashMap(t *testing.T) { factory := func() orderedmap.Map[int, int] { return intlinkedhashmap.NewDefault[int, int]() From 8521b7dd1be4333ea8b5969f38c206dc399ce5de Mon Sep 17 00:00:00 2001 From: bibenga <{ID}+{username}@users.noreply.github.com> Date: Sat, 23 Aug 2025 14:14:50 +0000 Subject: [PATCH 3/3] update header --- tests/benchmark1_test.go | 2 ++ tests/benchmark2_test.go | 2 ++ tests/general_test.go | 2 ++ 3 files changed, 6 insertions(+) diff --git a/tests/benchmark1_test.go b/tests/benchmark1_test.go index a538fd1..f07f48a 100644 --- a/tests/benchmark1_test.go +++ b/tests/benchmark1_test.go @@ -1,3 +1,5 @@ +// Copyright 2025 bibenga +// Inspired by Apache Commons Collections (Apache License 2.0) package tests import ( diff --git a/tests/benchmark2_test.go b/tests/benchmark2_test.go index b6064cf..2daef0e 100644 --- a/tests/benchmark2_test.go +++ b/tests/benchmark2_test.go @@ -1,3 +1,5 @@ +// Copyright 2025 bibenga +// Inspired by Apache Commons Collections (Apache License 2.0) package tests import ( diff --git a/tests/general_test.go b/tests/general_test.go index 0f35b1b..7071c1d 100644 --- a/tests/general_test.go +++ b/tests/general_test.go @@ -1,3 +1,5 @@ +// Copyright 2025 bibenga +// Inspired by Apache Commons Collections (Apache License 2.0) package tests import (