better selection of next id number (now reusing lower numbers)

This commit is contained in:
Rob Pearce 2022-06-13 21:16:01 +10:00
parent cfe5d42e5d
commit 4aa14b73b2
2 changed files with 23 additions and 1768 deletions

1750
out

File diff suppressed because it is too large Load Diff

41
t.sh
View File

@ -141,6 +141,21 @@ function getuid() {
return 0 return 0
} }
function updatenextid() {
local nextid2=1
nextid2=1
while [[ " ${taskid[@]}" == *\ $nextid2* ]]; do
nextid2=$((nextid2 + 1))
done
nextid=$nextid2
}
function addidmap() { #1=id 2=uid
local id="$1" uid="$2"
idmap[$id]=$uid
[[ $b5 -eq 1 ]] && eval i_idmap["$uid"]=$id
}
function loadids() { function loadids() {
local LINE n uid id max count local LINE n uid id max count
count=0 count=0
@ -160,8 +175,7 @@ function loadids() {
id=${LINE#*:} id=${LINE#*:}
#uid=$(echo "$LINE" | sed 's/:.*$//g') #uid=$(echo "$LINE" | sed 's/:.*$//g')
#id=$(echo "$LINE" | sed 's/^.*://g') #id=$(echo "$LINE" | sed 's/^.*://g')
idmap[$id]=$uid addidmap $id $uid
[[ $b5 -eq 1 ]] && eval i_idmap["$uid"]=$id
if [[ -z $uid || -z $id ]]; then if [[ -z $uid || -z $id ]]; then
error "invalid idmapping line: '$LINE'" error "invalid idmapping line: '$LINE'"
profile "end" profile "end"
@ -170,7 +184,7 @@ function loadids() {
[[ $id -gt $max ]] && max=$id [[ $id -gt $max ]] && max=$id
count=$((count + 1)) count=$((count + 1))
done < "$idfile" done < "$idfile"
nextid=$((max + 1)) updatenextid
profile "end" profile "end"
dblog "got $count IDs from $idfile" dblog "got $count IDs from $idfile"
@ -209,7 +223,7 @@ function dumpids() {
function loadtasks() { function loadtasks() {
local f ess x thislev par parid show thissum thisdesc local f ess x thislev par parid show thissum thisdesc
local verbose=0 nextid2=1 local verbose=0
profile "start" profile "start"
maxid=-1 maxid=-1
@ -228,15 +242,7 @@ function loadtasks() {
numwid=${#maxid} numwid=${#maxid}
profile "finished loadtask calls" profile "finished loadtask calls"
# ---ooooo implement get_next_id() updatenextid
# minid=$( echo "${taskid[@]}" | tr ' ' '\n' | sort -nr | tail -1)
# if [[ $minid -lt $nextid ]]; then
# nextid2=1
# while [[ " ${taskid[@]}" == *\ $nextid2* ]]; do
# nextid2=$((nextid2 + 1))
# done
# nextid=$nextid2
# fi
dblog "Calculating max indent level" dblog "Calculating max indent level"
# figure out max indent level and next id # figure out max indent level and next id
@ -334,9 +340,8 @@ dblog "process token '${tok[$i]}'"
id=$(getid $uid) id=$(getid $uid)
if [[ -z $id ]]; then if [[ -z $id ]]; then
id=$nextid id=$nextid
idmap[$nextid]=$uid addidmap $nextid $uid
[[ $b5 -eq 1 ]] && eval i_idmap["$uid"]=$id updatenextid
nextid=$((nextid + 1))
needsave=1 needsave=1
fi fi
elif [[ ${tok[$i]} == "sum" ]]; then elif [[ ${tok[$i]} == "sum" ]]; then
@ -1124,7 +1129,7 @@ function addtask() {
fi fi
uid=$(randomuid) uid=$(randomuid)
thisid=$nextid thisid=$nextid
idmap[$thisid]=$uid addidmap $thisid $uid
taskid[$thisid]=$thisid taskid[$thisid]=$thisid
taskuid[$thisid]=$uid taskuid[$thisid]=$uid
tasksum[$thisid]="$*" tasksum[$thisid]="$*"
@ -1156,7 +1161,7 @@ END:VTODO
END:VCALENDAR END:VCALENDAR
EOF2 EOF2
nextid=$((nextid + 1)) updatenextid
saveids saveids
needtitle=1 needtitle=1
if [[ -z ${parentuid} ]]; then if [[ -z ${parentuid} ]]; then