GithubHelp home page GithubHelp logo

svasanta / study-indexdb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cduvvuri18/study-indexdb

0.0 2.0 0.0 51 KB

Disk based index database implementation. Purely written in Java.

Java 100.00%

study-indexdb's Introduction

Disk based index database implementation. Purely written in Java.

The primary objective of study-indexdb is to understand the implementation of the indexes with some real usecases, which I believe gives better grasp of these concepts. One can try out or extend my code in their test/school projects to use and dig deeper into the indexes.

As I am myself beginer to these concepts, I will continue to evolve the project with the better design, optimizations, etc but will make sure implementation stay simple to understand. Any updates will be posted here.

This project currently has 3 algorithms:

BTree - Disk based implementation

AVLTree - In memeory

RedBlackTree - In memory

Getting Started

BTRee

BTree is purely implemented in Java and it is disk based implementation.

References: CLRS/Adam Drozdek/wiki. BTree is omnipresent :-).

Below are the steps to use the BTree If one want to export it as library. If the intent of the viewer is to understand the disk based implementation of BTree, then I would suggest to start with the test cases. BTree - Disk based implementation.

Create BTree

While providing the folder path @ which index file is expected to create, do not provide the file name. Index file is created with the simple class name of the key(Looks weird right..I will fix this later).

Case - 1: Key and value both primitives

IndexFactory<Integer, String> factory = new BTreeFactory<Integer, String>();
DBIndex<Integer, String> index = factory.create(Integer.class, String.class, Paths.get("<absolute_path_do_not_mention_index_file_name>"));

Case - 2: Key and value both can be Java first class objects or just one. If the Key or Value is POJO. Have to follow below conventions. Refer the available annotations Here

//If the Key is non-primitive, it has to be annotated with @Key and implement Comparable Interface
@Key
class StudentKey implements Comparable<StudentKey> {
	@Field(name = "id")
	private Integer id;

	@Field(name = "yob")
	private Integer yearOfBirth;

	StudentKey() {

	}

	StudentKey(Integer id, Integer yearOfBirth) {
		this.id = id;
		this.yearOfBirth = yearOfBirth;
	}

	@Override
	public int compareTo(StudentKey other) {
		int t = this.id.compareTo(other.id);
		if (t != 0) {
			return t;
		}

		return this.yearOfBirth.compareTo(other.yearOfBirth);
	}
}

//If the key is non-primitive, it has to be annotated with @Entity
@Entity
class Student {
	@TextField(name = "fName", length = 30)
	private String firstName;

	@TextField(name = "lName", length = 30)
	private String lastName;

	@Field(name = "rollNo")
	private Integer rollNo;
  
 	Student(String firstName, String lastName, Integer rollNo) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.rollNo = rollNo;
	}

	public String getFirstName() {
		return firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public Integer getRollNo() {
		return rollNo;
	}
}

//create the Index
IndexFactory<StudentKey, Student> idxFactory = new BTreeFactory<StudentKey, Student>();
DBIndex<StudentKey, Student> index = idxFactory.create(StudentKey.class, Student.class, Paths.get("<absolute_path_do_not_mention_index_file_name>"));

insert, search, delete, successor

//After create btree step, invoke init
index.init();

index.insert(new StudentKey(1, 1990), new Student("Chaitanya", "Duvvuri", 210210))

//continue with all your operations

//insert
//search

....

//finally

index.close();

All the operations performed above are persistent on disk.

Open BTree.

While mentioning the path, do not provide the file name. BTree will look up for index file with the simple class name of the key provided in the given path(Looks weird right..I will fix this later).

index = idxFactory.open(Integer.class, String.class, Paths.get("<absolute_path_do_not_mention_index_file_name>"));

//search

//continue with all your operations

//finally
index.close();

Refer the test cases for more details

None of these algorithm implementations are thread safe

In Progress..

study-indexdb's People

Contributors

cduvvuri18 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.