UVa 644 - Immediate Decodability

本文探讨了即时可解码编码的概念,即一种确保没有一个符号的编码是另一个符号编码的前缀的方法。通过示例说明了即时可解码与非即时可解码编码的区别,并提供了一个用于检测一组编码是否即时可解码的程序实现。
Immediate Decodability

An encoding of a set of symbols is said to be immediately decodable if no code for one symbol is  the prefix of a code for another symbol.  We will assume for this problem that all codes are in  binary, that no two codes within a set of codes are the same, that each code has at least one bit  and no more than ten bits, and that each set has at least two codes and no more than eight.


Examples:  Assume an alphabet that has symbols  {A, B, C, D}


The following code is immediately decodable:


     A:01   B:10   C:0010   D:0000


but this one is not:


     A:01   B:10   C:010   D:0000    (Note that A is a prefix ofC)

Input

Write a program that accepts as input a series of groups of records from a data file. Each record in a group contains a collection of zeroes and ones representing a binary code for a  different symbol.  Each group is followed by a single separator record containing a single 9; the  separator records are not part of the group. Each group is independent of other groups; the codes  in one group are not related to codes in any other group (that is, each group is to be processed  independently).

Output

For each group, your program should determine whether the codes in that group are immediately decodable, and should print a single output line giving the group number and  stating whether the group is, or is not, immediately decodable.


The Sample Input describes the examples above.

Sample Input

01
10
0010
0000
9
01
10
010
0000
9

Sample Output

Set 1 is immediately decodable
Set 2 is not immediately decodable



Miguel A. Revilla
2000-01-17

 

 

#include<stdio.h>
#include<string.h>
int main()
{
    int i=0,j,k,n=1;
    char s[10][12];
    while(scanf("%s",s[i])!=EOF)
    {
        int flag=1;
        if(s[i][0]=='9')
        {
            for(j=0;j<i&&flag==1;j++)
                for(k=0;k<i&&flag==1;k++)
                {
                    if(j!=k&&strlen(s[j])<=strlen(s[k]))
                        if(&s[k][0]==strstr(s[k],s[j]))
                        flag=0;
                }
            i=0;
            if(flag)
                printf("Set %d is immediately decodable\n",n);
            else
                printf("Set %d is not immediately decodable\n",n);
            n++;
        }
        else
            i++;
    }
    return 0;
}


 

 

**HT-Immediate Block Ack(高吞吐量即时块确认)** 是 IEEE 802.11n 标准中定义的一种确认机制,用于在高吞吐量(HT)无线局域网中更高效地确认多个 MPDU 的接收情况。它是 **BlockAck(块确认)机制的一种实现方式**,并且在接收端收到聚合帧(A-MPDU)后**立即返回 BlockAck 响应帧(BA)**,以提升无线通信的效率。 --- ## ✅ 一、HT-Immediate Block Ack 的定义 ### ✅ 1. **定义** HT-Immediate Block Ack 是指: - 发送端使用 **BlockAck No Ack Policy** 发送多个 MPDU; - 接收端在收到这些 MPDU 后,**立即发送 BlockAck(BA)帧**,而不是对每个 MPDU 单独进行 ACK; - BA 帧中包含一个 bitmap,表示哪些 MPDU 已成功接收。 ### ✅ 2. **主要目的** - 减少每个 MPDU 的确认开销; - 支持 A-MPDU(聚合 MPDU)传输; - 提高无线网络的吞吐量和效率。 --- ## ✅ 二、HT-Immediate Block Ack 的工作流程 ### ✅ 1. **BlockAck 会话建立** - 通信双方通过 **ADDBA Request/Response** 帧协商 BlockAck 参数(如窗口大小、TID、起始序列号等); - 建立 BlockAck 会话。 ### ✅ 2. **发送端发送 A-MPDU** - 使用 BlockAck No Ack Policy; - 多个 MPDU 被聚合为一个 A-MPDU 发送; - 不要求每个 MPDU 都立即收到 ACK。 ### ✅ 3. **接收端处理 A-MPDU** - 将每个 MPDU 插入重排序缓冲区(Reorder Buffer); - 若收到 BAR 帧,则立即返回 BA 帧; - 若未收到 BAR,但 BlockAck Policy 是 Immediate,则在收到最后一个 MPDU(MoreFrag=0)后**立即返回 BA 帧**。 ### ✅ 4. **发送端接收 BA 帧** - 根据 BA 的 bitmap 判断哪些 MPDU 成功接收; - 对未确认的 MPDU 进行重传。 --- ## ✅ 三、BlockAck Policy 类型 IEEE 802.11 支持以下几种 BlockAck 策略: | BlockAck Policy | 是否需要 BAR | 是否立即返回 BA | 说明 | |------------------|--------------|------------------|------| | Normal Ack Policy | ❌ 否 | ❌ 否 | 每个 MPDU 都需要单独确认(传统方式) | | BlockAck No Ack Policy | ✅ 是 | ❌ 否 | 需要 BAR 触发 BA 响应 | | HT-Immediate BlockAck | ❌ 否 | ✅ 是 | 接收端收到最后一个 MPDU 后立即返回 BA | --- ## ✅ 四、HT-Immediate BlockAck 的帧交互示例 ```text STA A (发送端) AP (接收端) | | |<----- A-MPDU (MPDU 1, 2, 3) ---->| | | |<----- BlockAck (BA) bitmap ----->| | | ``` - A-MPDU 中包含多个 MPDU; - 接收端在收到最后一个 MPDU 后,立即返回 BA; - BA 中的 bitmap 表示哪些 MPDU 已接收。 --- ## ✅ 五、C语言模拟 HT-Immediate BlockAck 的行为 以下是一个简化版的 BlockAck 机制模拟,展示 HT-Immediate BlockAck 的基本行为: ```c #include <stdio.h> #include <stdint.h> #include <string.h> #define MAX_SEQ 4096 #define WINDOW_SIZE 64 typedef struct { uint16_t seq; int received; } MPDU_STATUS; MPDU_STATUS scoreboard[MAX_SEQ]; // 用于记录接收状态 int start_seq = 0; // BlockAck 窗口起始序列号 // 初始化 scoreboard void init_scoreboard() { for (int i = 0; i < MAX_SEQ; i++) { scoreboard[i].received = 0; } } // 接收一个 MPDU,并记录其序列号 void receive_mpdu(uint16_t seq, int is_last_frag) { printf("Received MPDU: Seq %d\n", seq); scoreboard[seq].seq = seq; scoreboard[seq].received = 1; // 如果是最后一个分片,且是 HT-Immediate BlockAck Policy if (is_last_frag) { printf("Triggering HT-Immediate BlockAck...\n"); send_blockack(); } } // 发送 BlockAck 帧(包含 bitmap) void send_blockack() { printf("Sending BlockAck (BA) Frame:\n"); printf("Bitmap: "); for (int i = 0; i < WINDOW_SIZE; i++) { uint16_t seq = (start_seq + i) % MAX_SEQ; if (scoreboard[seq].received) { printf("1"); } else { printf("0"); } } printf("\n"); } int main() { init_scoreboard(); // 模拟接收 A-MPDU 中的多个 MPDU receive_mpdu(100, 0); // MoreFrag = 1 receive_mpdu(101, 0); receive_mpdu(102, 1); // MoreFrag = 0 -> 触发 BlockAck return 0; } ``` --- ## ✅ 六、总结 | 内容 | 说明 | |------|------| | ✅ HT-Immediate BlockAck 是什么? | IEEE 802.11n 中的块确认机制 | | ✅ 是否需要 BAR 帧? | 否 | | ✅ 是否立即返回 BA? | 是 | | ✅ 主要优点 | 减少确认开销,提高吞吐量 | | ✅ 适用场景 | A-MPDU 聚合传输 | --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值