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
#include <stdio.h> | |
#include <libc.h> | |
typedef struct { | |
int *marking; | |
int *takes; | |
int *puts; | |
int transition_count; | |
int place_count; | |
} PetriNet; |
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
func barBellNet() -> PetriNet { | |
let totoalWeightInGram = Place(name: "tototalWeightInGram") | |
let barBellSelected = Place(name: "BarBellSelected") | |
let barBellNotSelected = Place(name: "BarBellNotSelected", initNumberOfTokens: 1) | |
let barBell10Kg = Place(name: "10KgBarBell", initNumberOfTokens: 1) | |
let barBell15Kg = Place(name: "15KgBarBell", initNumberOfTokens: 1) | |
let barBell17_5Kg = Place(name: "17.5_KgBarBell", initNumberOfTokens: 1) | |
let barBell20Kg = Place(name: "20_KgBarBell", initNumberOfTokens: 1) | |
let weight0_5kg = Place(name: "0.5_KgWeight", initNumberOfTokens: 4) | |
let weight1kg = Place(name: "1_KgWeight", initNumberOfTokens: 4) |
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
func ticTacToeNet() -> PetriNet { | |
let xTurn = Place(name: "xTurn", initNumberOfTokens: 1) | |
let oTurn = Place(name: "oTurn") | |
let xWin = Place(name: "xWin") | |
let oWin = Place(name: "oWin") | |
let e1 = Place(name: "e1", initNumberOfTokens: 1) | |
let e2 = Place(name: "e2", initNumberOfTokens: 1) | |
let e3 = Place(name: "e3", initNumberOfTokens: 1) | |
let e4 = Place(name: "e4", initNumberOfTokens: 1) |
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
1. Motivation | |
This format is designed to allow users pack data together for random access and with space efficiency in mind. | |
2. Internal structure | |
IndexedData (further referenced as idata) can be split up in two general regions: manifest and data. | |
Manifest region contains information needed to identify the number of elements in data region. | |
Plus it contains data neded to extract a signle element out of the data region. | |
Optionaly it can contain a validation key, which can be used to ensure that the data at hand is in fact idata. | |
The data region contains all data items linearly concatenaited to each other. |
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
let now = Instant::now(); | |
for (index, e) in vec_clone.iter().enumerate() { | |
assert_eq!(first_index_for_eytzinger(&vec_clone, e).expect(""), index) | |
} | |
let eytz_search = now.elapsed(); | |
let now = Instant::now(); | |
for (index, e) in vec_unstable.iter().enumerate() { | |
assert_eq!(vec_unstable.binary_search(e).expect(""), index) | |
} |
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
pub fn first_index_for_eytzinger<T>(arr: &[T], value: &T) -> Option<usize> where T: PartialOrd { | |
let mut index = 0; | |
let count = arr.len(); | |
while index < count { | |
let candidate = unsafe{ arr.get_unchecked(index) }; | |
if value == candidate { | |
return Some(index) | |
} | |
index = index * 2 + 1 + ((candidate < value) as usize); | |
} |
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
import struct | |
import base64 | |
import json | |
from .value_types import ValueType | |
class FlxValue: | |
def __init__(self, buffer, offset, parent_width, packed_type): | |
self._buffer = buffer | |
self._offset = offset |
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
using System; | |
using System.Collections.Concurrent; | |
using System.Collections.Generic; | |
using System.Reflection; | |
using System.Runtime.InteropServices; | |
using Unity.Collections.LowLevel.Unsafe; | |
using UnityEditor; | |
using UnityEditor.IMGUI.Controls; | |
using UnityEngine; | |
using Unity.Entities; |
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
frame { | |
items: [int] # implicit input | |
value: int # implicit input | |
min_index: int | |
max_index: int | |
mid_index: int | |
<- found_index: int # explicit output | |
} | |
# sel is selector |
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
All I present in my blog post is just thin infrastructure (Helpers if you will) on top of ISystemStateComponentData. | |
You can use it in Jobs and it is not expensive as it does not introduce anything you would not do yourself if you would like to perform diff check on an entity. | |
For a more practical explanation how I envision this stuff to work please have a look at this response: | |
https://medium.com/@icex33/i-am-not-sure-if-you-were-able-to-see-the-gist-i-added-add298168546 | |
Now why is it possible to use in Jobs? | |
Because if you call the `Diff<Position,PositionHistory>()` method on entity you are not mutating anything. You are just comparing two component values - current position and previous position. The return type is a struct which has 3 properties. The Type is an enum with following cases: | |
- NothingChanged, both values are equal | |
- Added, there is a current value set but there is no previous value | |
- Updated, the current and previous values are different |