Skip to content

Commit

Permalink
[b][basic] Add Endianness in primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
at15 committed Jun 24, 2020
1 parent 251a401 commit cbad06d
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 17 deletions.
22 changes: 7 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
# Node rules:
## Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# IDE Start
.idea
.vscode
# IDE End

## Dependency directory
## Commenting this out is preferred by some people, see
## https://docs.npmjs.com/misc/faq#should-i-check-my-node_modules-folder-into-git
node_modules

# Book build output
_book

# eBook build output
*.epub
*.mobi
*.pdf
# Example Start
*.out
# Example End
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Layout would be (subject to change, and need to merge w/ layout in libtsdb-go)
- integer, float number and their machine representation (basic for working on compression)
- statistic, distribution, random etc.
- maybe information theory
? data model
? data model ? a dedicated chapter?
- 03 components (might flatten this)
- overview
- query language
Expand Down
8 changes: 8 additions & 0 deletions book/abbreviation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Abbreviation

## TODO

- [ ] support building index for abbreviation and point them to definition

- MSB: Most Significant Byte
- LSB: Least Significant Byte
2 changes: 1 addition & 1 deletion book/basic/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Chapter 02 Basic
# Chapter 02: Basic

- [Primitive Data Type](primitive) Representation of primitive type like integer, float, string.
1 change: 1 addition & 0 deletions book/basic/primitive/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
33 changes: 33 additions & 0 deletions book/basic/primitive/code/endianness.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* project: ntsdb
* file: endianness.c
* chapter: basic
* section: primitive
* description: show endianess of integer
* compile: gcc endianess.c
* run: ./a.out
*/

#include <stdio.h>

// NOTE: based on CSAPP Figure 2.4

void show_bytes(unsigned char* start, size_t len) {
for (int i = 0; i < len; i++) {
printf(" %.2x", start[i]);
}
printf("\n");
}

void show_int(int x) {
show_bytes((unsigned char*) &x, sizeof(x));
}

int main() {
// 01 04 00 00
// 1025 is 2^10+1, which is 0x0401, print starts from smaller memory address, 01 is LSB and prints before 04
show_int(1025);

// 1024 2048
printf("%d %d\n", 0x0400, 0x0400 << 1);
}
23 changes: 23 additions & 0 deletions book/basic/primitive/endianness.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Endianness

- `byte` i.e. 8 bits is the atomic unit, endianness is for byte ordering. (for the scope in this book)
- big-endian, save MSB (Most Significant Byte) in the smallest address
- little-endian, save LSB (Least Significant Byte) in the smallest address
- most processors are little endian
- network order is big endian
- numeric literal, left is MSB
- bit shift, shift left shift towards MSB, e.g. `0x0400 << 1` is `0x0800`

Example [code](code/endianness.c)

`2^10+1` when written in literal is `100_0000_0001` or `0x0401` (hex), it requires two bytes

```text
memory address: 0 8
big-endian : 0000_0100 0000_0001
little-endian : 0000_0001 0000_0100
```

## Reference

- https://en.wikipedia.org/wiki/Endianness
5 changes: 5 additions & 0 deletions book/compression/gorilla.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Facebook Gorilla Compression

## TODO

- [ ] merge notes from libtsdb-go
1 change: 1 addition & 0 deletions book/overview/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Chapter 01: Overview
39 changes: 39 additions & 0 deletions survey/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Time Series Database Survey

This folder contains survey on implementation of various TSDBs.

Required list in README

- link to [awesome tsdb](https://github.com/xephonhq/awesome-time-series-database), which should contain basic meta data.
- link to required files within the folder
- a short overview
- highlight in this database
- design flaw/limitation

Required files for describing each database.

Code walk through

- **read.md** Read path, link to source w/ commit hash.
- **write.md** Write path, link to source w/ commit hash.

API

- **protocol.md** Wire protocol format and transport, mainly about write because many TSDB have dedicated query language.
- **query-language.md** Query language.

Internal

- **model.md** General data model, what is a time series for this TSDB (yeah, this definition varies).
- **compression.md** Compression related algorithm or code.
- **query-execution.md** Query execution and optimization, especially for those with query language and distributed ones.
- **storage-engine.md** Only applies to TSDB w/ their own storage format, i.e. write opaque blob to local fs or object store.
- **schema.md** Only applies to TSDB w/ underlying database i.e. Cassandra, ElasticSearch
- **distributed.md** Only applies to distributed TSDB, replication model, consensus protocol. Including those built on top of distributed data store i.e. Cassandra, S3.

Operation

- **build.md** How to build from source locally
- **docker.md** How to run it using docker(-compose) locally
- **config.md** Config file example, how to config the system (underlying database, operating system) properly
- **k8s.md** How to run it on k8s, operator and special things about their operator e.g. local volume

0 comments on commit cbad06d

Please sign in to comment.