mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-26 09:28:35 +08:00
There are concrete implementations for a simple set, a key-value store, and nested sets with 2 or 3 keys. The API stays the same for all implementations and the performances is more or less the same as without the wrapper (at least with YJIT enabled).
33 lines
458 B
Ruby
Vendored
33 lines
458 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module Migrations::SetStore
|
|
class SimpleSet
|
|
include Interface
|
|
|
|
def initialize
|
|
@store = Set.new
|
|
end
|
|
|
|
def add(value)
|
|
@store.add(value)
|
|
self
|
|
end
|
|
|
|
def add?(value)
|
|
!!@store.add?(value)
|
|
end
|
|
|
|
def include?(value)
|
|
@store.include?(value)
|
|
end
|
|
|
|
def bulk_add(records)
|
|
@store.merge(records)
|
|
nil
|
|
end
|
|
|
|
def empty?
|
|
@store.empty?
|
|
end
|
|
end
|
|
end
|