Skip to content

Commit

Permalink
Merge branch 'main' into layout-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnabdaz authored Jul 27, 2024
2 parents cf182d5 + beba87d commit 65ddcfa
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 deletions.
30 changes: 19 additions & 11 deletions src/components/DialogBox/OpenOffline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
type="radio"
name="projectId"
:value="projectId"
v-model="selectedProjectId"
/>
{{ projectName }}<span></span>
<i
class="fa fa-trash deleteOfflineProject"
@click="deleteOfflineProject(projectId)"
@click="deleteOfflineProject(projectId.toString())"
></i>
</label>
<p v-if="JSON.stringify(projectList) == '{}'">
Expand Down Expand Up @@ -64,32 +65,39 @@
<script lang="ts" setup>
import load from '#/simulator/src/data/load'
import { useState } from '#/store/SimulatorStore/state'
import { onMounted, onUpdated, ref, toRaw } from '@vue/runtime-core'
import { onMounted, onUpdated, ref, reactive } from '@vue/runtime-core'
const SimulatorState = useState()
const projectList = ref({})
const projectList: {
[key: string]: string
} = reactive({})
const selectedProjectId = ref<string | null>(null)
onMounted(() => {
SimulatorState.dialogBox.open_project_dialog = false
})
onUpdated(() => {
var data = localStorage.getItem('projectList')
projectList.value = JSON.parse(localStorage.getItem('projectList')) || {}
const data = localStorage.getItem('projectList')
projectList.value = data ? JSON.parse(data) : {}
})
function deleteOfflineProject(id) {
function deleteOfflineProject(id: string) {
localStorage.removeItem(id)
const temp = JSON.parse(localStorage.getItem('projectList')) || {}
const data = localStorage.getItem('projectList')
const temp = data ? JSON.parse(data) : {}
delete temp[id]
projectList.value = temp
localStorage.setItem('projectList', JSON.stringify(temp))
}
function openProjectOffline() {
SimulatorState.dialogBox.open_project_dialog = false
let ele = $('input[name=projectId]:checked')
if (!ele.val()) return
load(JSON.parse(localStorage.getItem(ele.val())))
window.projectId = ele.val()
if (!selectedProjectId.value) return
const projectData = localStorage.getItem(selectedProjectId.value)
if (projectData) {
load(JSON.parse(projectData))
window.projectId = selectedProjectId.value
}
}
function OpenImportProjectDialog() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
// Algorithm used for Combinational Analysis

type BooleanMinimizeType = {
minTerms: number[]
dontCares: number[]
numVars: number
result: string[]
}

export default function BooleanMinimize(
numVarsArg,
minTermsArg,
dontCaresArg = []
numVarsArg: number,
minTermsArg: number[],
dontCaresArg: number[] = []
) {
var __result
var __result: string[]

Object.defineProperties(this, {
minTerms: {
Expand Down Expand Up @@ -47,7 +54,7 @@ export default function BooleanMinimize(
}

BooleanMinimize.prototype.solve = function () {
function dec_to_binary_string(n) {
const dec_to_binary_string = (n: number) => {
var str = n.toString(2)

while (str.length != this.numVars) {
Expand All @@ -57,14 +64,14 @@ BooleanMinimize.prototype.solve = function () {
return str
}

function num_set_bits(s) {
const num_set_bits = (s: string) => {
var ans = 0
for (let i = 0; i < s.length; ++i) if (s[i] === '1') ans++
return ans
}

function get_prime_implicants(allTerms) {
var table = []
const get_prime_implicants = (allTerms: string[]) => {
var table: Set<string>[] = []
var primeImplicants = new Set()
var reduced

Expand Down Expand Up @@ -115,11 +122,11 @@ BooleanMinimize.prototype.solve = function () {
return primeImplicants
}

function get_essential_prime_implicants(primeImplicants, minTerms) {
const get_essential_prime_implicants = (primeImplicants: string[], minTerms: string[]) => {
var table = [],
column

function check_if_similar(minTerm, primeImplicant) {
const check_if_similar = (minTerm: string, primeImplicant: string) => {
for (let i = 0; i < primeImplicant.length; ++i) {
if (
primeImplicant[i] !== '-' &&
Expand All @@ -131,7 +138,7 @@ BooleanMinimize.prototype.solve = function () {
return true
}

function get_complexity(terms) {
const get_complexity = (terms: string[]) => {
var complexity = terms.length

for (let t of terms) {
Expand All @@ -146,7 +153,7 @@ BooleanMinimize.prototype.solve = function () {
return complexity
}

function isSubset(sub, sup) {
const isSubset = (sub: Set<number>, sup: Set<number>) => {
for (let i of sub) {
if (!sup.has(i)) return false
}
Expand All @@ -166,8 +173,8 @@ BooleanMinimize.prototype.solve = function () {
table.push(column)
}

var possibleSets = [],
tempSets
let possibleSets: Set<number>[] = [],
tempSets: Set<number>[]

for (let i of table[0]) {
possibleSets.push(new Set([i]))
Expand Down Expand Up @@ -216,12 +223,12 @@ BooleanMinimize.prototype.solve = function () {
return essentialImplicants
}

var minTerms = this.minTerms.map(dec_to_binary_string.bind(this))
var dontCares = this.dontCares.map(dec_to_binary_string.bind(this))
var minTerms: string[] = this.minTerms.map(dec_to_binary_string.bind(this))
var dontCares: string[] = this.dontCares.map(dec_to_binary_string.bind(this))

return get_essential_prime_implicants.call(
this,
Array.from(get_prime_implicants.call(this, minTerms.concat(dontCares))),
Array.from(get_prime_implicants.call(this, minTerms.concat(dontCares))) as string[],
minTerms
)
}

0 comments on commit 65ddcfa

Please sign in to comment.