Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libMiMic by
NyLPC_cPtrTbl.c
00001 /********************************************************************************* 00002 * PROJECT: MiMic 00003 * -------------------------------------------------------------------------------- 00004 * 00005 * This file is part of MiMic 00006 * Copyright (C)2011 Ryo Iizuka 00007 * 00008 * MiMic is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published 00010 * by the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 * 00021 * For further information please contact. 00022 * http://nyatla.jp/ 00023 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp> 00024 * 00025 *********************************************************************************/ 00026 #include "NyLPC_cPtrTbl.h" 00027 00028 void NyLPC_cPtrTbl_initialize(NyLPC_TcPtrTbl_t* i_inst,void** i_buf,NyLPC_TUInt16 i_size) 00029 { 00030 i_inst->size=i_size; 00031 i_inst->len=0; 00032 i_inst->buf=i_buf; 00033 memset(i_inst->buf,0,i_size*sizeof(void*)); 00034 } 00035 void* NyLPC_cPtrTbl_get(NyLPC_TcPtrTbl_t* i_inst,NyLPC_TUInt16 i_index) 00036 { 00037 return i_inst->buf[i_index]; 00038 } 00039 00040 void NyLPC_cPtrTbl_set(NyLPC_TcPtrTbl_t* i_inst,NyLPC_TUInt16 i_index,void* i_val) 00041 { 00042 void** p=(i_inst->buf+i_index); 00043 if(*p==NULL){ 00044 if(i_val!=NULL){ 00045 //投入 00046 i_inst->len++; 00047 } 00048 }else{ 00049 if(i_val==NULL){ 00050 //消去 00051 i_inst->len--; 00052 } 00053 } 00054 //値を反映 00055 *p=i_val; 00056 return; 00057 } 00058 00059 NyLPC_TInt16 NyLPC_cPtrTbl_add(NyLPC_TcPtrTbl_t* i_inst,void* i_val) 00060 { 00061 int i; 00062 void** p=i_inst->buf; 00063 00064 for(i=i_inst->size-1;i>=0;i--){ 00065 if(*(p+i)==NULL){ 00066 NyLPC_cPtrTbl_set(i_inst,i,i_val); 00067 return i; 00068 } 00069 } 00070 return -1; 00071 } 00072 00073 /** 00074 * i_indexの要素に、NULLをセットして削除します。 00075 */ 00076 void NyLPC_cPtrTbl_remove(NyLPC_TcPtrTbl_t* i_inst,NyLPC_TUInt16 i_index) 00077 { 00078 NyLPC_cPtrTbl_set(i_inst,i_index,NULL); 00079 return; 00080 } 00081 00082 NyLPC_TInt16 NyLPC_cPtrTbl_getIndex(NyLPC_TcPtrTbl_t* i_inst,void* i_val) 00083 { 00084 int i; 00085 void** p=i_inst->buf; 00086 00087 for(i=i_inst->size-1;i>=0;i--){ 00088 if(*(p+i)==i_val){ 00089 return i; 00090 } 00091 } 00092 return -1; 00093 } 00094 00095 /** 00096 * 現在の要素数を返します。 00097 * この数は、テーブルに存在する有効なポインタの数です。 00098 */ 00099 NyLPC_TInt16 NyLPC_cPtrTbl_getLength(NyLPC_TcPtrTbl_t* i_inst) 00100 { 00101 return i_inst->len; 00102 } 00103 00104 NyLPC_TBool NyLPC_cPtrTbl_hasEmpty(NyLPC_TcPtrTbl_t* i_inst) 00105 { 00106 return i_inst->len<i_inst->size; 00107 }
Generated on Tue Jul 12 2022 16:22:59 by
