This file contains hidden or 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
package scanlineFilling | |
/* each edge consists of 4 values: the yMin, yMax, xOfYMin and the slopeInverse thus the total number is 4*/ | |
const val SizeOfVariablesPerEdge = 4 | |
/** | |
* the values we need to store are recorded in an array, and these are their indices. | |
* Essentially something like this | |
``` | |
Index: 0 1 2 3 4 5 6 7 8 9 10 11 |
This file contains hidden or 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
package scanlineFilling | |
/** | |
* The basic steps of a scan-line filling algorithm: build the edge table; sort the edges; loop through the scan-lines from yMin to the yMaximum, | |
* update the x coordinate as you move along, then fill up the regions covered by the active edges (successor and pre-decessor) | |
*/ | |
data class Edge(val yMaximum: Float, | |
val yMinimum:Float, | |
var xOfYmin:Float, val slopeInverse:Float) |
This file contains hidden or 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
sealed class SqlStatement | |
// Select statement | |
data class Select( | |
val selectList: SelectList, | |
val from: TableReference, | |
val where: Condition? = null, | |
val groupBy: GroupBy? = null, | |
val orderBy: OrderBy? = null, | |
val limit: Limit? = null |
This file contains hidden or 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
<sql_statement> ::= <select> | <insert> | <update> | <delete> // the full sql statement | |
<select> ::= "SELECT" <select_list> "FROM" <table_reference> ["WHERE <condition>"] ["GROUP BY" <column_list>] ["ORDER BY" <order_list> [<order_by_option>]] ["LIMIT" <number>] // select * from users where age > 12 or select name,age from users order by name ASC | |
<insert> ::= "INSERT INTO" <identifier> "("<column_list>")" "VALUES" "(" <value_list> ")" // insert into users (name,age) values ('John', 12) | |
<update> ::= "UPDATE" <identifier> "SET" <column_assignment> ["WHERE" <condition>] // update users set name='Alice' where id=1 | |
<delete> ::= "DELETE FROM" <identifier> ["WHERE" <condition>] // delete from users where age=12 | |
<table_reference> ::= <identifier> ["JOIN" <identifier> "ON" <condition>] // items or items JOIN orders ON users.id=orders.user_id | |
<select_list> ::= "*"| <column_list> // * name or * name,age,gender | |
<column_list> ::= <identifier>{","<identifier>} // name or name,age or name,age,gender | |
<order_by_option>::= "AS |
This file contains hidden or 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
sealed class SqlStatement | |
// SELECT statement | |
data class Select( | |
val selectList: SelectList, | |
val tableReference: TableReference, | |
val whereCondition: Condition? = null, | |
val groupBy: ColumnList? = null, | |
val orderBy: OrderList? = null, | |
val orderByOption: OrderByOption? = null, |
This file contains hidden or 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
<sql_statement> ::= <select> | <insert> | <update> | <delete> // the full sql statement | |
<select> ::= "SELECT" <select_list> "FROM" <table_reference> ["WHERE <condition>"] ["GROUP BY" <column_list>] ["ORDER BY" <order_list> [<order_by_option>]] ["LIMIT" <number>] // select * from users where age > 12 or select name,age from users order by name ASC | |
<insert> ::= "INSERT INTO" <identifier> "("<column_list>")" "VALUES" "(" <value_list> ")" // insert into users (name,age) values ('John', 12) | |
<update> ::= "UPDATE" <identifier> "SET" <column_assignment> ["WHERE" <condition>] // update users set name='Alice' where id=1 | |
<delete> ::= "DELETE FROM" <identifier> ["WHERE" <condition>] // delete from users where age=12 | |
<table_reference> ::= <identifier> ["JOIN" <identifier> "ON" <condition>] // items or items JOIN orders ON users.id=orders.user_id | |
<select_list> ::= "*"| <column_list> // * name or * name,age,gender | |
<column_list> ::= <identifier>{","<identifier>} // name or name,age or name,age,gender | |
<order_by_option>::= "AS |
This file contains hidden or 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
package org.example | |
import kotlinx.coroutines.* | |
import okhttp3.* | |
import okhttp3.HttpUrl.Companion.toHttpUrl | |
import org.example.DownloadProgress.Companion.calculateDownloadPercentageFromDownloadProgress | |
import org.example.Utils.ATTEMPT_COUNT | |
import org.example.Utils.DedicatedBlockingDispatcher | |
import org.example.Utils.combineSegmentsToFile | |
import org.example.Utils.copyToOutputStreamAsynchronously |
This file contains hidden or 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
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
requestNotificationPermission() | |
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager | |
/* if you use AlarmManager.setRepeating(timeInMillis, timeInterval), note that the system will always delay your | |
alarm by 5 seconds and the interval must be at least 60 seconds+. However there's virtually no difference between |
This file contains hidden or 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
fun main(){ | |
coroutineScope { | |
launch { findEvenNumbers(1,10..20) } | |
launch { findEvenNumbers(2,30..60) } | |
} | |
} | |
private fun findEvenNumbers(workerName:Int,range: IntRange){ | |
for (i in range){ | |
if (i%2==0) println("[$workerName]: even found $i") | |
} |
NewerOlder