lite-containers 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.rubocop.yml +72 -0
  4. data/Gemfile +14 -0
  5. data/Gemfile.lock +127 -0
  6. data/README.md +145 -0
  7. data/bench/containers_bench.rb +122 -0
  8. data/lib/lite/containers/abstract/collection.rb +25 -0
  9. data/lib/lite/containers/abstract/deque.rb +23 -0
  10. data/lib/lite/containers/abstract/implicit_key.rb +23 -0
  11. data/lib/lite/containers/abstract/queue.rb +24 -0
  12. data/lib/lite/containers/abstract/sorted_map.rb +29 -0
  13. data/lib/lite/containers/avl_tree/balance.rb +74 -0
  14. data/lib/lite/containers/avl_tree/delete.rb +32 -0
  15. data/lib/lite/containers/avl_tree/find.rb +99 -0
  16. data/lib/lite/containers/avl_tree/implementation.rb +88 -0
  17. data/lib/lite/containers/avl_tree/insert.rb +27 -0
  18. data/lib/lite/containers/avl_tree/interfaces/bracket_assign.rb +33 -0
  19. data/lib/lite/containers/avl_tree/interfaces/key_extraction_strategy/abstract.rb +48 -0
  20. data/lib/lite/containers/avl_tree/interfaces/key_extraction_strategy/explicit.rb +34 -0
  21. data/lib/lite/containers/avl_tree/interfaces/key_extraction_strategy/implicit.rb +60 -0
  22. data/lib/lite/containers/avl_tree/node.rb +35 -0
  23. data/lib/lite/containers/avl_tree/traversal.rb +43 -0
  24. data/lib/lite/containers/avl_tree.rb +159 -0
  25. data/lib/lite/containers/error.rb +7 -0
  26. data/lib/lite/containers/heap.rb +169 -0
  27. data/lib/lite/containers/helpers/comparison.rb +106 -0
  28. data/lib/lite/containers/helpers/key_extractor.rb +29 -0
  29. data/lib/lite/containers/helpers/merge.rb +49 -0
  30. data/lib/lite/containers/sorted_array/binary_search.rb +42 -0
  31. data/lib/lite/containers/sorted_array.rb +188 -0
  32. data/lib/lite/containers/top_n/abstract.rb +56 -0
  33. data/lib/lite/containers/top_n/avl_tree.rb +25 -0
  34. data/lib/lite/containers/top_n/deque.rb +33 -0
  35. data/lib/lite/containers/top_n/error.rb +11 -0
  36. data/lib/lite/containers/top_n/heap.rb +32 -0
  37. data/lib/lite/containers/top_n.rb +31 -0
  38. data/lib/lite/containers/version.rb +7 -0
  39. data/lib/lite/containers.rb +3 -0
  40. data/lite_containers.gemspec +25 -0
  41. metadata +83 -0
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'abstract'
4
+ require_relative '../heap'
5
+
6
+ module Lite
7
+ module Containers
8
+ module TopN
9
+ class Heap
10
+ include Abstract
11
+
12
+ Backend = Containers::Heap
13
+
14
+ def self.instance(type, limit: nil, filter: nil, key_extractor: nil)
15
+ comparison = Helpers::Comparison.instance(type, key_extractor: key_extractor).invert
16
+ backend = Backend.with_comparison(comparison)
17
+ new backend, limit, filter
18
+ end
19
+
20
+ def pop
21
+ @backend.pop
22
+ end
23
+
24
+ def drain!
25
+ @backend.drain!.reverse
26
+ end
27
+ end
28
+
29
+ register_backend :heap, Heap
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'error'
4
+
5
+ module Lite
6
+ module Containers
7
+ module TopN
8
+ def self.register_backend(name, backend)
9
+ registry[name] = backend
10
+ end
11
+
12
+ def self.registry
13
+ @registry ||= {}
14
+ end
15
+
16
+ def self.instance(backend, type, limit: nil, filter: nil, **backend_options)
17
+ limit = Integer(limit) unless limit.nil?
18
+ raise Error, "Expected positive integer or nil for limit, got '#{limit}'" unless limit.nil? || limit.positive?
19
+
20
+ wrapper_class = wrapper_class(backend)
21
+ wrapper_class.instance type, limit: limit, filter: filter, **backend_options
22
+ end
23
+
24
+ def self.wrapper_class(name)
25
+ raise Error, "Unexpected backend: #{name}" unless registry.key?(name)
26
+
27
+ registry[name]
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lite
4
+ module Containers
5
+ VERSION = '0.0.5'
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lite/containers/version'
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require_relative 'lib/lite/containers/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'lite-containers'
9
+ spec.version = Lite::Containers::VERSION
10
+ spec.authors = ['Tomas Milsimer']
11
+ spec.email = ['tomas.milsimer@protonmail.com']
12
+
13
+ spec.summary = 'A collection of containers: heap, sorted array, AVL tree'
14
+ spec.homepage = 'https://github.com/lame-impala/lite-containers'
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.required_ruby_version = '>= 2.7.3'
25
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lite-containers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Milsimer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-02-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - tomas.milsimer@protonmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rubocop.yml"
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - README.md
25
+ - bench/containers_bench.rb
26
+ - lib/lite/containers.rb
27
+ - lib/lite/containers/abstract/collection.rb
28
+ - lib/lite/containers/abstract/deque.rb
29
+ - lib/lite/containers/abstract/implicit_key.rb
30
+ - lib/lite/containers/abstract/queue.rb
31
+ - lib/lite/containers/abstract/sorted_map.rb
32
+ - lib/lite/containers/avl_tree.rb
33
+ - lib/lite/containers/avl_tree/balance.rb
34
+ - lib/lite/containers/avl_tree/delete.rb
35
+ - lib/lite/containers/avl_tree/find.rb
36
+ - lib/lite/containers/avl_tree/implementation.rb
37
+ - lib/lite/containers/avl_tree/insert.rb
38
+ - lib/lite/containers/avl_tree/interfaces/bracket_assign.rb
39
+ - lib/lite/containers/avl_tree/interfaces/key_extraction_strategy/abstract.rb
40
+ - lib/lite/containers/avl_tree/interfaces/key_extraction_strategy/explicit.rb
41
+ - lib/lite/containers/avl_tree/interfaces/key_extraction_strategy/implicit.rb
42
+ - lib/lite/containers/avl_tree/node.rb
43
+ - lib/lite/containers/avl_tree/traversal.rb
44
+ - lib/lite/containers/error.rb
45
+ - lib/lite/containers/heap.rb
46
+ - lib/lite/containers/helpers/comparison.rb
47
+ - lib/lite/containers/helpers/key_extractor.rb
48
+ - lib/lite/containers/helpers/merge.rb
49
+ - lib/lite/containers/sorted_array.rb
50
+ - lib/lite/containers/sorted_array/binary_search.rb
51
+ - lib/lite/containers/top_n.rb
52
+ - lib/lite/containers/top_n/abstract.rb
53
+ - lib/lite/containers/top_n/avl_tree.rb
54
+ - lib/lite/containers/top_n/deque.rb
55
+ - lib/lite/containers/top_n/error.rb
56
+ - lib/lite/containers/top_n/heap.rb
57
+ - lib/lite/containers/version.rb
58
+ - lite_containers.gemspec
59
+ homepage: https://github.com/lame-impala/lite-containers
60
+ licenses:
61
+ - MIT
62
+ metadata:
63
+ homepage_uri: https://github.com/lame-impala/lite-containers
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 2.7.3
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubygems_version: 3.4.10
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: 'A collection of containers: heap, sorted array, AVL tree'
83
+ test_files: []