-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added IndexingState to FieldGetter to allow more powerful indexing fe…
…atures
- Loading branch information
1 parent
d0c0021
commit dbccc1a
Showing
11 changed files
with
79 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package lightdb.field | ||
|
||
trait IndexingKey[T] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package lightdb.field | ||
|
||
class IndexingState { | ||
private var map = Map.empty[IndexingKey[_], Any] | ||
|
||
def get[T](key: IndexingKey[T]): Option[T] = map.get(key).map(_.asInstanceOf[T]) | ||
def getOrCreate[T](key: IndexingKey[T], create: => T): T = synchronized { | ||
get(key) match { | ||
case Some(value) => value | ||
case None => | ||
val value: T = create | ||
set(key, value) | ||
value | ||
} | ||
} | ||
def apply[T](key: IndexingKey[T]): T = get[T](key).getOrElse(throw new NullPointerException(s"Not found: $key")) | ||
def set[T](key: IndexingKey[T], value: T): Unit = synchronized { | ||
map += key -> value | ||
} | ||
def remove[T](key: IndexingKey[T]): Unit = synchronized { | ||
map -= key | ||
} | ||
def clear(): Unit = synchronized { | ||
map = Map.empty | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters